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

Is it possible to hide a particular tab in TabBar from inside a scene? #1247

Closed
dragfire opened this issue Oct 5, 2016 · 8 comments
Closed

Comments

@dragfire
Copy link
Contributor

dragfire commented Oct 5, 2016

I have 5 Tabs in TabBar and I would like to manipulate them from inside a Scene.
Is it possible to manipulate them using Actions.refresh?

@ArtemX9
Copy link

ArtemX9 commented Oct 19, 2016

@dragfire You have to write your own action and dispatch it. You also need to add action handling in you custom reducer.

@dragfire
Copy link
Contributor Author

@ArtemX9
Copy link

ArtemX9 commented Oct 19, 2016

You can import Reducer from react-native-router-flux, and implement it like this:

const reducerCreate = params => {
  const defaultReducer = new Reducer(params);
  return (state, action) => {
    switch (action.type) {
      case '*YOUR_ACTION_NAME*':
        ....manipulations with the state here....
        return state;
      default:
        return defaultReducer(state, action);
    }
  };
};

and then call it this way:

ACTIONS.*YOUR_SCENE_NAME*({ type: '*YOUR_ACTION_NAME*' });

@dragfire
Copy link
Contributor Author

Thank you @ArtemX9

@dragfire
Copy link
Contributor Author

dragfire commented Oct 20, 2016

@ArtemX9 I've implemented the reducer as you suggested. Everything is working as I want but there is a warning: Component's children should not be mutated being thrown in the console.

Here's my custom reducer:

const reducerCreate = params => {
    const defaultReducer = new Reducer(params);
    return (state, action) => {

        switch (action.type) {
            case CustomActions.REMOVE_TWO_TABS:

                let childrens = state.children;
                childrens[1].children.splice(1, 2);
                console.log('CHILDRENS:', childrens);
                return Object.assign({}, state, childrens);
            default:
                return defaultReducer(state, action);
        }
    };
};

Is it a false-positive or am I doing something wrong?

@ArtemX9
Copy link

ArtemX9 commented Oct 21, 2016

@dragfire try to clone state.children before splicing, because splice mutates the original array. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice

@dragfire
Copy link
Contributor Author

Ok thanks!

@hoangdoan267
Copy link

hoangdoan267 commented Jan 18, 2017

@dragfire I always have an error at const defaultReducer = new Reducer(params);
it said undefined is not an object (evaluating ' _ref3.initialState) ?

P/s: I want to change Tabbar title when pressing a button

import { Reducer } from 'react-native-router-flux'
const initialState = {
  tabStatus: "VN"
}
const routerReducer = params => {
  const defaultReducer = new Reducer(params)
  return (state, action) => {
    switch (action.type) {
      case 'CHANGE_LANGE':
        return {
          ...state,
          tabStatus: "EN"
        }
        break;
      default:
         return defaultReducer(state, action);
    }
  }
}

export default routerReducer

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

3 participants