Skip to content

Commit 33c25ef

Browse files
committed
fix: handle RTL when example app running in Expo Go
1 parent 30f067e commit 33c25ef

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

example/app.json

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@
1313
"config": "./metro.config.js",
1414
"projectRoots": ""
1515
},
16-
"platforms": [
17-
"android",
18-
"ios",
19-
"web"
20-
],
16+
"platforms": ["android", "ios", "web"],
2117
"owner": "react-native-paper",
2218
"ios": {
2319
"bundleIdentifier": "com.callstack.reactnativepaperexample",
@@ -26,10 +22,7 @@
2622
"android": {
2723
"package": "com.callstack.reactnativepaperexample",
2824
"versionCode": 28,
29-
"permissions": [
30-
"READ_EXTERNAL_STORAGE",
31-
"WRITE_EXTERNAL_STORAGE"
32-
],
25+
"permissions": ["READ_EXTERNAL_STORAGE", "WRITE_EXTERNAL_STORAGE"],
3326
"icon": "./assets/images/paper-icon.png",
3427
"adaptiveIcon": {
3528
"foregroundImage": "./assets/images/android-icon.png",
@@ -52,8 +45,6 @@
5245
"updates": {
5346
"url": "https://u.expo.dev/ba8f5139-58fe-48f0-b2f2-2d675b6eb2d4"
5447
},
55-
"plugins": [
56-
"expo-font"
57-
]
48+
"plugins": ["expo-font"]
5849
}
5950
}

example/src/DrawerItems.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ import * as React from 'react';
22
import { I18nManager, StyleSheet, View, Platform } from 'react-native';
33

44
import { DrawerContentScrollView } from '@react-navigation/drawer';
5+
import Constants, { ExecutionEnvironment } from 'expo-constants';
56
import * as Updates from 'expo-updates';
67
import {
78
Badge,
9+
Button,
10+
Dialog,
811
Drawer,
912
MD2Colors,
1013
MD3Colors,
1114
Switch,
1215
Text,
1316
TouchableRipple,
17+
Portal,
1418
} from 'react-native-paper';
1519

1620
import { deviceColorsSupported, isWeb } from '../utils';
@@ -87,12 +91,15 @@ const DrawerCollapsedItemsData = [
8791

8892
function DrawerItems() {
8993
const [drawerItemIndex, setDrawerItemIndex] = React.useState<number>(0);
94+
const [showRTLDialog, setShowRTLDialog] = React.useState(false);
9095
const preferences = React.useContext(PreferencesContext);
9196

9297
const _setDrawerItem = (index: number) => setDrawerItemIndex(index);
9398

9499
const { isV3, colors } = useExampleTheme();
95100
const isIOS = Platform.OS === 'ios';
101+
const expoGoExecution =
102+
Constants.executionEnvironment === ExecutionEnvironment.StoreClient;
96103

97104
if (!preferences) throw new Error('PreferencesContext not provided');
98105

@@ -113,13 +120,22 @@ function DrawerItems() {
113120
} = preferences;
114121

115122
const _handleToggleRTL = () => {
123+
if (expoGoExecution) {
124+
setShowRTLDialog(true);
125+
return;
126+
}
127+
116128
toggleRTL();
117129
I18nManager.forceRTL(!isRTL);
118130
if (isWeb) {
119131
Updates.reloadAsync();
120132
}
121133
};
122134

135+
const _handleDismissRTLDialog = () => {
136+
setShowRTLDialog(false);
137+
};
138+
123139
const coloredLabelTheme = {
124140
colors: isV3
125141
? {
@@ -254,6 +270,24 @@ function DrawerItems() {
254270
</Text>
255271
</>
256272
)}
273+
<Portal>
274+
<Dialog visible={showRTLDialog} onDismiss={_handleDismissRTLDialog}>
275+
<Dialog.Title>Changing to RTL</Dialog.Title>
276+
<Dialog.Content>
277+
<Text variant="bodyMedium">
278+
Due to Expo Go limitations it is impossible to change RTL
279+
dynamically. To do so, you need to create a development build of
280+
Example app or change it statically by setting{' '}
281+
<Text variant="labelMedium">forcesRTL</Text> property to true in{' '}
282+
<Text variant="labelMedium">app.json</Text> within{' '}
283+
<Text variant="labelMedium">example</Text> directory.
284+
</Text>
285+
<Dialog.Actions>
286+
<Button onPress={_handleDismissRTLDialog}>Ok</Button>
287+
</Dialog.Actions>
288+
</Dialog.Content>
289+
</Dialog>
290+
</Portal>
257291
</DrawerContentScrollView>
258292
);
259293
}

0 commit comments

Comments
 (0)