Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for "replace" navigation action? #50

Open
aksonov opened this issue Mar 14, 2016 · 16 comments
Open

Support for "replace" navigation action? #50

aksonov opened this issue Mar 14, 2016 · 16 comments

Comments

@aksonov
Copy link

aksonov commented Mar 14, 2016

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

@ericvicenti
Copy link
Owner

cc @hedgerwang

@hedgerwang
Copy link
Collaborator

@aksonov : do you have a minimum repro?

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

@aksonov
Copy link
Author

aksonov commented Mar 16, 2016

@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).

@hedgerwang
Copy link
Collaborator

@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;
    }
  };
}

@aksonov
Copy link
Author

aksonov commented Mar 16, 2016

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

@hedgerwang
Copy link
Collaborator

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

@aksonov
Copy link
Author

aksonov commented Mar 16, 2016

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 notifications@github.com написал(а):

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

@hedgerwang
Copy link
Collaborator

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.

@aksonov
Copy link
Author

aksonov commented Mar 18, 2016

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.

@chandu0101
Copy link

any update on this ?

just showing my interest in this issue/feature :)

@aksonov
Copy link
Author

aksonov commented Apr 18, 2016

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)

@ericvicenti
Copy link
Owner

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 😢

@zackify
Copy link

zackify commented May 3, 2016

@ericvicenti yep, broken for me too.

@mmazzarolo
Copy link

mmazzarolo commented May 5, 2016

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

@aksonov
Copy link
Author

aksonov commented May 17, 2016

@mmazzarolo Seems 0.26-rc works fine.

@mmazzarolo
Copy link

mmazzarolo commented May 17, 2016

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants