Add strong typing for react navigation props

Just add NavigationType to your Props, like this: import { StackNavigator, NavigationScreenProp } from ‘react-navigation’; export interface HomeScreenProps { navigation: NavigationScreenProp<any,any> }; export class HomeScreen extends React.Component<HomeScreenProps, object> { render() { return ( <View style={styles.container}> <Button title=”Go to Details” onPress={() => this.props.navigation.navigate(‘Details’)} /> </View> ); } }

How do I hide the shadow under react-navigation headers?

Add the following to the navigationOptions header style. const AppNavigation = StackNavigator( { ‘The First Screen!’: { screen: FirstScreen }, }, { navigationOptions: { header: { style: { elevation: 0, // remove shadow on Android shadowOpacity: 0, // remove shadow on iOS }, }, }, }, ); The documentation isn’t great yet, but you can … Read more

What is the difference between @react-navigation/stack vs @react-navigation/native-stack?

Native Stack uses the Android and IOS native navigation systems to navigate between pages. Native Stack Navigator https://reactnavigation.org/docs/native-stack-navigator/ Stack Navigator https://reactnavigation.org/docs/stack-navigator/ The other one does not really “navigate”, but instead will mimic navigation in JavaScript and generic Views (a bit like how “Single-Page Application” web apps mimic web navigation). They say they try to make … Read more

How to mock React Navigation’s navigation prop for unit tests with TypeScript in React Native?

Issue The mock does not match the expected type so TypeScript reports an error. Solution You can use the type any “to opt-out of type-checking and let the values pass through compile-time checks”. Details As you mentioned, in JavaScript it works to mock only what is needed for the test. In TypeScript the same mock … Read more

How to disable react navigation’s stack navigator transition?

React Navigation 5 {/* Screen level */} <NavigationContainer> <Stack.Navigator> <Stack.Screen name=”HomeScreen” component={HomeScreen} options={{ animationEnabled: false, }} /> </Stack.Navigator> </NavigationContainer> {/* Whole navigation stack */} <Stack.Navigator screenOptions={{ animationEnabled: false }}></Stack.Navigator> React Navigation 6 <Stack.Navigator screenOptions={{ animation: ‘none’ }}></Stack.Navigator> More options here https://reactnavigation.org/docs/stack-navigator/

React Navigation: Swipe on drawer does not work in Android

I have found the solution. React Navigation depends on the react-native-gesture-handler library. In the Installation section of React Navigation docs, it only says to create link by using the command react-native link. This is enough for iOS. But for Android, you have to edit the MainActivity.java file, so that the gesture handler library can work … Read more

How to get a height of a Keyboard in React-Native?

This is what I did: If the app has “Authorization / Log-in / Sign-up screen” then: In componentWillMount add KeyboardListeners as explained here: this.keyboardDidShowListener = Keyboard.addListener(‘keyboardDidShow’, this._keyboardDidShow); this.keyboardDidHideListener = Keyboard.addListener(‘keyboardDidHide’, this._keyboardDidHide); Add autoFocus to e-mail / phone number / any other “first” TextInput on the page, so that when the screen loads, the Keyboard pops-up. … Read more

How to Pass Parameters to screen in StackNavigator?

You can pass params with the navigate function’s second argument: onPress(user) { this.props.navigation.navigate( ‘DetailPage’, { user }, ); } React Navigation 5.x, 6.x (2022) Access them in this.props.route.params. For example in your DetailsPage: <Text style={styles.myStyle}>{this.props.route.params.user.name}</Text> https://reactnavigation.org/docs/params/ React Navigation <= 4.x Access them in this.props.navigation.state.params. For example in your DetailsPage: <Text style={styles.myStyle}>{this.props.navigation.state.params.user.name}</Text> https://reactnavigation.org/docs/4.x/params/

File not found.