Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): badgeTextColor property #13874

Merged
merged 2 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
TiC.PROPERTY_ACTIVE_TINT_COLOR,
TiC.PROPERTY_ACTIVE_TITLE_COLOR,
TiC.PROPERTY_BADGE,
TiC.PROPERTY_BADGE_COLOR,
TiC.PROPERTY_BADGE_COLOR, // DEPRECATED: Superseded by PROPERTY_BADGE_BACKGROUND_COLOR.
TiC.PROPERTY_BADGE_BACKGROUND_COLOR,
TiC.PROPERTY_BADGE_TEXT_COLOR,
TiC.PROPERTY_ICON,
TiC.PROPERTY_TINT_COLOR,
TiC.PROPERTY_TITLE,
Expand Down Expand Up @@ -245,7 +247,8 @@ public void onPropertyChanged(String name, Object value)
tabGroupView.updateTabIcon(this.tabGroupProxy.getTabIndex(this));
} else if (name.equals(TiC.PROPERTY_BADGE)) {
tabGroupView.updateBadge(this.tabGroupProxy.getTabIndex(this));
} else if (name.equals(TiC.PROPERTY_BADGE_COLOR)) {
} else if (name.equals(TiC.PROPERTY_BADGE_COLOR) || name.equals(TiC.PROPERTY_BADGE_BACKGROUND_COLOR)
|| name.equals(TiC.PROPERTY_BADGE_TEXT_COLOR)) {
tabGroupView.updateBadgeColor(this.tabGroupProxy.getTabIndex(this));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,24 @@ public void updateBadgeColor(int index)

// TODO: reset to default value when property is null
if (tabProxy.hasPropertyAndNotNull(TiC.PROPERTY_BADGE_COLOR)) {
Log.w(TAG, "badgeColor is deprecated. Use badgeBackgroundColor instead.");
int menuItemId = this.mBottomNavigationView.getMenu().getItem(index).getItemId();
BadgeDrawable badgeDrawable = this.mBottomNavigationView.getOrCreateBadge(menuItemId);
badgeDrawable.setBackgroundColor(
TiConvert.toColor(tabProxy.getProperty(TiC.PROPERTY_BADGE_COLOR), tabProxy.getActivity()));
}
if (tabProxy.hasPropertyAndNotNull(TiC.PROPERTY_BADGE_BACKGROUND_COLOR)) {
int menuItemId = this.mBottomNavigationView.getMenu().getItem(index).getItemId();
BadgeDrawable badgeDrawable = this.mBottomNavigationView.getOrCreateBadge(menuItemId);
badgeDrawable.setBackgroundColor(
TiConvert.toColor(tabProxy.getProperty(TiC.PROPERTY_BADGE_BACKGROUND_COLOR), tabProxy.getActivity()));
}
if (tabProxy.hasPropertyAndNotNull(TiC.PROPERTY_BADGE_TEXT_COLOR)) {
int menuItemId = this.mBottomNavigationView.getMenu().getItem(index).getItemId();
BadgeDrawable badgeDrawable = this.mBottomNavigationView.getOrCreateBadge(menuItemId);
badgeDrawable.setBadgeTextColor(
TiConvert.toColor(tabProxy.getProperty(TiC.PROPERTY_BADGE_TEXT_COLOR), tabProxy.getActivity()));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,21 @@ public void updateBadgeColor(int index)

// TODO: reset to default value when property is null
if (tabProxy.hasPropertyAndNotNull(TiC.PROPERTY_BADGE_COLOR)) {
Log.w(TAG, "badgeColor is deprecated. Use badgeBackgroundColor instead.");
BadgeDrawable badgeDrawable = this.mTabLayout.getTabAt(index).getOrCreateBadge();
badgeDrawable.setBackgroundColor(
TiConvert.toColor(tabProxy.getProperty(TiC.PROPERTY_BADGE_COLOR), tabProxy.getActivity()));
}
if (tabProxy.hasPropertyAndNotNull(TiC.PROPERTY_BADGE_BACKGROUND_COLOR)) {
BadgeDrawable badgeDrawable = this.mTabLayout.getTabAt(index).getOrCreateBadge();
badgeDrawable.setBackgroundColor(
TiConvert.toColor(tabProxy.getProperty(TiC.PROPERTY_BADGE_BACKGROUND_COLOR), tabProxy.getActivity()));
}
if (tabProxy.hasPropertyAndNotNull(TiC.PROPERTY_BADGE_TEXT_COLOR)) {
BadgeDrawable badgeDrawable = this.mTabLayout.getTabAt(index).getOrCreateBadge();
badgeDrawable.setBadgeTextColor(
TiConvert.toColor(tabProxy.getProperty(TiC.PROPERTY_BADGE_TEXT_COLOR), tabProxy.getActivity()));
}
}

@Override
Expand Down
4 changes: 3 additions & 1 deletion android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@ public class TiC
public static final String PROPERTY_BACKGROUND_SELECTED_COLOR = "backgroundSelectedColor";
public static final String PROPERTY_BACKGROUND_SELECTED_IMAGE = "backgroundSelectedImage";
public static final String PROPERTY_BADGE = "badge";
public static final String PROPERTY_BADGE_COLOR = "badgeColor";
public static final String PROPERTY_BADGE_COLOR = "badgeColor"; // DEPRECATED: Superseded by PROPERTY_BADGE_BACKGROUND_COLOR.
public static final String PROPERTY_BADGE_BACKGROUND_COLOR = "badgeBackgroundColor";
public static final String PROPERTY_BADGE_TEXT_COLOR = "badgeTextColor";
public static final String PROPERTY_TARGET_ITEM_INDEX = "targetItemIndex";
public static final String PROPERTY_TARGET_SECTION = "targetSection";
public static final String PROPERTY_TARGET_SECTION_INDEX = "targetSectionIndex";
Expand Down
22 changes: 22 additions & 0 deletions apidoc/Titanium/UI/Tab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ properties:
since: {android: "9.3.0"}

- name: badgeColor
deprecated:
since: "12.2.0"
notes: Use [Titanium.UI.Tab.badgeBackgroundColor](Titanium.UI.Tab.badgeBackgroundColor) instead.
summary: |
If this item displays a badge, this color will be used for the badge's background.
If set to null, the default background color will be used instead.
Expand All @@ -205,6 +208,25 @@ properties:
platforms: [android, iphone, ipad, macos]
since: {android: "9.3.0", iphone: "6.1.0", ipad: "6.1.0", macos: "9.2.0"}

- name: badgeBackgroundColor
summary: |
If this item displays a badge, this color will be used for the badge's background.
If set to null, the default background color will be used instead.
description: |
For information about color values, see the "Colors" section of <Titanium.UI>.
type: [String, Titanium.UI.Color]
platforms: [android, iphone, ipad, macos]
since: {android: "12.2.0"}

- name: badgeTextColor
summary: |
Set the text color of the badge.
description: |
For information about color values, see the "Colors" section of <Titanium.UI>.
type: [String, Titanium.UI.Color]
platforms: [android]
since: {android: "12.2.0"}

- name: icon
summary: Icon URL for this tab.
description: |
Expand Down
Loading