Skip to content

Commit 30add00

Browse files
Added activeIndicator color in android (#83)
* feat: added active indicator color option * feat: added support for new arch * feat: added example * fix: removed color fro native bottom tabs * feat: doc updated * feat: doc updated
1 parent ac97ff2 commit 30add00

File tree

9 files changed

+41
-0
lines changed

9 files changed

+41
-0
lines changed

android/src/main/java/com/rcttabview/RCTTabView.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
193193
updateTintColors()
194194
}
195195

196+
fun setActiveIndicatorColor(color: ColorStateList) {
197+
itemActiveIndicatorColor = color
198+
}
199+
196200
private fun updateTintColors(item: MenuItem? = null) {
197201
// First let's check current item color.
198202
val currentItemTintColor = items?.find { it.title == item?.title }?.activeTintColor

android/src/main/java/com/rcttabview/RCTTabViewImpl.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ class RCTTabViewImpl {
6262
}
6363
}
6464

65+
fun setActiveIndicatorColor(view: ReactBottomNavigationView, color: Int?) {
66+
if (color != null) {
67+
val color = ColorStateList.valueOf(color)
68+
view.setActiveIndicatorColor(color)
69+
}
70+
}
71+
6572
fun setActiveTintColor(view: ReactBottomNavigationView, color: Int?) {
6673
view.setActiveTintColor(color)
6774
}

android/src/newarch/RCTTabViewManager.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ class RCTTabViewManager(context: ReactApplicationContext) :
8989
tabViewImpl.setInactiveTintColor(view, value)
9090
}
9191

92+
override fun setActiveIndicatorColor(view: ReactBottomNavigationView?, value: Int?) {
93+
if (view != null && value != null)
94+
tabViewImpl.setActiveIndicatorColor(view, value)
95+
}
96+
9297
override fun getDelegate(): ViewManagerDelegate<ReactBottomNavigationView> {
9398
return delegate
9499
}

android/src/oldarch/RCTTabViewManager.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ class RCTTabViewManager(context: ReactApplicationContext) : SimpleViewManager<Re
9090
tabViewImpl.setInactiveTintColor(view, color)
9191
}
9292

93+
@ReactProp(name = "activeIndicatorColor", customType = "Color")
94+
fun setActiveIndicatorColor(view: ReactBottomNavigationView, color: Int?) {
95+
tabViewImpl.setActiveIndicatorColor(view, color)
96+
}
97+
9398
// iOS Props
9499

95100
@ReactProp(name = "sidebarAdaptable")

docs/docs/docs/guides/usage-with-react-navigation.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ Color for the inactive tabs.
7777

7878
Background color of the tab bar.
7979

80+
#### `activeIndicatorColor` <Badge text="android" type="info" />
81+
82+
Color of tab indicator. This option is only compatible with Material3 themes.
83+
8084
#### `translucent` <Badge text="iOS" type="info" />
8185

8286
A Boolean value that indicates whether the tab bar is translucent.

example/src/App.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ const FourTabsTranslucent = () => {
5454
return <FourTabs translucent={false} />;
5555
};
5656

57+
const FourTabsActiveIndicatorColor = () => {
58+
return <FourTabs activeIndicatorColor={'#87CEEB'} />;
59+
};
60+
5761
const examples = [
5862
{ component: ThreeTabs, name: 'Three Tabs' },
5963
{ component: FourTabs, name: 'Four Tabs' },
@@ -81,6 +85,10 @@ const examples = [
8185
component: FourTabsTranslucent,
8286
name: 'Four Tabs - Translucent tab bar',
8387
},
88+
{
89+
component: FourTabsActiveIndicatorColor,
90+
name: 'Four Tabs - Active Indicator color',
91+
},
8492
{ component: NativeBottomTabs, name: 'Native Bottom Tabs' },
8593
{ component: JSBottomTabs, name: 'JS Bottom Tabs' },
8694
{

example/src/Examples/FourTabs.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface Props {
1313
barTintColor?: ColorValue;
1414
translucent?: boolean;
1515
rippleColor?: ColorValue;
16+
activeIndicatorColor?: ColorValue;
1617
}
1718

1819
export default function FourTabs({
@@ -22,6 +23,7 @@ export default function FourTabs({
2223
barTintColor,
2324
translucent = true,
2425
rippleColor,
26+
activeIndicatorColor,
2527
}: Props) {
2628
const [index, setIndex] = useState(0);
2729
const [routes] = useState([
@@ -69,6 +71,7 @@ export default function FourTabs({
6971
barTintColor={barTintColor}
7072
translucent={translucent}
7173
rippleColor={rippleColor}
74+
activeIndicatorColor={activeIndicatorColor}
7275
/>
7376
);
7477
}

src/TabView.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ interface Props<Route extends BaseRoute> {
110110
*/
111111
translucent?: boolean;
112112
rippleColor?: ColorValue;
113+
/**
114+
* Color of tab indicator. (Android only)
115+
*/
116+
activeIndicatorColor?: ColorValue;
113117
}
114118

115119
const ANDROID_MAX_TABS = 6;

src/TabViewNativeComponent.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface TabViewProps extends ViewProps {
3232
inactiveTintColor?: ColorValue;
3333
ignoresTopSafeArea?: boolean;
3434
disablePageAnimations?: boolean;
35+
activeIndicatorColor?: ColorValue;
3536
}
3637

3738
export default codegenNativeComponent<TabViewProps>('RNCTabView', {

0 commit comments

Comments
 (0)