Skip to content
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

fix: add internal isNewBackTitleImplementation const #1791

Merged
merged 3 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions TestsExample/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import Test1646 from './src/Test1646';
import Test1649 from './src/Test1649';
import Test1683 from './src/Test1683';
import Test1726 from './src/Test1726';
import Test1791 from './src/Test1791';

enableFreeze(true);

Expand Down
63 changes: 63 additions & 0 deletions TestsExample/src/Test1791.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import {NavigationContainer} from '@react-navigation/native';

import {createNativeStackNavigator} from '@react-navigation/native-stack';

import React from 'react';
import {Button, View} from 'react-native';

const Stack = createNativeStackNavigator();

const Screen1 = ({navigation}) => (
<View style={{flex: 1}}>
<Button onPress={() => navigation.navigate('Screen2')} title="Next" />
</View>
);

const Screen2 = ({navigation}) => (
<View style={{flex: 1}}>
<Button onPress={() => navigation.navigate('Screen3')} title="Next" />
</View>
);

const Screen3 = ({navigation}) => (
<View style={{flex: 1}}>
<Button onPress={() => navigation.navigate('Screen4')} title="Next" />
</View>
);

const Screen4 = () => <View style={{flex: 1}} />;

const App = () => {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen component={Screen1} name="Screen1" />
<Stack.Screen
component={Screen2}
name="Screen2"
options={{
headerBackTitleVisible: false,
headerBackTitle: 'Custom title in back button menu',
}}
/>
<Stack.Screen
component={Screen3}
name="Screen3"
options={{
headerBackTitle: 'Small title',
headerBackTitleStyle: {fontSize: 8},
}}
/>
<Stack.Screen
component={Screen4}
name="Screen4"
options={{
headerBackTitle: 'Custom title',
}}
/>
</Stack.Navigator>
</NavigationContainer>
);
};

export default App;
2 changes: 2 additions & 0 deletions src/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
} from './types';
import {
isSearchBarAvailableForCurrentPlatform,
isNewBackTitleImplementation,
executeNativeBackPress,
} from './utils';

Expand Down Expand Up @@ -466,7 +467,7 @@
console.warn(
'Importing SearchBar is only valid on iOS and Android devices.'
);
return View as any as ReactNode;

Check warning on line 470 in src/index.native.tsx

View workflow job for this annotation

GitHub Actions / install-and-lint

Unexpected any. Specify a different type
}

return (
Expand Down Expand Up @@ -592,5 +593,6 @@
useTransitionProgress,

isSearchBarAvailableForCurrentPlatform,
isNewBackTitleImplementation,
executeNativeBackPress,
};
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export * from './types';
export { default as useTransitionProgress } from './useTransitionProgress';
export {
isSearchBarAvailableForCurrentPlatform,
isNewBackTitleImplementation,
executeNativeBackPress,
} from './utils';

Expand Down
6 changes: 6 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ export function executeNativeBackPress() {
BackHandler.exitApp();
return true;
}

// Because of a bug introduced in https://github.com/software-mansion/react-native-screens/pull/1646
// react-native-screens v3.21 changed how header's backTitle handles whitespace strings in https://github.com/software-mansion/react-native-screens/pull/1726
// To allow for backwards compatibility in @react-navigation/native-stack we need a way to check if this version or newer is used.
// See https://github.com/react-navigation/react-navigation/pull/11423 for more context.
export const isNewBackTitleImplementation = true;