Skip to content

Commit 2e92f1d

Browse files
m1gacb1kenobi
andauthored
fix(android): fix tintColor and activeTintColor in a TabbedBar (#14088)
* fix(android): fix tintColor and activeTintColor in a TabbedBar * apidocs * use method and add guards * more functions --------- Co-authored-by: Chris Barber <[email protected]>
1 parent 5fc81f0 commit 2e92f1d

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUITabbedBar.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.content.Context;
1111
import android.content.res.Configuration;
1212
import android.graphics.Color;
13+
import android.graphics.PorterDuff;
1314
import android.graphics.drawable.Drawable;
1415
import android.view.MenuItem;
1516
import androidx.annotation.ColorInt;
@@ -133,9 +134,11 @@ protected void onLayout(boolean changed, int l, int t, int r, int b)
133134
// no selected color specified but a text color -> use that
134135
selectedTextColor = textColor;
135136
}
136-
137137
this.tabLayout.setTabTextColors(textColor, selectedTextColor);
138138
}
139+
if (getProxy().hasPropertyAndNotNull(TiC.PROPERTY_ACTIVE_TINT_COLOR)) {
140+
setTintColor(this.tabLayout.getTabAt(0), TiC.PROPERTY_ACTIVE_TINT_COLOR);
141+
}
139142
setNativeView(this.tabLayout);
140143
}
141144

@@ -261,6 +264,10 @@ private void addItem(Object value)
261264
if (value instanceof Drawable) {
262265
tab.setIcon(((Drawable) value));
263266
TiUITabLayoutTabGroup.scaleIconToFit(tab);
267+
268+
if (proxy.hasPropertyAndNotNull(TiC.PROPERTY_TINT_COLOR)) {
269+
setTintColor(tab, TiC.PROPERTY_TINT_COLOR);
270+
}
264271
} else {
265272
tab.setText(value.toString());
266273
}
@@ -282,6 +289,14 @@ private void addItem(Object value)
282289
}
283290
}
284291

292+
private void setTintColor(TabLayout.Tab tab, String color)
293+
{
294+
if (tab != null && tab.getIcon() != null) {
295+
tab.getIcon().setColorFilter(TiConvert.toColor(proxy.getProperty(color),
296+
TiApplication.getAppCurrentActivity()), PorterDuff.Mode.SRC_IN);
297+
}
298+
}
299+
285300
// Handle switching styles after creation
286301
public void setNewStyle(int newStyle)
287302
{
@@ -394,6 +409,10 @@ private void onTabIndexChangedTo(int index)
394409
// First, update the proxy's "index" property.
395410
proxy.setProperty(TiC.PROPERTY_INDEX, index);
396411

412+
if (proxy.hasPropertyAndNotNull(TiC.PROPERTY_ACTIVE_TINT_COLOR)) {
413+
setTintColor(this.tabLayout.getTabAt(index), TiC.PROPERTY_ACTIVE_TINT_COLOR);
414+
}
415+
397416
// Last, fire a "click" event.
398417
if (!skipClickEvent) {
399418
KrollDict data = new KrollDict();
@@ -406,7 +425,10 @@ private void onTabIndexChangedTo(int index)
406425
@Override
407426
public void onTabUnselected(TabLayout.Tab tab)
408427
{
409-
// No override
428+
// set old tint color again
429+
if (proxy.hasPropertyAndNotNull(TiC.PROPERTY_TINT_COLOR)) {
430+
setTintColor(tab, TiC.PROPERTY_TINT_COLOR);
431+
}
410432
}
411433

412434
@Override

apidoc/Titanium/UI/TabbedBar.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ properties:
5656
availability: creation
5757
platforms: [iphone, ipad, android, macos]
5858
since: {iphone: "9.0.0", ipad: "9.0.0", android: "12.0.0"}
59+
- name: activeTintColor
60+
summary: Icon tint color of the selected tab
61+
type: [ String, Titanium.UI.Color ]
62+
availability: creation
63+
platforms: [android]
64+
since: {android: "12.5.0"}
5965
- name: style
6066
summary: Style of the tabbed bar.
6167
description: |
@@ -66,7 +72,7 @@ properties:
6672
6773
The `BAR` style specifies a more compact style and allows the bar's background
6874
color or gradient to show through.
69-
75+
7076
For Android use [Titanium.UI.TABS_STYLE_DEFAULT](Titanium.UI.TABS_STYLE_DEFAULT) or
7177
[Titanium.UI.TABS_STYLE_BOTTOM_NAVIGATION](Titanium.UI.TABS_STYLE_BOTTOM_NAVIGATION) and
7278
it is only supported in the creation dictionary of the proxy.

0 commit comments

Comments
 (0)