Skip to content
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
4 changes: 4 additions & 0 deletions android/src/main/java/com/rcttabview/RCTTabView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
updateTintColors()
}

fun setActiveIndicatorColor(color: ColorStateList) {
itemActiveIndicatorColor = color
}

private fun updateTintColors(item: MenuItem? = null) {
// First let's check current item color.
val currentItemTintColor = items?.find { it.title == item?.title }?.activeTintColor
Expand Down
7 changes: 7 additions & 0 deletions android/src/main/java/com/rcttabview/RCTTabViewImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ class RCTTabViewImpl {
}
}

fun setActiveIndicatorColor(view: ReactBottomNavigationView, color: Int?) {
if (color != null) {
val color = ColorStateList.valueOf(color)
view.setActiveIndicatorColor(color)
}
}

fun setActiveTintColor(view: ReactBottomNavigationView, color: Int?) {
view.setActiveTintColor(color)
}
Expand Down
5 changes: 5 additions & 0 deletions android/src/newarch/RCTTabViewManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ class RCTTabViewManager(context: ReactApplicationContext) :
tabViewImpl.setInactiveTintColor(view, value)
}

override fun setActiveIndicatorColor(view: ReactBottomNavigationView?, value: Int?) {
if (view != null && value != null)
tabViewImpl.setActiveIndicatorColor(view, value)
}

override fun getDelegate(): ViewManagerDelegate<ReactBottomNavigationView> {
return delegate
}
Expand Down
5 changes: 5 additions & 0 deletions android/src/oldarch/RCTTabViewManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ class RCTTabViewManager(context: ReactApplicationContext) : SimpleViewManager<Re
tabViewImpl.setInactiveTintColor(view, color)
}

@ReactProp(name = "activeIndicatorColor", customType = "Color")
fun setActiveIndicatorColor(view: ReactBottomNavigationView, color: Int?) {
tabViewImpl.setActiveIndicatorColor(view, color)
}

// iOS Props

@ReactProp(name = "sidebarAdaptable")
Expand Down
4 changes: 4 additions & 0 deletions docs/docs/docs/guides/usage-with-react-navigation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ Color for the inactive tabs.

Background color of the tab bar.

#### `activeIndicatorColor` <Badge text="android" type="info" />

Color of tab indicator. This option is only compatible with Material3 themes.

#### `translucent` <Badge text="iOS" type="info" />

A Boolean value that indicates whether the tab bar is translucent.
Expand Down
8 changes: 8 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
return <FourTabs translucent={false} />;
};

const FourTabsActiveIndicatorColor = () => {
return <FourTabs activeIndicatorColor={'#87CEEB'} />;
};

const examples = [
{ component: ThreeTabs, name: 'Three Tabs' },
{ component: FourTabs, name: 'Four Tabs' },
Expand Down Expand Up @@ -81,6 +85,10 @@
component: FourTabsTranslucent,
name: 'Four Tabs - Translucent tab bar',
},
{
component: FourTabsActiveIndicatorColor,
name: 'Four Tabs - Active Indicator color',
},
{ component: NativeBottomTabs, name: 'Native Bottom Tabs' },
{ component: JSBottomTabs, name: 'JS Bottom Tabs' },
{
Expand Down Expand Up @@ -131,7 +139,7 @@
name="BottomTabs Example"
component={App}
options={{
headerRight: () => (

Check warning on line 142 in example/src/App.tsx

View workflow job for this annotation

GitHub Actions / lint

Do not define components during render. React will see a new component type on every render and destroy the entire subtree’s DOM nodes and state (https://reactjs.org/docs/reconciliation.html#elements-of-different-types). Instead, move this component definition out of the parent component “Navigation” and pass data as props. If you want to allow component creation in props, set allowAsProps option to true
<Button
onPress={() =>
Alert.alert(
Expand Down
3 changes: 3 additions & 0 deletions example/src/Examples/FourTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface Props {
barTintColor?: ColorValue;
translucent?: boolean;
rippleColor?: ColorValue;
activeIndicatorColor?: ColorValue;
}

export default function FourTabs({
Expand All @@ -22,6 +23,7 @@ export default function FourTabs({
barTintColor,
translucent = true,
rippleColor,
activeIndicatorColor,
}: Props) {
const [index, setIndex] = useState(0);
const [routes] = useState([
Expand Down Expand Up @@ -69,6 +71,7 @@ export default function FourTabs({
barTintColor={barTintColor}
translucent={translucent}
rippleColor={rippleColor}
activeIndicatorColor={activeIndicatorColor}
/>
);
}
4 changes: 4 additions & 0 deletions src/TabView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ interface Props<Route extends BaseRoute> {
*/
translucent?: boolean;
rippleColor?: ColorValue;
/**
* Color of tab indicator. (Android only)
*/
activeIndicatorColor?: ColorValue;
}

const ANDROID_MAX_TABS = 6;
Expand Down
1 change: 1 addition & 0 deletions src/TabViewNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface TabViewProps extends ViewProps {
inactiveTintColor?: ColorValue;
ignoresTopSafeArea?: boolean;
disablePageAnimations?: boolean;
activeIndicatorColor?: ColorValue;
}

export default codegenNativeComponent<TabViewProps>('RNCTabView', {
Expand Down
Loading