-
-
Notifications
You must be signed in to change notification settings - Fork 643
fix(Android): RTL layout for center-aligned custom header title #3896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import React from 'react'; | ||
| import { | ||
| View, | ||
| Text, | ||
| StyleSheet, | ||
| I18nManager, | ||
| Button, | ||
| DevSettings, | ||
| } from 'react-native'; | ||
| import { NavigationContainer } from '@react-navigation/native'; | ||
| import { createNativeStackNavigator } from '@react-navigation/native-stack'; | ||
|
|
||
| const Stack = createNativeStackNavigator(); | ||
|
|
||
| function toggleRTL(forceRTL: boolean) { | ||
| if (I18nManager.isRTL === forceRTL) return; | ||
| I18nManager.forceRTL(forceRTL); | ||
| I18nManager.allowRTL(forceRTL); | ||
| DevSettings.reload(); | ||
| } | ||
|
|
||
| function HeaderTitle() { | ||
| return ( | ||
| <Text style={{ fontSize: 18, fontWeight: 'bold' }}>Custom Title</Text> | ||
| ); | ||
| } | ||
|
|
||
| function HomeScreen() { | ||
| return ( | ||
| <View style={styles.container}> | ||
| <Text style={styles.heading}>Issue #3438</Text> | ||
| <Text>headerTitleAlign: center + headerTitle as function</Text> | ||
| <Text>RTL mode: {I18nManager.isRTL ? 'YES' : 'NO'}</Text> | ||
| <Text style={styles.note}> | ||
| The header title above should say "Custom Title". | ||
| {'\n'}If it's missing or there's extra space, the bug is present. | ||
| </Text> | ||
| <View style={styles.buttons}> | ||
| <Button title="Force RTL" onPress={() => toggleRTL(true)} /> | ||
| <Button title="Force LTR" onPress={() => toggleRTL(false)} /> | ||
| </View> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| function App() { | ||
| return ( | ||
| <NavigationContainer> | ||
| <Stack.Navigator> | ||
| <Stack.Screen | ||
| name="Home" | ||
| component={HomeScreen} | ||
| options={{ | ||
| headerTitleAlign: 'center', | ||
| headerTitle: HeaderTitle, | ||
| }} | ||
| /> | ||
| </Stack.Navigator> | ||
|
Comment on lines
+46
to
+58
|
||
| </NavigationContainer> | ||
| ); | ||
| } | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| container: { | ||
| flex: 1, | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| padding: 20, | ||
| gap: 8, | ||
| }, | ||
| heading: { | ||
| fontWeight: 'bold', | ||
| fontSize: 16, | ||
| }, | ||
| note: { | ||
| textAlign: 'center', | ||
| marginTop: 20, | ||
| color: 'gray', | ||
| }, | ||
| buttons: { | ||
| flexDirection: 'row', | ||
| gap: 12, | ||
| marginTop: 20, | ||
| }, | ||
| }); | ||
|
|
||
| export default App; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LAYOUT_DIRECTION_RTL/LAYOUT_DIRECTION_LTRare used unqualified in this file, but there is no import for these constants. This won’t compile unless they’re referenced viaView.LAYOUT_DIRECTION_*or imported explicitly.