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

Changing scene makes render methods be called multiple times for a single action, stacking up #2827

Closed
NikiTsv opened this issue Jan 23, 2018 · 2 comments

Comments

@NikiTsv
Copy link

NikiTsv commented Jan 23, 2018

Version

  • react-native-router-flux v4.0.0-beta.28 (v3 is not supported)
  • react-native v0.52.0

Expected behaviour

Changing scene should dispose components and their 'render' methods should be called only once.
Lifecycle method - 'componentWillUnmount' is being called when switching scene.

Actual behaviour

Changing scenes makes components' render method be called multiple times (stacking for each scene change).
Component lifecycle method 'componentWillUnmount' is not called.

Steps to reproduce

For non-obvious bugs, please fork this component, modify Example project to reproduce your issue and include link here.

  1. When changing to scene A the render method of the component is called once.
  2. When I change to scene B the render method of component in scene A and component in B are called.
  3. When I change back to scene A the component A method is called two times and component B method is called one time.
  4. This stacks up multiple times. It's like the components are living in the background and are not disposed.

Code samples:

Note - those are containers.
Router.js:

<Router>
      <Scene key="root" navigationBarStyle={styles.navigationBarStyle}>
        <Scene key="login" hideNavBar={true} component = {LoginContainer} title = "Login" />  
        <Scene key="enotMap"  hideNavBar={true} component={EnotMapContainer} title = "Enot map!"/>
        <Scene key="main"  hideNavBar={true} component={MainContainer} title = "Home!"/>
        <Scene key="filters"  hideNavBar={true} component={MainContainer} title = "Home!"/>
        <Scene key="poiDetailsView"  hideNavBar={true} component={PoiDetailsViewContainer} title = "Details!"/>
      </Scene>
    </Router>

MainContainer:

    let catFilteredItems = filterItemsPoisByCategories(state.enotMap.markers.items, state.enotMap.userFilters.categories);
    let timeAndCategoryFilteredItems = filterPoisByTime(catFilteredItems, state.enotMap.userFilters.selectedTimeFilter);
    return {
        items: timeAndCategoryFilteredItems,
        routing: state.routing,
    }
};

const mapDispatchToProps = (dispatch) => ({
    changeScene: (sceneInfo) => {
        dispatch(changeScene(sceneInfo))
    },
})

export const MainContainer = connect(mapStateToProps, mapDispatchToProps)(Main);

Example reducer code that changes the scenes:

    switch (action.type){
        case actionTypes.SCENE_CHANGE:
            // TODO: switch
            if(action.sceneName == SceneNames.enotMap) Actions.enotMap();
            if(action.sceneName == SceneNames.main) Actions.main();
            if(action.sceneName == SceneNames.poiDetailsView) Actions.poiDetailsView();
            if(action.sceneName == SceneNames.filters) Actions.filters();

            return {
                headerText: getHeaderText(action.sceneName),
                sceneInfo: {itemId: action.itemId},
                scene: action.sceneName
            }
        default:
            return state;
    };
};```
Can this be used with containers or only simple components?
@NikiTsv
Copy link
Author

NikiTsv commented Jan 24, 2018

Using Actions.reset('someSceneName') disposes all the pages in the stack and thus not calling their render method each time.
I navigate to my main page by using reset to clear the stack.
Pressing back makes the app exit but that's okay in my case.

@aksonov
Copy link
Owner

aksonov commented Aug 8, 2018

Please try to reproduce it with Example project and latest version 4.0.0-beta.40. Feel free to open if the issue still exists

@aksonov aksonov closed this as completed Aug 8, 2018
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

2 participants