forked from software-mansion/react-native-screens
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: maintain native behavior of iOS back button with custom style
Previously if a custom font or font size was set in the config, a new `RNSUIBarButtonItem` would be created and set as the back bar button item. However, this would break native behavior where the button title would shorten to "Back" if there's not enough space. In iOS 13 it's possible to keep this native behavior and also style the back button using `UINavigationBarAppearance`. The only caveat with this approach is that because `UINavigationBarAppearance` is not available prior to iOS 13, so on older systems we will go ahead and create a custom `RNSUIBarButtonItem`. This solves some issues mentioned in software-mansion#1589.
- Loading branch information
1 parent
49b24b4
commit 4143d99
Showing
3 changed files
with
126 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Sample React Native App | ||
* https://github.com/facebook/react-native | ||
* | ||
*/ | ||
|
||
import React from 'react'; | ||
import {Button, Text, View} from 'react-native'; | ||
import {NavigationContainer} from '@react-navigation/native'; | ||
import { | ||
createNativeStackNavigator, | ||
NativeStackScreenProps, | ||
} from 'react-native-screens/native-stack'; | ||
|
||
type Screens = { | ||
'Second Screen': undefined; | ||
'Screen With a Ridiculously Long Title and then some': undefined; | ||
}; | ||
|
||
const HomeScreen = ({navigation, route}: NativeStackScreenProps<Screens>) => { | ||
return ( | ||
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}> | ||
<Text>{route.name}</Text> | ||
<Button | ||
title="Navigate to second screen" | ||
onPress={() => { | ||
navigation.push('Second Screen'); | ||
}} | ||
/> | ||
</View> | ||
); | ||
}; | ||
|
||
const SecondScreen = ({route}: NativeStackScreenProps<Screens>) => { | ||
return ( | ||
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}> | ||
<Text>{route.name}</Text> | ||
</View> | ||
); | ||
}; | ||
|
||
const Stack = createNativeStackNavigator(); | ||
|
||
const App = () => { | ||
return ( | ||
<NavigationContainer> | ||
<Stack.Navigator> | ||
<Stack.Screen | ||
name="Screen With a Ridiculously Long Title and then some" | ||
component={HomeScreen} | ||
/> | ||
<Stack.Screen | ||
name="Second Screen" | ||
component={SecondScreen} | ||
options={{ | ||
headerBackTitleStyle: { | ||
fontFamily: 'AvenirNextCondensed-DemiBoldItalic', | ||
}, | ||
}} | ||
/> | ||
</Stack.Navigator> | ||
</NavigationContainer> | ||
); | ||
}; | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters