'Global' modal in React Native - 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/

Related

How to change the bottom tab icon dinamically in React Navigation

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")

react-native-collapsible close collapsible from any press

I am using react-native-collapsible for a project. Everything working well but I would like the user to be able to close the collapsible by clicking anywhere on the screen when it is opened. On a desktop it would be easy with a !event.target match but since I am new to React Native (expo) I am a bit out of solution.
Thanks a lot, I pasted no code because I am currently using the Lorem example from the lib so won't be much useful.
You can Make one useState variable and pass it into the property of
collapsed={Your useState Veriable} react-native-collapsible .
also make all the Design wrap into TouchableOpacity and it's onPress event to make it true.

Components for only tabs in React-Native

I want to achieve this in react-native,
Is there a component that have this tab switching animation with also capability off adding an icon next to tabName if possible.
P.S: I found a component react-native-material-tabs but without the ability to an icon. Also found components that requires container component, where I just need one for tabs for my use case.

Quora-like expandable component in React Native

I'm trying to build a React Native app and would like to implement a component just like in Quora where upon clicking the question, the component expands and shows the remaining details (text/images of the question).
I tried using react-native-panel from https://github.com/dwicao/react-native-panel#readme, but it can only handle text in the panel before expanding. I'd like to implement a panel that has an image in it even before I press on the panel to expand. Would love it if anyone could refer me to any npm packages that use components to achieve this. Thank you!
Use this tutorial https://blog.theodo.com/2020/06/build-accordion-list-react-native/. Stick the desired image somewhere there in the code.

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.