popTo method
Issue Description
I am going to use popTo method. But I can not get target component's id. I want to ComponentId in now stack. But I don't know how to get component list and ids. And I want to know how to get componentId from component's name.
Environment
- React Native Navigation version: 2.2.5
- React Native version: 0.57.8
- Platform(s) (iOS, Android, or both?): both
- Device info (Simulator/Device? OS version? Debug/Release?): Debug
This seems more suitable in Stack Overflow but if you need to pop back to a specific component, you should be remembering which component anyway, so maybe just store the desired component's componentId and use it in the screen you want to pop from.
Hi @andrei0807 , I made package for full redux integration for react-native-navigation. Npm : https://www.npmjs.com/package/react-native-navigation-redux-integration .
For your case you can use getActiveStackArray(state) selector which return array of active stack components ( each object has id, name and type, you can just us id for popTo method ). Feel free to try it.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.
The issue has been closed for inactivity.
In order to use popTo, you need to determine the "componentId" of that screen. The componentId is not the selected name of the component; It's a string which is a combination of "component" + "some random number". example: "component400"
So, you need to pass the componentId from Target screen to other screens:
Navigation.push(this.props.componentId, {
component: {
name: "example.selectedScreenName",
passProps: {
targetComponentId: this.props.componentId
}
},
});
Then, use the following code in current screen, to pop to the target screen:
onPress={() => Navigation.popTo(this.props.targetComponentId)}