I want to have a component like button (or react-native-action-button precisely) to be shown in each screen using React Navigation.
Does React Navigation has any option in inside Routes to implement it once and use everywhere?
Note: I don't want to import Component in each .js class and use it in render.
Reference -> Like this in app's each screen. Floating Action Button Reference
Going backThe header provided by the native stack navigator will automatically include a back button when it is possible to go back from the active screen (if there is only one screen in the navigation stack, there is nothing that you can go back to, and so there is no back button).
Stack Navigator provides a way for your app to transition between screens where each new screen is placed on top of a stack. By default the stack navigator is configured to have the familiar iOS and Android look & feel: new screens slide in from the right on iOS, use OS default animation on Android.
In your Navigation Container add it like this`
<NavigationContainer>
<Stack.Navigator initialRouteName="SplashScreen">
...
</Stack.Navigator>
<Button /> // add your component here. It will be visible in all screens
</NavigationContainer>
Make a default screen with that button. Everytime when you want to use that button wrap your all items with that component instead of view. For example 'DefaultScreen' is your view with the default component. Use it like that:
render(){
<DefaulScreen>
{AllOtherItems}
</DefaulScreen>
}
And in that DefaultScreen render all children like this:
class DefaultScreen extends Component {
render(){
<View>
{this.props.children}
{defaultComponentThatYouWantToPutWithCustomStyle}
</View>
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With