Skip to content

Commit

Permalink
Merge branch 'master' into TIMOB-28404
Browse files Browse the repository at this point in the history
  • Loading branch information
sgtcoolguy committed Apr 2, 2021
2 parents 8c7a19d + be93510 commit df8850e
Show file tree
Hide file tree
Showing 14 changed files with 225 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,25 @@ public void addTab(TabProxy tabProxy)
addTabItemInController(tabProxy);
}

/**
* Determines if given tab needs to call textColorStateList() for custom text color handling.
* @param tabProxy The tab to check for custom color properties. Can be null.
* @return Returns true if textColorStateList() needs to be called.
*/
protected boolean hasCustomTextColor(TiViewProxy tabProxy)
{
// Do not continue if released.
if ((this.proxy == null) || (tabProxy == null)) {
return false;
}

// Check if the properties used by the textColorStateList() method are defined.
return this.proxy.hasProperty(TiC.PROPERTY_TITLE_COLOR)
|| this.proxy.hasProperty(TiC.PROPERTY_ACTIVE_TITLE_COLOR)
|| tabProxy.hasProperty(TiC.PROPERTY_TITLE_COLOR)
|| tabProxy.hasProperty(TiC.PROPERTY_ACTIVE_TITLE_COLOR);
}

/**
* Method for creating a ColorStateList instance usef for item in the Controller.
* It creates a ColorStateList with two states - one for the provided parameter and
Expand All @@ -281,7 +300,10 @@ protected ColorStateList textColorStateList(TiViewProxy tabProxy, int stateToUse
}

int[][] textColorStates = new int[][] { new int[] { -stateToUse }, new int[] { stateToUse } };
int[] textColors = { this.colorOnSurfaceInt, this.colorPrimaryInt };
int[] textColors = {
ColorUtils.setAlphaComponent(this.colorOnSurfaceInt, 153), // 60% opacity
this.colorPrimaryInt
};

final KrollDict tabProperties = tabProxy.getProperties();
final KrollDict properties = getProxy().getProperties();
Expand All @@ -301,6 +323,25 @@ protected ColorStateList textColorStateList(TiViewProxy tabProxy, int stateToUse
return new ColorStateList(textColorStates, textColors);
}

/**
* Determines if given tab needs to call createBackgroundDrawableForState() for custom background color handling.
* @param tabProxy The tab to check for custom color properties. Can be null.
* @return Returns true if createBackgroundDrawableForState() needs to be called.
*/
protected boolean hasCustomBackground(TiViewProxy tabProxy)
{
// Do not continue if released.
if ((this.proxy == null) || (tabProxy == null)) {
return false;
}

// Check if the properties used by the createBackgroundDrawableForState() method are defined.
return this.proxy.hasProperty(TiC.PROPERTY_TABS_BACKGROUND_COLOR)
|| this.proxy.hasProperty(TiC.PROPERTY_TABS_BACKGROUND_SELECTED_COLOR)
|| tabProxy.hasProperty(TiC.PROPERTY_BACKGROUND_COLOR)
|| tabProxy.hasProperty(TiC.PROPERTY_BACKGROUND_FOCUSED_COLOR);
}

