Skip to content

Commit 8867d42

Browse files
author
Ahmed Awaad
committed
refactor: update layoutDirection prop to use 'locale' for consistency across components
1 parent b478d2a commit 8867d42

File tree

6 files changed

+27
-15
lines changed

6 files changed

+27
-15
lines changed

apps/example/src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const UnlabeledTabs = () => {
7474
return <LabeledTabs showLabels={false} />;
7575
};
7676
const FourTabsRightToLeft = () => {
77-
return <FourTabsRTL layoutDirection={'rightToLeft'} />;
77+
return <FourTabsRTL layoutDirection={'locale'} />;
7878
};
7979

8080
const examples = [
@@ -165,7 +165,7 @@ const examples = [
165165
name: 'Bottom Accessory View',
166166
screenOptions: { headerShown: false },
167167
},
168-
{ component: FourTabsRightToLeft, name: 'Four Tabs - RTL', platform: 'ios' },
168+
{ component: FourTabsRightToLeft, name: 'Four Tabs - RTL' },
169169
];
170170

171171
function App() {

apps/example/src/Examples/FourTabsRTL.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import TabView, { SceneMap } from 'react-native-bottom-tabs';
2-
import React, { useState } from 'react';
2+
import React from 'react';
33
import { Article } from '../Screens/Article';
44
import { Albums } from '../Screens/Albums';
55
import { Contacts } from '../Screens/Contacts';
66
import { Chat } from '../Screens/Chat';
77
import { I18nManager, type ColorValue } from 'react-native';
8+
import type { LayoutDirection } from 'react-native-bottom-tabs/src/types';
89

910
interface Props {
1011
disablePageAnimations?: boolean;
@@ -14,7 +15,7 @@ interface Props {
1415
hideOneTab?: boolean;
1516
rippleColor?: ColorValue;
1617
activeIndicatorColor?: ColorValue;
17-
layoutDirection?: 'leftToRight' | 'rightToLeft';
18+
layoutDirection?: LayoutDirection;
1819
}
1920

2021
const renderScene = SceneMap({
@@ -32,22 +33,22 @@ export default function FourTabsRTL({
3233
hideOneTab = false,
3334
rippleColor,
3435
activeIndicatorColor,
35-
layoutDirection = 'leftToRight',
36+
layoutDirection = 'locale',
3637
}: Props) {
3738
React.useLayoutEffect(() => {
38-
if (layoutDirection === 'rightToLeft') {
39+
if (layoutDirection === 'rtl') {
3940
I18nManager.allowRTL(true);
4041
I18nManager.forceRTL(true);
4142
}
4243
return () => {
43-
if (layoutDirection === 'rightToLeft') {
44+
if (layoutDirection === 'rtl') {
4445
I18nManager.allowRTL(false);
4546
I18nManager.forceRTL(false);
4647
}
4748
};
4849
}, [layoutDirection]);
49-
const [index, setIndex] = useState(0);
50-
const [routes] = useState([
50+
const [index, setIndex] = React.useState(0);
51+
const [routes] = React.useState([
5152
{
5253
key: 'article',
5354
title: 'المقالات',

packages/react-native-bottom-tabs/src/TabView.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ import { BottomTabBarHeightContext } from './utils/BottomTabBarHeightContext';
2222
import type { ImageSource } from 'react-native/Libraries/Image/ImageSource';
2323
import NativeTabView from './TabViewNativeComponent';
2424
import useLatestCallback from 'use-latest-callback';
25-
import type { AppleIcon, BaseRoute, NavigationState, TabRole } from './types';
25+
import type {
26+
AppleIcon,
27+
BaseRoute,
28+
LayoutDirection,
29+
NavigationState,
30+
TabRole,
31+
} from './types';
2632
import DelayedFreeze from './DelayedFreeze';
2733
import {
2834
BottomAccessoryView,
@@ -202,11 +208,10 @@ interface Props<Route extends BaseRoute> {
202208
*/
203209
renderBottomAccessoryView?: BottomAccessoryViewProps['renderBottomAccessoryView'];
204210
/**
205-
* The direction of the layout. (iOS only)
206-
* @platform ios
207-
* @default 'leftToRight'
211+
* The direction of the layout.
212+
* @default 'locale'
208213
*/
209-
layoutDirection?: 'leftToRight' | 'rightToLeft';
214+
layoutDirection?: LayoutDirection;
210215
}
211216

212217
const ANDROID_MAX_TABS = 100;
@@ -245,7 +250,7 @@ const TabView = <Route extends BaseRoute>({
245250
tabBarStyle,
246251
tabLabelStyle,
247252
renderBottomAccessoryView,
248-
layoutDirection = 'leftToRight',
253+
layoutDirection = 'locale',
249254
...props
250255
}: Props<Route>) => {
251256
// @ts-ignore

packages/react-native-bottom-tabs/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export type AppleIcon = { sfSymbol: SFSymbol };
77

88
export type TabRole = 'search';
99

10+
export type LayoutDirection = 'ltr' | 'rtl' | 'locale';
11+
1012
export type BaseRoute = {
1113
key: string;
1214
title?: string;

packages/react-navigation/src/navigators/createNativeBottomTabNavigator.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function NativeBottomTabNavigator({
4343
screenOptions,
4444
tabBarActiveTintColor: customActiveTintColor,
4545
tabBarInactiveTintColor: customInactiveTintColor,
46+
layoutDirection = 'locale',
4647
...rest
4748
}: NativeBottomTabNavigatorProps) {
4849
const { colors } = useTheme();
@@ -77,6 +78,7 @@ function NativeBottomTabNavigator({
7778
<NavigationContent>
7879
<NativeBottomTabView
7980
{...rest}
81+
layoutDirection={layoutDirection}
8082
tabBarActiveTintColor={activeTintColor}
8183
tabBarInactiveTintColor={inactiveTintColor}
8284
state={state}

packages/react-navigation/src/views/NativeBottomTabView.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Props = NativeBottomTabNavigationConfig & {
1919

2020
export default function NativeBottomTabView({
2121
state,
22+
layoutDirection,
2223
navigation,
2324
descriptors,
2425
tabBar,
@@ -114,6 +115,7 @@ export default function NativeBottomTabView({
114115
});
115116
}
116117
}}
118+
layoutDirection={layoutDirection}
117119
/>
118120
);
119121
}

0 commit comments

Comments
 (0)