From 4143d994f2dcf72034f0bea7ba9f3ff29faeee50 Mon Sep 17 00:00:00 2001 From: Jasper Reddin Date: Fri, 16 Sep 2022 10:19:54 -0500 Subject: [PATCH] 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 #1589. --- TestsExample/App.js | 3 +- TestsExample/src/Test1540.tsx | 66 ++++++++++++++++++++++++ ios/RNSScreenStackHeaderConfig.mm | 84 +++++++++++++++++++++---------- 3 files changed, 126 insertions(+), 27 deletions(-) create mode 100644 TestsExample/src/Test1540.tsx diff --git a/TestsExample/App.js b/TestsExample/App.js index 1964c2d7a1..e9fa7b88d6 100644 --- a/TestsExample/App.js +++ b/TestsExample/App.js @@ -82,9 +82,10 @@ import Test1473 from './src/Test1473'; import Test1476 from './src/Test1476'; import Test1509 from './src/Test1509'; import Test1539 from './src/Test1539'; +import Test1540 from './src/Test1540'; enableFreeze(true); export default function App() { - return ; + return ; } diff --git a/TestsExample/src/Test1540.tsx b/TestsExample/src/Test1540.tsx new file mode 100644 index 0000000000..7ce44cb80e --- /dev/null +++ b/TestsExample/src/Test1540.tsx @@ -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) => { + return ( + + {route.name} +