/**
* Method for creating a RippleDrawable to be used as a bacgkround for an item in the Controller.
* Creates the RippleDrawable for two states - the provided state and its negative value.
Expand Down Expand Up @@ -459,6 +500,20 @@ public void updateTitle(String title)
}
}

public boolean hasCustomIconTint(TiViewProxy tabProxy)
{
// Do not continue if released.
if ((this.proxy == null) || (tabProxy == null)) {
return false;
}

// Check if the properties used by the updateIconTint() method are defined.
return this.proxy.hasProperty(TiC.PROPERTY_ACTIVE_TINT_COLOR)
|| this.proxy.hasProperty(TiC.PROPERTY_TINT_COLOR)
|| tabProxy.hasProperty(TiC.PROPERTY_ACTIVE_TINT_COLOR)
|| tabProxy.hasProperty(TiC.PROPERTY_TINT_COLOR);
}

public Drawable updateIconTint(TiViewProxy tabProxy, Drawable drawable, boolean selected)
{
if (drawable == null) {
Expand All @@ -481,7 +536,7 @@ public Drawable updateIconTint(TiViewProxy tabProxy, Drawable drawable, boolean
}
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
} else {
color = this.colorOnSurfaceInt;
color = ColorUtils.setAlphaComponent(this.colorOnSurfaceInt, 153); // 60% opacity
if (tabProperties.containsKeyAndNotNull(TiC.PROPERTY_TINT_COLOR)
|| properties.containsKeyAndNotNull(TiC.PROPERTY_TINT_COLOR)) {
final String colorString = tabProperties.optString(TiC.PROPERTY_TINT_COLOR,
Expand All @@ -500,6 +555,18 @@ protected int getColorPrimary()
return this.colorPrimaryInt;
}

@ColorInt
protected int getActiveColor(TiViewProxy tabProxy)
{
Object colorObject = null;
if ((tabProxy != null) && tabProxy.hasPropertyAndNotNull(TiC.PROPERTY_ACTIVE_TINT_COLOR)) {
colorObject = tabProxy.getProperty(TiC.PROPERTY_ACTIVE_TINT_COLOR);
} else if ((this.proxy != null) && this.proxy.hasPropertyAndNotNull(TiC.PROPERTY_ACTIVE_TINT_COLOR)) {
colorObject = this.proxy.getProperty(TiC.PROPERTY_ACTIVE_TINT_COLOR);
}
return (colorObject != null) ? TiColorHelper.parseColor(colorObject.toString()) : this.colorPrimaryInt;
}

public static ColorStateList createRippleColorStateListFrom(@ColorInt int colorInt)
{
int[][] rippleStates = new int[][] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ protected void onLayout(boolean hasChanged, int left, int top, int right, int bo
}
};
this.mBottomNavigationView.setFitsSystemWindows(true);
this.mBottomNavigationView.setItemRippleColor(
TiUIAbstractTabGroup.createRippleColorStateListFrom(getColorPrimary()));

// Add tab bar and view pager to the root Titanium view.
// Note: If getFitsSystemWindows() returns false, then Titanium window's "extendSafeArea" is set true.
Expand Down Expand Up @@ -256,13 +258,15 @@ public void setBackgroundColor(int colorInt)
public void updateTabBackgroundDrawable(int index)
{
try {
BottomNavigationMenuView bottomMenuView =
((BottomNavigationMenuView) this.mBottomNavigationView.getChildAt(0));
// BottomNavigationMenuView rebuilds itself after adding a new item, so we need to reset the colors each time.
TiViewProxy tabProxy = tabs.get(index).getProxy();
Drawable drawable = createBackgroundDrawableForState(tabProxy, android.R.attr.state_checked);
drawable = new RippleDrawable(createRippleColorStateListFrom(getColorPrimary()), drawable, null);
bottomMenuView.getChildAt(index).setBackground(drawable);
if (hasCustomBackground(tabProxy) || hasCustomIconTint(tabProxy)) {
BottomNavigationMenuView bottomMenuView =
((BottomNavigationMenuView) this.mBottomNavigationView.getChildAt(0));
Drawable drawable = createBackgroundDrawableForState(tabProxy, android.R.attr.state_checked);
drawable = new RippleDrawable(createRippleColorStateListFrom(getActiveColor(tabProxy)), drawable, null);
bottomMenuView.getChildAt(index).setBackground(drawable);
}
} catch (Exception e) {
Log.w(TAG, WARNING_LAYOUT_MESSAGE);
}
Expand Down Expand Up @@ -336,13 +340,15 @@ public void updateBadgeColor(int index)
public void updateTabTitleColor(int index)
{
try {
BottomNavigationMenuView bottomMenuView =
((BottomNavigationMenuView) this.mBottomNavigationView.getChildAt(0));
// BottomNavigationMenuView rebuilds itself after adding a new item, so we need to reset the colors each time.
TiViewProxy tabProxy = tabs.get(index).getProxy();
// Set the TextView textColor.
((BottomNavigationItemView) bottomMenuView.getChildAt(index))
.setTextColor(textColorStateList(tabProxy, android.R.attr.state_checked));
if (hasCustomTextColor(tabProxy)) {
// Set the TextView textColor.
BottomNavigationMenuView bottomMenuView =
((BottomNavigationMenuView) this.mBottomNavigationView.getChildAt(0));
((BottomNavigationItemView) bottomMenuView.getChildAt(index))
.setTextColor(textColorStateList(tabProxy, android.R.attr.state_checked));
}
} catch (Exception e) {
Log.w(TAG, WARNING_LAYOUT_MESSAGE);
}
Expand Down Expand Up @@ -410,9 +416,8 @@ public boolean onMenuItemClick(MenuItem item)
private void updateIconTint()
{
for (int i = 0; i < this.tabs.size(); i++) {
final TiUITab tab = this.tabs.get(i);
if (tab.getProxy() != null) {
final TiViewProxy tabProxy = tab.getProxy();
final TiViewProxy tabProxy = this.tabs.get(i).getProxy();
if (hasCustomIconTint(tabProxy)) {
final boolean selected = i == currentlySelectedIndex;
Drawable drawable = this.mBottomNavigationView.getMenu().getItem(i).getIcon();
drawable = updateIconTint(tabProxy, drawable, selected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class TiUITabLayoutTabGroup extends TiUIAbstractTabGroup implements TabLa
{
// region private fields
private TabLayout mTabLayout;
private boolean mHasChangedRippleColor;
// endregion

public TiUITabLayoutTabGroup(TabGroupProxy proxy, TiBaseActivity activity)
Expand Down Expand Up @@ -105,6 +106,7 @@ protected void onConfigurationChanged(Configuration newConfig)
}
};
this.mTabLayout.setFitsSystemWindows(true);
this.mTabLayout.setTabRippleColor(createRippleColorStateListFrom(getColorPrimary()));

// Set the OnTabSelected listener.
this.mTabLayout.addOnTabSelectedListener(this);
Expand Down Expand Up @@ -213,10 +215,12 @@ public void updateTabBackgroundDrawable(int index)
return;
}

if (!hasCustomBackground(tabProxy)) {
return;
}

Drawable backgroundDrawable = createBackgroundDrawableForState(tabProxy, android.R.attr.state_selected);
this.mTabLayout.setBackground(backgroundDrawable);
this.mTabLayout.setTabRippleColor(createRippleColorStateListFrom(getColorPrimary()));
this.mTabLayout.setUnboundedRipple(true);
}

@Override
Expand Down Expand Up @@ -247,6 +251,10 @@ public void updateTabTitleColor(int index)
return;
}

if (!hasCustomTextColor(tabProxy)) {
return;
}

try {
final LinearLayout tabLayout = getTabLinearLayoutForIndex(index);
// Set the TextView textColor.
Expand Down Expand Up @@ -392,9 +400,8 @@ private LinearLayout getTabLinearLayoutForIndex(int index)
private void updateIconTint()
{
for (int i = 0; i < this.tabs.size(); i++) {
final TiUITab tab = this.tabs.get(i);
if (tab.getProxy() != null) {
final TiViewProxy tabProxy = tab.getProxy();
final TiViewProxy tabProxy = this.tabs.get(i).getProxy();
if (hasCustomIconTint(tabProxy)) {
final boolean selected = i == this.mTabLayout.getSelectedTabPosition();
Drawable drawable = this.mTabLayout.getTabAt(i).getIcon();
drawable = updateIconTint(tabProxy, drawable, selected);
Expand All @@ -408,8 +415,22 @@ public void selectTab(int tabIndex)
{
super.selectTab(tabIndex);

// Update the selected tab's colors. (TabLayour resets colors when a selection is made.)
updateIconTint();
updateTabBackgroundDrawable(tabIndex);

// Update ripple and tab underline color to match selected tab's tint color.
// Note: Only do this if custom colors properties are defined since this will prevent selection animation.
if ((tabIndex >= 0) && (tabIndex < this.tabs.size())) {
final TiViewProxy tabProxy = this.tabs.get(tabIndex).getProxy();
if (mHasChangedRippleColor || hasCustomIconTint(tabProxy)) {
int activeColor = getActiveColor(tabProxy);
this.mTabLayout.setTabRippleColor(createRippleColorStateListFrom(activeColor));
this.mTabLayout.setSelectedTabIndicatorColor(activeColor);
this.mTabLayout.setUnboundedRipple(true);
mHasChangedRippleColor = true;
}
}
}

public static void scaleIconToFit(TabLayout.Tab tab)
Expand Down
6 changes: 6 additions & 0 deletions android/templates/build/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,10 @@ public void onCreate()
<% }); %>
<% } %>
}

@Override
public void verifyCustomModules(TiRootActivity rootActivity)
{
// This method is needed by the "appc" CLI.
}
}
Binary file modified android/titanium/lib/aps-analytics.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -994,4 +994,12 @@ public AccessibilityManager getAccessibilityManager()
}
return accessibilityManager;
}

/**
* To be overridden by app template "./android/templates/app/App.java" to verify Titanium modules.
* @param rootActivity Splash screen activity needed to display a module verification error dialog.
*/
public void verifyCustomModules(TiRootActivity rootActivity)
{
}
}
3 changes: 2 additions & 1 deletion apidoc/Titanium/UI/Tab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ properties:
- name: backgroundFocusedColor
summary: Sets the color of the tab when it is focused.
description: |
On the Android platform, this sets the color of the active tab.
On the Android platform, this sets the color of the active tab and is only supported by
[TABS_STYLE_BOTTOM_NAVIGATION](Titanium.UI.Android.TABS_STYLE_BOTTOM_NAVIGATION).
For information about color values, see the "Colors" section of <Titanium.UI>.
platforms: [android]
Expand Down
34 changes: 33 additions & 1 deletion apidoc/Titanium/UI/TabGroup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@ methods:
platforms: [android]
since: 3.6.0

