Skip to content

Commit

Permalink
feat(android): tabbedbar color properties (#13540)
Browse files Browse the repository at this point in the history
* feat(android): tabbedbar color properties

* match ios
  • Loading branch information
m1ga authored Sep 10, 2022
1 parent 10f084f commit 2453af6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.view.MenuItem;
import androidx.annotation.ColorInt;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.color.MaterialColors;
import com.google.android.material.tabs.TabLayout;
Expand All @@ -21,6 +23,7 @@
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.R;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiColorHelper;
Expand Down Expand Up @@ -102,7 +105,37 @@ protected void onLayout(boolean changed, int l, int t, int r, int b)
// Note: By default it uses a gray ripple for unselected tabs which doesn't match Google's own apps.
int colorPrimary = getTabRippleColorFrom(this.tabLayout.getContext());
this.tabLayout.setTabRippleColor(TiUIAbstractTabGroup.createRippleColorStateListFrom(colorPrimary));
if (getProxy().hasPropertyAndNotNull(TiC.PROPERTY_SELECTED_TEXT_COLOR)
|| getProxy().hasPropertyAndNotNull(TiC.PROPERTY_TEXT_COLOR)) {
// get default colors
int selectedTextColor = activity.getResources().getColor(R.color.ti_light_primary);
int textColor = tabLayout.getTabTextColors().getDefaultColor();
Configuration config;

// if night mode get dark default color
if (activity != null) {
config = activity.getResources().getConfiguration();
} else {
config = TiApplication.getInstance().getResources().getConfiguration();
}
if ((config.uiMode & Configuration.UI_MODE_NIGHT_YES) != 0) {
selectedTextColor = activity.getResources().getColor(R.color.ti_dark_primary);
}

// assign new colors
if (getProxy().hasPropertyAndNotNull(TiC.PROPERTY_TEXT_COLOR)) {
textColor = TiConvert.toColor(getProxy().getProperties().getString(TiC.PROPERTY_TEXT_COLOR), activity);
}
if (getProxy().hasPropertyAndNotNull(TiC.PROPERTY_SELECTED_TEXT_COLOR)) {
selectedTextColor =
TiConvert.toColor(getProxy().getProperties().getString(TiC.PROPERTY_SELECTED_TEXT_COLOR), activity);
} else if (getProxy().hasPropertyAndNotNull(TiC.PROPERTY_TEXT_COLOR)) {
// no selected color specified but a text color -> use that
selectedTextColor = textColor;
}

this.tabLayout.setTabTextColors(textColor, selectedTextColor);
}
setNativeView(this.tabLayout);
}

Expand Down
2 changes: 2 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ public class TiC
public static final String PROPERTY_SELECTION_INDICATOR = "selectionIndicator";
public static final String PROPERTY_SELECTION_OPENS = "selectionOpens";
public static final String PROPERTY_SELECTED_ROWS = "selectedRows";
public static final String PROPERTY_SELECTED_TEXT_COLOR = "selectedTextColor";
public static final String PROPERTY_SELECTION_STYLE = "selectionStyle";
public static final String PROPERTY_SEPARATOR_COLOR = "separatorColor";
public static final String PROPERTY_SEPARATOR_HEIGHT = "separatorHeight";
Expand Down Expand Up @@ -748,6 +749,7 @@ public class TiC
public static final String PROPERTY_TEMPLATE = "template";
public static final String PROPERTY_TEMPLATES = "templates";
public static final String PROPERTY_TEXT = "text";
public static final String PROPERTY_TEXT_COLOR = "textColor";
public static final String PROPERTY_TEXTID = "textid";
public static final String PROPERTY_THEME = "theme";
public static final String PROPERTY_TEXT_ALIGN = "textAlign";
Expand Down
32 changes: 22 additions & 10 deletions apidoc/Titanium/UI/TabbedBar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ summary: A button bar that maintains a selected state.
description: |
A tabbed bar is a button bar that
maintains a state (visually distinguished as a pressed or selected look).
It is closely related to the `ButtonBar` control. See the description of
It is closely related to the `ButtonBar` control. See the description of
[ButtonBar](Titanium.UI.ButtonBar) for information on styling tabbed bars and buttons
bars.
Use the <Titanium.UI.createTabbedBar> method to create a Tabbed Bar.
extends: Titanium.UI.View
platforms: [iphone, ipad, android, macos]
Expand All @@ -19,38 +19,50 @@ excludes:
properties: [children]
methods: [add, remove, removeAllChildren, replaceAt]

events:
events:
- name: click
summary: Fired when a button is clicked.
properties:
properties:
- name: index
summary: Index of the clicked button.
summary: Index of the clicked button.
type: Number
properties:
- name: index
summary: Index of the currently selected button.
type: Number
- name: labels
summary: Array of labels for the tabbed bar.
summary: Array of labels for the tabbed bar.
description: |
The labels can be specified either using an array of strings, in which case
each string defines the title for a button, or using an array of simple
dictionary objects, <BarItemType>, which can specify title, image, width and
dictionary objects, <BarItemType>, which can specify title, image, width and
enabled state for each button.
type: [Array<String>, Array<BarItemType>]
- name: textColor
summary: Color of the text
type: [ String, Titanium.UI.Color ]
availability: creation
platforms: [iphone, ipad, android, macos]
since: {iphone: "9.0.0", ipad: "9.0.0", android: "12.0.0"}
- name: selectedTextColor
summary: Color of the selected text
type: [ String, Titanium.UI.Color ]
availability: creation
platforms: [iphone, ipad, android, macos]
since: {iphone: "9.0.0", ipad: "9.0.0", android: "12.0.0"}
- name: style
summary: Style of the tabbed bar.
description: |
Specify one of the constants:
For iOS:
For iOS:
[Titanium.UI.iOS.SystemButtonStyle](Titanium.UI.iOS.SystemButtonStyle),
either `PLAIN`, `BORDERED`, or `BAR`.
The `BAR` style specifies a more compact style and allows the bar's background
color or gradient to show through.
For Android:
[Titanium.UI.TABS_STYLE_*]
In Android [style](Titanium.UI.TabbedBar.style) is only supported in the creation dictionary
In Android [style](Titanium.UI.TabbedBar.style) is only supported in the creation dictionary
of the proxy.
type: Number
default: Titanium.UI.iOS.SystemButtonStyle.PLAIN for iOS, Ti.UI.TABS_STYLE_DEFAULT for Android
Expand Down

0 comments on commit 2453af6

Please sign in to comment.