Moving to a different screen with navigation jumpTo - react-native

I am using react navigation v6. I use navigation.navigate() to move to another screen and navigation.jumpTo() for my custom tabs. The issue I am facing is, after I navigate to a different screen and go back to the previous screen with a new params passed, the navigation is unable to read the jumpTo() anymore as it becomes undefined.
Example:
The screen navigation below is working fine without any params get passed
Screen A > Screen B > Screen A > Screen Tab 1
This 2nd example is when there is a params get passed back to Screen A and jumpTo() Screen Tab 1 will throw error undefined
Screen A > Screen B > Screen A (username: john) > Screen Tab 1
Based on the React Navigation Navigate documentation, it will push a new screen if it has a different params, in my case is Screen A (username: john). So I guess that is what causing the error to appear.
Is there a way to keep the jumpTo() function or any similar method I can use? I don't want to use redux if possible.

Related

Tab Navigator's `goBack` not working properly on React Native Navigation

I created a tab navigator for an app using #react-navigation/native: ^6.0.16. But when I tried to go back it always goes back to the first screen on the tab navigator.
For example if I navigate from Home >> Notifications >> Profile and press the android back button instead of Notifications I reach Home. Basically going back on any tab (other than Home) navigates me back to home.
This issue does not seem to be a problem for #react-navigation/native: v5.x but I rather not go back to using version 5.x.
Is there any way I can fix this issue on version 6.x?
You can checkout a small snack of the issue here.
Just goto package.json and replace "#react-navigation/native": "^6.0.16", with "#react-navigation/native": "^5.9.8", to get the intended output.
As per docs here, you can specify the behaviour you want:
This controls what happens when goBack is called in the navigator.
This includes pressing the device's back button or back gesture on
Android.
It supports the following values:
firstRoute - return to the first screen defined in the navigator
(default) initialRoute - return to initial screen passed in
initialRouteName prop, if not passed, defaults to the first screen
order - return to screen defined before the focused screen history -
return to last visited screen in the navigator; if the same screen is
visited multiple times, the older entries are dropped from the history
none - do not handle back button

How to open a screen from another screen which was already opened from a another screen?

So I have a React Native app with a bottom tab navigation, in one of those tab screens I have an icons in the right header which leads me to a settings screen and for this I use stackNavigation but I also want to open another screen from this Settings screen - Account screen. How do I achieve this? Do I just use stack navigation again?

React Native & React Navigation 5.x: hiding bottom tab bar in specific screens

I'm currently building an app that has a bottom tab bar with a navigation stack in each tab. Now I want to create an image screen where the tab bar is hidden. I've followed the docs at https://reactnavigation.org/docs/hiding-tabbar-in-screens, which works fine if you only want the user to able to navigate to the screen and then navigate back to the tab stack.
The problem is that I want it to feel like the image screen is part of the tab stack so the user can navigate from the image screen to another screen (i.e. push another screen on top of the stack). This doesn't work for me using the method mentioned above...
I've also tried using the option tabBarVisible: false, but it makes the "hide animation" glitchy (which the docs also warns for: https://reactnavigation.org/docs/bottom-tab-navigator).

Navigation using react native

I'm new in react native and I'm looking for an example of react navigation. I'm looking to create a home page similar to the picture below.
Use React Navigation
Stack Navigator - It let's you switch between screens. It creates a stack. It let's to navigate from one screen to another. When you press back button it navigates you back to the first screen. It
Tab navigator- It will create tabs as your picture.
In your case I think you will need a tab navigator which will be inside stack navigator.

React native navigation after state change in redux

I am using react-redux and react-native's navigation in my app. My goal is of navigate after successful API call from Screen A -> Screen B -> Screen C and so on.
This is what I'm doing in the app.
On Screen A, button is pressed, and an redux action is generated.
Action is internally calling an API and getting result and dispatching event to reducer state.
After reducer's state gets updated (Success cases), I wanted to navigate to Screen B.
Again same 1-3 steps for Screen B to Screen C.
I did tried following approaches:
Adding navigation code in componentWillReceiveProps:
Problem with this approach is, its calling all the componentWillReceiveProps of navigation stack. This is rendering current screen multiple times before navigating to next screen (I observed this behaviour from Screen B -> Screen C)
Adding navigation code render method itself and returning null.
Again problem here is, what if I have multiple reducer mapped in one screen. Again I will be navigating more than once if both reducer changes.
I thought of using EventListener's, but than I have to keep track of adding and removing them.
Any ideas on how can I achieve this.
Thanks