Skip to content
Open
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
5 changes: 5 additions & 0 deletions apps/example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { SafeAreaProvider } from 'react-native-safe-area-context';
import JSBottomTabs from './Examples/JSBottomTabs';
import ThreeTabs from './Examples/ThreeTabs';
import FourTabs from './Examples/FourTabs';
import FourTabsRTL from './Examples/FourTabsRTL';
import MaterialBottomTabs from './Examples/MaterialBottomTabs';
import SFSymbols from './Examples/SFSymbols';
import LabeledTabs from './Examples/Labeled';
Expand Down Expand Up @@ -72,6 +73,9 @@ const FourTabsActiveIndicatorColor = () => {
const UnlabeledTabs = () => {
return <LabeledTabs showLabels={false} />;
};
const FourTabsRightToLeft = () => {
return <FourTabsRTL layoutDirection={'rtl'} />;
};

const examples = [
{
Expand Down Expand Up @@ -161,6 +165,7 @@ const examples = [
name: 'Bottom Accessory View',
screenOptions: { headerShown: false },
},
{ component: FourTabsRightToLeft, name: 'Four Tabs - RTL' },
];

function App() {
Expand Down
95 changes: 95 additions & 0 deletions apps/example/src/Examples/FourTabsRTL.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import TabView, { SceneMap } from 'react-native-bottom-tabs';
import React from 'react';
import { Article } from '../Screens/Article';
import { Albums } from '../Screens/Albums';
import { Contacts } from '../Screens/Contacts';
import { Chat } from '../Screens/Chat';
import { I18nManager, type ColorValue } from 'react-native';
import type { LayoutDirection } from 'react-native-bottom-tabs/src/types';

interface Props {
disablePageAnimations?: boolean;
scrollEdgeAppearance?: 'default' | 'opaque' | 'transparent';
backgroundColor?: ColorValue;
translucent?: boolean;
hideOneTab?: boolean;
rippleColor?: ColorValue;
activeIndicatorColor?: ColorValue;
layoutDirection?: LayoutDirection;
}

const renderScene = SceneMap({
article: Article,
albums: Albums,
contacts: Contacts,
chat: Chat,
});

export default function FourTabsRTL({
disablePageAnimations = false,
scrollEdgeAppearance = 'default',
backgroundColor,
translucent = true,
hideOneTab = false,
rippleColor,
activeIndicatorColor,
layoutDirection = 'locale',
}: Props) {
React.useLayoutEffect(() => {
if (layoutDirection === 'rtl') {
I18nManager.allowRTL(true);
I18nManager.forceRTL(true);
}
return () => {
if (layoutDirection === 'rtl') {
I18nManager.allowRTL(false);
I18nManager.forceRTL(false);
}
};
}, [layoutDirection]);
const [index, setIndex] = React.useState(0);
const [routes] = React.useState([
{
key: 'article',
title: 'المقالات',
focusedIcon: require('../../assets/icons/article_dark.png'),
unfocusedIcon: require('../../assets/icons/chat_dark.png'),
badge: '!',
},
{
key: 'albums',
title: 'البومات',
focusedIcon: require('../../assets/icons/grid_dark.png'),
badge: '5',
hidden: hideOneTab,
},
{
key: 'contacts',
focusedIcon: require('../../assets/icons/person_dark.png'),
title: 'المتراسلين',
badge: ' ',
},
{
key: 'chat',
focusedIcon: require('../../assets/icons/chat_dark.png'),
title: 'المحادثات',
role: 'search',
},
]);

return (
<TabView
sidebarAdaptable
disablePageAnimations={disablePageAnimations}
scrollEdgeAppearance={scrollEdgeAppearance}
navigationState={{ index, routes }}
onIndexChange={setIndex}
renderScene={renderScene}
tabBarStyle={{ backgroundColor }}
translucent={translucent}
rippleColor={rippleColor}
activeIndicatorColor={activeIndicatorColor}
layoutDirection={layoutDirection}
/>
);
}
1 change: 1 addition & 0 deletions apps/example/src/Examples/NativeBottomTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function NativeBottomTabs() {
initialRouteName="Chat"
labeled={true}
hapticFeedbackEnabled={false}
layoutDirection="leftToRight"
tabBarInactiveTintColor="#C57B57"
tabBarActiveTintColor="#F7DBA7"
tabBarStyle={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
layout(left, top, right, bottom)
}

fun applyDirection(dir: Int) {
bottomNavigation.layoutDirection = dir
}

override fun requestLayout() {
super.requestLayout()
@Suppress("SENSELESS_COMPARISON") // layoutCallback can be null here since this method can be called in init
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ class RCTTabViewManager(context: ReactApplicationContext) :
view.isHapticFeedbackEnabled = value
}

override fun setLayoutDirection(view: ReactBottomNavigationView, value: String?) {
val direction = when (value) {
"rtl" -> View.LAYOUT_DIRECTION_RTL
"ltr" -> View.LAYOUT_DIRECTION_LTR
else -> View.LAYOUT_DIRECTION_LOCALE
}
view.applyDirection(direction)
}

override fun setFontFamily(view: ReactBottomNavigationView?, value: String?) {
view?.setFontFamily(value)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
_tabViewProvider.hapticFeedbackEnabled = newViewProps.hapticFeedbackEnabled;
}

if (oldViewProps.layoutDirection != newViewProps.layoutDirection) {
_tabViewProvider.layoutDirection = RCTNSStringFromStringNilIfEmpty(newViewProps.layoutDirection);
}

if (oldViewProps.fontSize != newViewProps.fontSize) {
_tabViewProvider.fontSize = [NSNumber numberWithInt:newViewProps.fontSize];
}
Expand Down
11 changes: 11 additions & 0 deletions packages/react-native-bottom-tabs/ios/TabView/NewTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@

@ViewBuilder
var body: some View {
var effectiveLayoutDirection: LayoutDirection {
let dir = props.layoutDirection ?? "locale"
if let mapped = ["rtl": LayoutDirection.rightToLeft,

Check warning on line 16 in packages/react-native-bottom-tabs/ios/TabView/NewTabView.swift

View workflow job for this annotation

GitHub Actions / swift-lint

Multiline Literal Brackets Violation: Multiline literals should have their surrounding brackets in a new line (multiline_literal_brackets)
"ltr": LayoutDirection.leftToRight][dir] {

Check warning on line 17 in packages/react-native-bottom-tabs/ios/TabView/NewTabView.swift

View workflow job for this annotation

GitHub Actions / swift-lint

Multiline Literal Brackets Violation: Multiline literals should have their surrounding brackets in a new line (multiline_literal_brackets)
return mapped
}
let system = UIView.userInterfaceLayoutDirection(for: .unspecified)
return system == .rightToLeft ? .rightToLeft : .leftToRight
}

TabView(selection: $props.selectedPage) {
ForEach(props.children) { child in
if let index = props.children.firstIndex(of: child),
Expand Down Expand Up @@ -49,6 +59,7 @@
}
}
}
.environment(\.layoutDirection, effectiveLayoutDirection)
.measureView { size in
onLayout(size)
}
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-bottom-tabs/ios/TabViewProps.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class TabViewProps: ObservableObject {
@Published var translucent: Bool = true
@Published var disablePageAnimations: Bool = false
@Published var hapticFeedbackEnabled: Bool = false
@Published var layoutDirection: String?
@Published var fontSize: Int?
@Published var fontFamily: String?
@Published var fontWeight: String?
Expand Down
5 changes: 5 additions & 0 deletions packages/react-native-bottom-tabs/ios/TabViewProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
}

@objc public protocol TabViewProviderDelegate {
func onPageSelected(key: String, reactTag: NSNumber?)

Check warning on line 42 in packages/react-native-bottom-tabs/ios/TabViewProvider.swift

View workflow job for this annotation

GitHub Actions / swift-lint

Legacy Objective-C Reference Type Violation: Prefer Swift value types to bridged Objective-C reference types (legacy_objc_type)
func onLongPress(key: String, reactTag: NSNumber?)
func onTabBarMeasured(height: Int, reactTag: NSNumber?)
func onLayout(size: CGSize, reactTag: NSNumber?)
Expand Down Expand Up @@ -95,6 +95,11 @@
}
}

@objc public var layoutDirection: NSString? {
didSet {
props.layoutDirection = layoutDirection as? String
}
}
@objc public var scrollEdgeAppearance: NSString? {
didSet {
props.scrollEdgeAppearance = scrollEdgeAppearance as? String
Expand Down
15 changes: 14 additions & 1 deletion packages/react-native-bottom-tabs/src/TabView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@
import type { ImageSource } from 'react-native/Libraries/Image/ImageSource';
import NativeTabView from './TabViewNativeComponent';
import useLatestCallback from 'use-latest-callback';
import type { AppleIcon, BaseRoute, NavigationState, TabRole } from './types';
import type {
AppleIcon,
BaseRoute,
LayoutDirection,
NavigationState,
TabRole,
} from './types';
import DelayedFreeze from './DelayedFreeze';
import {
BottomAccessoryView,
Expand Down Expand Up @@ -201,6 +207,11 @@
* @platform ios
*/
renderBottomAccessoryView?: BottomAccessoryViewProps['renderBottomAccessoryView'];
/**
* The direction of the layout.
* @default 'locale'
*/
layoutDirection?: LayoutDirection;
}

const ANDROID_MAX_TABS = 100;
Expand Down Expand Up @@ -239,6 +250,7 @@
tabBarStyle,
tabLabelStyle,
renderBottomAccessoryView,
layoutDirection = 'locale',
...props
}: Props<Route>) => {
// @ts-ignore
Expand Down Expand Up @@ -269,7 +281,7 @@

if (!loaded.includes(focusedKey)) {
// Set the current tab to be loaded if it was not loaded before
setLoaded((loaded) => [...loaded, focusedKey]);

Check warning on line 284 in packages/react-native-bottom-tabs/src/TabView.tsx

View workflow job for this annotation

GitHub Actions / lint

'loaded' is already declared in the upper scope on line 280 column 10
}

const icons = React.useMemo(
Expand Down Expand Up @@ -398,6 +410,7 @@
onTabBarMeasured={handleTabBarMeasured}
onNativeLayout={handleNativeLayout}
hapticFeedbackEnabled={hapticFeedbackEnabled}
layoutDirection={layoutDirection}
activeTintColor={activeTintColor}
inactiveTintColor={inactiveTintColor}
barTintColor={tabBarStyle?.backgroundColor}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';

Check warning on line 1 in packages/react-native-bottom-tabs/src/TabViewNativeComponent.ts

View workflow job for this annotation

GitHub Actions / lint

'react-native/Libraries/Utilities/codegenNativeComponent' React Native deep imports are deprecated. Please use the top level import instead
import type { ColorValue, ProcessedColorValue, ViewProps } from 'react-native';
import type {
DirectEventHandler,
Expand All @@ -7,7 +7,7 @@
WithDefault,
} from 'react-native/Libraries/Types/CodegenTypes';
//@ts-ignore
import type { ImageSource } from 'react-native/Libraries/Image/ImageSource';

Check warning on line 10 in packages/react-native-bottom-tabs/src/TabViewNativeComponent.ts

View workflow job for this annotation

GitHub Actions / lint

'react-native/Libraries/Image/ImageSource' React Native deep imports are deprecated. Please use the top level import instead

export type OnPageSelectedEventData = Readonly<{
key: string;
Expand Down Expand Up @@ -56,6 +56,7 @@
disablePageAnimations?: boolean;
activeIndicatorColor?: ColorValue;
hapticFeedbackEnabled?: boolean;
layoutDirection?: string;
minimizeBehavior?: string;
fontFamily?: string;
fontWeight?: string;
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native-bottom-tabs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export type AppleIcon = { sfSymbol: SFSymbol };

export type TabRole = 'search';

export type LayoutDirection = 'ltr' | 'rtl' | 'locale';

export type BaseRoute = {
key: string;
title?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function NativeBottomTabNavigator({
screenOptions,
tabBarActiveTintColor: customActiveTintColor,
tabBarInactiveTintColor: customInactiveTintColor,
layoutDirection = 'locale',
...rest
}: NativeBottomTabNavigatorProps) {
const { colors } = useTheme();
Expand Down Expand Up @@ -77,6 +78,7 @@ function NativeBottomTabNavigator({
<NavigationContent>
<NativeBottomTabView
{...rest}
layoutDirection={layoutDirection}
tabBarActiveTintColor={activeTintColor}
tabBarInactiveTintColor={inactiveTintColor}
state={state}
Expand Down
2 changes: 2 additions & 0 deletions packages/react-navigation/src/views/NativeBottomTabView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Props = NativeBottomTabNavigationConfig & {

export default function NativeBottomTabView({
state,
layoutDirection,
navigation,
descriptors,
tabBar,
Expand Down Expand Up @@ -114,6 +115,7 @@ export default function NativeBottomTabView({
});
}
}}
layoutDirection={layoutDirection}
/>
);
}
Loading