navigation-rfc icon indicating copy to clipboard operation
navigation-rfc copied to clipboard

Support for "replace" navigation action?

Open aksonov opened this issue 9 years ago • 16 comments
trafficstars

I implement 'replace' support with my own reducer (just changing state.children[state.index]), it works except I'm getting yellow warning setState can only update a mounted component - i believe i've broken built-in NavigationCard animation stuff (any way to disable it?). Any possible solution to avoid warning?

screen shot 2016-03-14 at 19 50 39

aksonov avatar Mar 14 '16 19:03 aksonov

cc @hedgerwang

ericvicenti avatar Mar 14 '16 22:03 ericvicenti

@aksonov : do you have a minimum repro?

perhaps you can reproduce this with the modified module.exports = NavigationCardStackExample?

hedgerwang avatar Mar 15 '16 00:03 hedgerwang

@hedgerwang It is difficult to provide minimum repo, because 'replace' action is not supported by NavigationCardStackExample. I was able to reproduce it in Example project for my react-native-router-flux component, please check 3.0alpha branch: https://github.com/aksonov/react-native-router-flux/tree/3.0alpha

I'm doing 'replace' action there within componentDidMount of Launch class (to Login screen).

aksonov avatar Mar 16 '16 12:03 aksonov

@aksonov :

Does replace mean replace current navigationState with another one? For that case, you could probably change the reducer at NavigationCardStackExample to this:


function createReducer(initialState) {
  return (currentState, action) => {
    switch (action.type) {
      case 'RootContainerInitialAction':
        return initialState;

      case 'push':
        return NavigationStateUtils.push(currentState, {key: action.key});

      case 'back':
      case 'pop':
        return currentState.index > 0 ?
          NavigationStateUtils.pop(currentState) :
          currentState;
      case 'replace':
          return action.state,
      default:
        return currentState;
    }
  };
}

hedgerwang avatar Mar 16 '16 17:03 hedgerwang

No, replace means to replace one scene to another scene (with unmounting of previous scene) - what old Navigator does

aksonov avatar Mar 16 '16 17:03 aksonov

I see.

I think you could start with adding replace to NavigationStateUtils then change the reducer to the following:

function createReducer(initialState) {
  return (currentState, action) => {
    switch (action.type) {
      case 'RootContainerInitialAction':
        return initialState;

      case 'push':
        return NavigationStateUtils.push(currentState, {key: action.key});

      case 'back':
      case 'pop':
        return currentState.index > 0 ?
          NavigationStateUtils.pop(currentState) :
          currentState;
      case 'replace':
          return NavigationStateUtils.replace(currentState, {key: action.key});
      default:
        return currentState;
    }
  };
}

hedgerwang avatar Mar 16 '16 17:03 hedgerwang

I did it already with own reducer. The problem in that warning. Probably because replaced component is unmounted before transition ends..

Pavel.

16 марта 2016 г., в 18:16, Hedger Wang [email protected] написал(а):

I see.

I think you could start with adding replace to NavigationStateUtils then change the reducer to the following:

function createReducer(initialState) { return (currentState, action) => { switch (action.type) { case 'RootContainerInitialAction': return initialState;

  case 'push':
    return NavigationStateUtils.push(currentState, {key: action.key});

  case 'back':
  case 'pop':
    return currentState.index > 0 ?
      NavigationStateUtils.pop(currentState) :
      currentState;
  case 'replace':
      return NavigationStateUtils.replace(currentState, {key: action.key});
  default:
    return currentState;
}

}; } — You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub

aksonov avatar Mar 16 '16 18:03 aksonov

Do you want the replaces navigation state to go way with animation or just be removed immediately?

What kind of warning that you were getting? Could you please share a screenshot for that? Thanks.

hedgerwang avatar Mar 16 '16 22:03 hedgerwang

Screenshot is shown at first message - i was not able to see where is that setState call. I could live without animation, but community of my component also want possibility of animation... The problem happens only if i do replace within componentDidMount.

aksonov avatar Mar 18 '16 13:03 aksonov

any update on this ?

just showing my interest in this issue/feature :)

chandu0101 avatar Apr 05 '16 23:04 chandu0101

After upgrading to 0.24rc, replace action stops working at all, @hedgerwang, @ericvicenti Is there any docs how to migrate from 0.22 to 0.24rc (or 0.23)? I'm just replacing current element in the state with new one within reducer. It worked well within 0.22, but not for 0.24rc (0.23)

aksonov avatar Apr 18 '16 08:04 aksonov

If the new child state has a new key, it should get replaced. Otherwise it should get re-rendered. I'll look into it this afternoon. There are a bunch of reports on this, so it looks like something is seriously broken 😢

ericvicenti avatar Apr 18 '16 15:04 ericvicenti

@ericvicenti yep, broken for me too.

zackify avatar May 03 '16 18:05 zackify

Same issue here even on 0.25.1... any progress on this?

mmazzarolo avatar May 05 '16 09:05 mmazzarolo

@mmazzarolo Seems 0.26-rc works fine.

aksonov avatar May 17 '16 07:05 aksonov

@aksonov thanks man! Edit: nope, it is still not working for me.
Replacing the entire stack doesn't re-render the app. We should probably wait for this.

mmazzarolo avatar May 17 '16 07:05 mmazzarolo