How to change the bottom tab icon dinamically in React Navigation - react-native

I would like to know if it's possible to change the bottom tab icon dynamically, I mean, I'm interested to change one of the tab icons when an event occurs...
I have read the documentation but couldn't find any related info about it...
The only solution that I can think of is using a global store variable to control it when it's defined in the bottom tab navigation, using a solution similar to what react-navigation docs proposes here.

I would also think of using a global state management API such as Context API (https://reactjs.org/docs/context.html#dynamic-context), redux (https://redux.js.org/tutorials/quick-start), recoil (https://recoiljs.org/docs/introduction/installation/), etc.
and then set the global state variable on event handler, as well as in the ternary operator in the react-navigation example you provided (in the place
of "focused")

Related

Codename One Access SideNavigationPanel Using UIID

I have an Android app with a side menu. Since I am using css support, I need to style the side menu using code (what I prefer anyway).
I am facing difficulties finding the correct approach to access the side menu.
This is what I have tried:
Style sideMenuStyle = UIManager.getInstance().getComponentStyle("SideNavigationPanel");
sideMenuStyle.setBorder(Border.createEmpty());
sideMenuStyle.setFgColor(ColorUtil.GREEN);
sideMenuStyle.setBgColor(ColorUtil.BLUE);
sideMenuStyle.setBgTransparency(200);
The side menu is in place, but my code does not have any influence on the color of the background/ foreground.
What am I missing?
Why not use CSS to style the side navigation panel?
That makes far more sense.
getComponentStyle returns a new Style object instance which means your changes have no impact. This is important as each component invokes that method to get its own style. If it returned the same instance changes to the style of one component would impact all components.
You can use setComponentStyle but I'd strongly recommend you don't take that route.

React Native refresh screen / component / change state

I am using react-native, nested react-navigation, SectionLists, ActionSheet, etc and I am having hard times setting up a decent way of refreshing components / screens. As I have a few different cases, I have also tried different approaches with no luck.
Examples:
- Sending a callback function as a param in the navigator when transitioning from one screen to another for state change.
- Assigning AsyncStorage.getItem straight to a state variable (e.g: used on a ListView) and expect it to refresh.
I've seen many questions in the react-navigation git repo (mainly on how to refresh a screen), and recent suggestion to the project on the best approach for future releases, that got me asking if this is something that is in place already.
I can say though, that I've successfully used redux to check the connection state (NetInfo), that although I couldn't yet port the same idea to a different schenario, I think that it is my best approach.
At the moment I have one schenario, that if solved, I believe will answer a few questions I have. For example:
I have a list of news in my Home screen and a few options in my Drawer navigator that I would like to, when clicked, to sort the Home list, without having to call navigate('screen_name') as I would like to, to still keep the Drawer opened after clicked.
What would be the best approach for this ?
Thanks in advance!
One approach you could follow is:
On click on a DrawerNavigator item, you can dispatch an action which would intern change the state by a value. Eg: filterBy: . This store value can be passed as a prop to your home screen, which would intern contain a logic to filter based on that value.
I havent worked with DrawerNavigator but i feel onPress on each item in drawer navigation can be prevented and a action can be invoked at the same place.

Differences between this.props.navigation.dispatch vs this.props.navigation.navigate?

I see a lot of folks in the react-navigation issues section using this.props.navigation.dispatch to programmatically navigate. Is there any specific reason or use case to use that over this.props.navigation.navigate?
It seems like you can pass more options to the dispatch function? Is there anything else? Can you use dispatch without explicitly tying react-navigation into your apps redux store? Right now I have an app that has redux, but I dont explicitly configure my redux setup to know about react-navigation (and would prefer to keep it that way if I can).
From github 👇🏻:
This is the code of navigate function which reuses navigation.dispatch.. And remember:
Code Don't Lie
Then, navigation.navigate(...args) is an alias of navigation.dispatch(NavigationActions.navigate(...args))
From the React Navigation docs The Navigation Prop chapter (https://reactnavigation.org/docs/navigators/navigation-prop#dispatch-Send-an-action-to-the-router):
...The other navigation functions use dispatch behind the scenes...
Also parameters for NavigationActions.navigate and this.props.navigation.navigate are the same. There should be no difference which one you use. In my opinion, this.props.navigation.navigate is shorter and more readable.

Vuejs: shared states between components

I would like to know the best practice for implementing shared states between components in Vuejs.
Imagine situation A: you have a web app that shows a modal. The modal has the boolean state show. This state should change if the modal OK-button is clicked, but also if any part of the background is clicked, and perhaps even on some server pushed state change. Thus the modal should be able to change the state as should the parent app.
Situation B: you have a web app that shows input fields inside different components that share a common data value. If the user changes value through the field in one component, it should also update in the other. Again both should even update on a server push event.
Questions:
I am right that the correct way to go about this would be to use vuex and make the shared state a store field that is observed by and changed through emitted actions by all components / parents that need to modify that value?
Does that not introduce this kind of dangerous (since hard to handle) magic reactivity that we know from Meteor?
How to best document the flow, what depends on what?
A: For a modal component, I'd say that show should be a prop. So the parent component can control the modal whatever it wants. In this case there is no shared state at all.
The modal itself doesn't need to know anything about the server. If the prop show is true, just display the modal and vice versa.
I think the mask layer is a part of the modal, so when the mask is clicked, the modal emits an event. The parent component receives the event and can decide to hide the modal or not to.
Vue has an official modal example here (thanks #craig_h for mentioning): https://v2.vuejs.org/v2/examples/modal.html
B: Just bind the vuex state to the inputs. Nothing wrong.
Note that not all the components need to access the vuex store directly. For some pure UI components, just use props. So the parent components have the right to control them and increase flexibility.
I recommend you to read these docs:
https://facebook.github.io/react/docs/lifting-state-up.html
https://medium.com/#dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0#.j7ry4a3as
http://redux.js.org/docs/basics/UsageWithReact.html
Yes these are React / Redux docs. Since Vue is relatively young, react community has more documentation / articles. But both Vue and React are component-based libraries. The idea of how you design a component is basically the same.
You can also take a look at this vuex example: https://github.com/vuejs/vuex/tree/dev/examples/chat
This is a very simple example but it does use all the things I mentioned above. Emitting an event, some pure UI components...

'Global' modal in React Native

I'm building an app in React native, and basically, I need a modal(which will have the same content every time) to be available globally (in all components of app), so that I can be able to open it from anywhere in my app.
Obviously copy/pasting the same modal in all the components is not a good solution
Right now I'm having tons of trouble implementing it, so I would like to know what would be the best way to accomplish something like that
Use a Navigator and place your modal below it. Make it visible only when the state changes. The state can be changed from each component inside the Navigator via props.navigator.
You can see the full code with explanation here http://browniefed.com/blog/react-native-easy-overlay-modal-with-navigator/