react-native-navigation icon indicating copy to clipboard operation
react-native-navigation copied to clipboard

popTo method

Open andrei0807 opened this issue 7 years ago • 5 comments

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

andrei0807 avatar Jan 29 '19 03:01 andrei0807

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.

jinshin1013 avatar Jan 30 '19 07:01 jinshin1013

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.

manicantic avatar Jan 31 '19 22:01 manicantic

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.

stale[bot] avatar Mar 02 '19 23:03 stale[bot]

The issue has been closed for inactivity.

stale[bot] avatar Mar 09 '19 23:03 stale[bot]

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)}

Garamani avatar Nov 07 '20 12:11 Garamani