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

fix(android): fix tintColor and activeTintColor in a TabbedBar #14088

Merged
merged 6 commits into from
Aug 20, 2024
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 @@ -10,6 +10,7 @@
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.view.MenuItem;
import androidx.annotation.ColorInt;
Expand Down Expand Up @@ -133,9 +134,11 @@ protected void onLayout(boolean changed, int l, int t, int r, int b)
// no selected color specified but a text color -> use that
selectedTextColor = textColor;
}

this.tabLayout.setTabTextColors(textColor, selectedTextColor);
}
if (getProxy().hasPropertyAndNotNull(TiC.PROPERTY_ACTIVE_TINT_COLOR)) {
setTintColor(this.tabLayout.getTabAt(0), TiC.PROPERTY_ACTIVE_TINT_COLOR);
}
setNativeView(this.tabLayout);
}

Expand Down Expand Up @@ -261,6 +264,10 @@ private void addItem(Object value)
if (value instanceof Drawable) {
tab.setIcon(((Drawable) value));
TiUITabLayoutTabGroup.scaleIconToFit(tab);

if (proxy.hasPropertyAndNotNull(TiC.PROPERTY_TINT_COLOR)) {
setTintColor(tab, TiC.PROPERTY_TINT_COLOR);
}
} else {
tab.setText(value.toString());
}
Expand All @@ -282,6 +289,14 @@ private void addItem(Object value)
}
}

private void setTintColor(TabLayout.Tab tab, String color)
{
if (tab != null && tab.getIcon() != null) {
tab.getIcon().setColorFilter(TiConvert.toColor(proxy.getProperty(color),
TiApplication.getAppCurrentActivity()), PorterDuff.Mode.SRC_IN);
}
}

// Handle switching styles after creation
public void setNewStyle(int newStyle)
{
Expand Down Expand Up @@ -394,6 +409,10 @@ private void onTabIndexChangedTo(int index)
// First, update the proxy's "index" property.
proxy.setProperty(TiC.PROPERTY_INDEX, index);

if (proxy.hasPropertyAndNotNull(TiC.PROPERTY_ACTIVE_TINT_COLOR)) {
setTintColor(this.tabLayout.getTabAt(index), TiC.PROPERTY_ACTIVE_TINT_COLOR);
}

// Last, fire a "click" event.
if (!skipClickEvent) {
KrollDict data = new KrollDict();
Expand All @@ -406,7 +425,10 @@ private void onTabIndexChangedTo(int index)
@Override
public void onTabUnselected(TabLayout.Tab tab)
{
// No override
// set old tint color again
if (proxy.hasPropertyAndNotNull(TiC.PROPERTY_TINT_COLOR)) {
setTintColor(tab, TiC.PROPERTY_TINT_COLOR);
}
}

@Override
Expand Down
8 changes: 7 additions & 1 deletion apidoc/Titanium/UI/TabbedBar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ properties:
availability: creation
platforms: [iphone, ipad, android, macos]
since: {iphone: "9.0.0", ipad: "9.0.0", android: "12.0.0"}
- name: activeTintColor
summary: Icon tint color of the selected tab
type: [ String, Titanium.UI.Color ]
availability: creation
platforms: [android]
since: {android: "12.5.0"}
- name: style
summary: Style of the tabbed bar.
description: |
Expand All @@ -66,7 +72,7 @@ properties:

The `BAR` style specifies a more compact style and allows the bar's background
color or gradient to show through.

For Android use [Titanium.UI.TABS_STYLE_DEFAULT](Titanium.UI.TABS_STYLE_DEFAULT) or
[Titanium.UI.TABS_STYLE_BOTTOM_NAVIGATION](Titanium.UI.TABS_STYLE_BOTTOM_NAVIGATION) and
it is only supported in the creation dictionary of the proxy.
Expand Down
Loading