Using ex-navigation with exponent.js how do you route to a new stack? - react-native

I wish to trigger navigation to a details screen from a redux action - how do i do that with exponent ex-navigation? Should I use navigation.performAction ? Where's the documentation for that method? This would be a route with a fresh stack since they would be coming from a create screen and they shouldn't press back to the create form. This would also be a route that exists outside the tab navigation.

Related

react-navigation V6: what's the difference between replace and navigate

From the react-navigation/native V6 documentation
navigation.replace replaces the current route with a new one
whereas navigation.navigate goes to another screen and figures out the action it needs to take to do it
Can you please explain me what's the difference between the two?
Navigate
navigate - go to another screen, figures out the action it needs to
take to do it
Navigate will go to the screen, but the action it takes to go there will depend on the type of navigator.
For bottom Tab it will simply replace the route with the new one to
navigate and pressing back in android at least will by default
navigate to first screen in navigator.
For Stack, navigate will push the new route into the current stack. The previous components in the route will still be mounted. Only popping them will unmount them. In a stack, going back will simply pop.
Replace
replace - replace the current route with a new one
Replace will simply replace the current route with a new one. What this means in a stack navigator is, that the current component will be unmounted and the component from new route will be mounted. Which is a different behaviour from what navigate would've done (push)
TLDR: Navigate takes best course of action, Replace only works in some navigators, with specifically unmounting current and mounting new.

How to transfer data between screens in Drawer navigation in React-Native

I want to take state value of one screen to another screen. How to do it? Both screens are under drawer navigation.
To pass the value between different activities
Approach 1:
Pass params to a route by putting them in an object as a second parameter to the navigation.navigate function from First Screen. Using :
this.props.navigation.navigate('RouteName', { /* params go here */ })
Read the params in your Second screen. Using:
this.props.navigation.getParam(paramName, defaultValue)
Approach 2:
By using redux. With it, you create a shared store of variables, so you can access them anywhere in the application. The following link demonstrates how to configure redux in your project. https://blog.cloudboost.io/getting-started-with-react-native-and-redux-6cd4addeb29

How to insert new scene on pop stack in react native?

I am working on existing react native project and I want to find solution for pop action on navigation stack where I want to introduce new scene which is actually not on stack.
I have three different type of route based on state of user logged In, logged out or in locked state. So while user's app state is locked at that time on launch I am directing user to reset account page from launch scene.
Launch Scene -> Reset Account
But on back event of Reset Account, I want to show login page instead of Launch scene, but Login scene is not in stack as of now.
So how to insert new scene when user performs pop action ?
I am new to react native and I don't know how to modify navigation stack programmatically without performing any animation ?
In my project there is one package named react-native-router-flux to handle react navigation.
Any insight will be helpful.
I suggest you create a SwitchNavigator between LaunchScreen and AccountStack
AccountStack is a StackNavigator that render both:
LoginScreen.
ResetAccountScreen. << This would be your initialRoute.

React Navigation infinite stack / dynamic stack

I would like to realise an infinite stack with react navigation, that means I would need a dynamic stacknavigator where I can push in a unlimited number of screens (a maximum of 20 screens would be enough). You can imagine this like in the amazon app where you can click on a related product in the product details and it shows you another product details screen where you can do the same thing.
Does anyone of you has an idea how to do that ?
This can be done with react-navigation
Instead of using this.props.navigation.navigate('ScreenName') you can use this.props.navigation.push('ScreenName')
You would probably want to pass some sort of description to the screen so that it knows what to render you can do that by passing params
this.props.navigation.push('ScreenName', { key: productId })
You would just have to set up a few template screens that could then be populated by the parameters that you pass to them.
You can see more about the different functions that react-navigation has here
https://reactnavigation.org/docs/en/navigation-prop.html#navigator-dependent-functions
Here is a snack showing it working https://snack.expo.io/#andypandy/infinite-navigation
In the snack I pass a position and date, you can see these update as each screen is pushed onto the stack. Pressing Go Back goes back one place on the stack.

Tab navigator issue when calling an API

i am stuck in a problem that is,
in my application one screen has a Tabbar component so i have used Tabnavigation from react-navigation.
so there is two tabs in that screen and both of that tabs have GET API for displaying data
so my main problem is when tab screen is open at that time both tabs file is calling API because of tabnavigator is in stack navigator.
So please help me to solve this issue.
i have to do like this::-
when i click on tab then after API will be call but here when the screen is arrive at that time both tabs call their API.
so please sort out this issue guys.
You can use TabNavigator's lazy prop.
lazy - Whether to lazily render tabs as needed as opposed to rendering them upfront.
This way your API call will happen only when you switch to that tab. The call will happen only on first switch though. You may need to add some logic to recall API on certain event or time to get the new data.