React-native-router-flux: Get active route on Drawer

Created on 30 May 2016  ·  3Comments  ·  Source: aksonov/react-native-router-flux

Hello, I want to highlight the current active item on my Drawer, how can I get the current scene/route so I can highlight the corresponding item?
I tried Actions.currentRouter but it is undefined.

Thanks

question

Most helpful comment

If you are using the default reducer you can also get access to the current state and hence the route using:

const reducerCreate = params=>{

    const defaultReducer = Reducer(params);

    return (state, action)=>{


       // The following is an example alternative implementation of Reducer.js .getCurrent(state)
        var currentState = state;

        if(currentState){
          while (currentState.children){
            currentState = currentState.children[currentState.index]
          }
        }

        return defaultReducer(state, action);
    }
};

All 3 comments

If you use redux, maybe you can check this to get the this.props.route.key.

If you are using the default reducer you can also get access to the current state and hence the route using:

const reducerCreate = params=>{

    const defaultReducer = Reducer(params);

    return (state, action)=>{


       // The following is an example alternative implementation of Reducer.js .getCurrent(state)
        var currentState = state;

        if(currentState){
          while (currentState.children){
            currentState = currentState.children[currentState.index]
          }
        }

        return defaultReducer(state, action);
    }
};

Would be nice to add it to the docs of the drawer part

Was this page helpful?
0 / 5 - 0 ratings