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

[v2] 'Component id already exists' when using setStackRoot

Open thinklinux opened this issue 7 years ago • 4 comments

Issue Description

I'm trying to replace a screen in the stack. So I figured that setStackRoot is maybe the way to do it because there is no replace API and setStackRoot supports multiple children. So if I rebuild the stack it should be the same as replacing a part of it.

Code Snippets

Navigation.setStackRoot('CustomComponentId', [
  { 
    component: {
      id: 'CustomId',
      name: 'CustomName'
    } 
  },
  {
    component: {
      id: 'CustomId2',
      name: 'CustomName2'
    }
  },
]);

Screenshot

The code above results in that error:

screenshot 2019-01-17 at 10 19 20


Environment

  • React Native Navigation version: 2.5.2
  • React Native version: 0.57.1
  • Platform(s) (iOS, Android, or both?): iOS
  • Device info (Simulator/Device? OS version? Debug/Release?): Simulator / Debug

So I can't use that API if a component is already in the stack. I think that this is directly related to this issue #4333. Is there any workaround for replacing a component in the stack?

thinklinux avatar Jan 17 '19 08:01 thinklinux

Hello, I encounter the issue myself, so if anyone has an idea to share, I'd greatly appreciate it !

kiroukou avatar Feb 04 '19 19:02 kiroukou

Hi @thinklinux, I made library for redux integration for RNN : https://www.npmjs.com/package/react-native-navigation-redux-integration. So if you integrate it with your project you can omit custom IDs and use selectors for getting component ids ( RNN will always create unique id for every component you use). In your example you can either use getActiveScreenId selector or even better, dispatch action and let middleware handle setting stack root with this action creator setStackRoot ( If you are currently on active stack ). Just dispatch actions like this

dispatch(setStackRoot([
  { 
    component: {
     //note - no id
      name: 'CustomName'
    } 
  },
  {
    component: {
      name: 'CustomName2'
    }
  },
]))

Also library provides more selectors and middleware actions.

manicantic avatar Feb 07 '19 09:02 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 09 '19 10:03 stale[bot]

The issue has been closed for inactivity.

stale[bot] avatar Mar 16 '19 10:03 stale[bot]