- name: getActiveTab
summary: Gets the currently-active tab.
returns:
type: Titanium.UI.Tab
deprecated:
since: "10.0.0"
removed: "10.0.0"
notes: Use the <Titanium.UI.TabGroup.activeTab> property instead.

- name: open
summary: Opens the tab group and makes it visible.

Expand All @@ -263,6 +272,26 @@ methods:
summary: Tab to remove.
type: Titanium.UI.Tab

- name: setActiveTab
summary: Selects the currently active tab in a tab group.
parameters:
- name: indexOrObject
summary: Index or object of the tab to switch to.
type: [Number, Titanium.UI.Tab]
deprecated:
since: "10.0.0"
removed: "10.0.0"
notes: Use the <Titanium.UI.TabGroup.activeTab> property instead.

- name: getTabs
summary: Gets all tabs that are managed by the tab group.
returns:
type: Array<Titanium.UI.Tab>
deprecated:
since: "10.0.0"
removed: "10.0.0"
notes: Use the <Titanium.UI.TabGroup.tabs> property instead.

properties:
- name: activeTab
summary: Active tab.
Expand Down Expand Up @@ -555,7 +584,10 @@ properties:
description: |
For information about color values, see the "Colors" section of <Titanium.UI>.
A tab's [backgroundSelectedColor](Titanium.UI.Tab.backgroundSelectedColor) property takes
This property is only supported by
[TABS_STYLE_BOTTOM_NAVIGATION](Titanium.UI.Android.TABS_STYLE_BOTTOM_NAVIGATION).
A tab's [backgroundFocusedColor](Titanium.UI.Tab.backgroundFocusedColor) property takes
precedence if set.
type: String
platforms: [android]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<key>HeadersPath</key>
<string>Headers</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<string>ios-arm64_x86_64-maccatalyst</string>
<key>LibraryPath</key>
<string>libAPSAnalytics.a</string>
<key>SupportedArchitectures</key>
Expand All @@ -19,38 +19,38 @@
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
<string>maccatalyst</string>
</dict>
<dict>
<key>HeadersPath</key>
<string>Headers</string>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>libAPSAnalytics.a</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>HeadersPath</key>
<string>Headers</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-maccatalyst</string>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>libAPSAnalytics.a</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>maccatalyst</string>
</dict>
</array>
<key>CFBundlePackageType</key>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit df8850e

Please sign in to comment.