Display any view on top of native-stack's modal
Hello, thank you for this awesome library.
Is there any possible solution to display any view on top of visible stack's modal?
I realized, that react-native-modal is not visible over stack's modal, and also there is no way to display any view on top of screen. For example, I need to display in-app-notification on top of all content, or sometime display modal loader spinner - both of them are not appears when stack's modal is visible.
This is related to ios only, android works fine.
I've got the same issue. iOS-Modal issue only.
same issue
This issue is known and also reported by me. You can't even toggle the element inspector on the modal. They managed to get EXPOs Dev Menu finally to overlay the modal, but not sure about any other view. The modal is currently the most top element that nothing can overlap. I also had issues with in-app-notifications and worked around displaying them inside the modal when modal was open - but yeah, there should be another method for it. Maybe we need to wrap a provider for that native-modal and let it mount there - dunno if thats even possible, just thinking.
P:S the modal from import { Modal } from "react-native" actually can overlap it. My app uses this too
@Hirbod how Modal from react-native can overlap? I've tested it for a while, but modal just invisible and dismisses almost right after mounted.
@Strate https://streamable.com/mtsbmh here, from my app
@Hirbod wow, awesome! This is looks like Shared Element Transition, but with Modal?
Yes, tooked me a crazy amount of time and is not smooth on android :D But it works with react-native modal in a react-native-screens modal :D Hopefully we will have natie-shared-element support for v5 stack at some point :)
@Hirbod could you please share some code for Modal from react-native? Which presentation used for display over screen's modal? Because my modal still invisible :(
@Strate its nothing special.
import { Modal } from "react-native";
....
...
...
renderFullscreen = () => {
return (
<Modal
transparent
visible={fullscreen}
onShow={this.handleModalShow}
onRequestClose={this.close}
/>
)};
I think the important thing is that Modal isn't rendered on mount. My modal gets rendered when my Image receives an onPress. I have an if-statement around my Modal in my code.
And my renderFullScreen returns the Modal and unmounts again in my close function. My onPress sets the state fullscreen to true and renders the modal
return (
<View>
<TouchableWithoutFeedback onPress={....}>
<View>
<ImageCustom />
</View>
</TouchableWithoutFeedback>
{fullscreen && this.renderFullscreen()}
</View>
);
I've the same issue, I'm trying to display a loader but can't draw over the 'formsheet' modal.
<>
<NavigationContainer>
<Stack.Navigator screenOptions={{ stackPresentation: 'formSheet' }} .... >
</NavigationContainer>
<View style={{
...Stylesheet.absoluteFillObject,
zIndex: 1000,
backgroundColor: 'rgba(0,0,0,0.4)'
}}/> /* <<< */
</>
Can you provide a repo with the thing you want to achieve so I could work on it?
Hi @WoLewicki this repo explains the issue ( at least the one I'm having.)
https://github.com/a-eid/react-native-native-stack-global-loader
you can see that when we have a formSheet screen the loader is behind the screen unlike the normal screen. please let me know if you need more context.
I wan't to do another example for toast but it basically is the same idea.
thank you.
it's also worth noting that this happens also with other modals.
also a modal screen (using stackPresentation:modal) does not pop up over a react-native-modal's modal component.
@a-eid regarding your example: the loader will not load above the modal this way since all the views displayed under the root view of the application will be displayed also under the modal screens. You can spot the same thing while using Modal component from react-native. It is like so because of the native view hierarchy of iOS. Roots of the modals are above the react's root view, so the only way to display something above the modal is to either display it in that modal, or display another modal on the previous modal. In particular, for your example, the flow can be changed somehow like that:
<Stack.Screen
name="modal-screen"
options={{
stackPresentation: 'formSheet',
}}>
{() => (
<GlobalLoader>
<ModalScreen />
</GlobalLoader>
)}
</Stack.Screen>
Then the GlobalLoader component is under the modal screen in the view hierarchy and is displayed on the modal component.
Another option, maybe even better, is to make the GlobalLoader a Screen of the stack and call navigation to it when triggered and goBack when removing it. In order for it to be displayed on the whole screen, you can use stackPresentation: 'transparentModal' which will give you an option to make the component semi-transparent. Does it solve your issue?
@Abhishek12345679 yes, because it messes with the modal stack of native-stack and is not permitted in react-native-screens since they both use view controllers.
@WoLewicki thank you for the reply.
I'm wondering how would you display toasts on a 'formSheet' screens ?
also can you trigger a modal with Animated.Value ?
About the first question, what is the difference of having formSheet screens for displaying toasts? I think the approach should be the same, the Toast should be a child of the Screen component in order to be visible over the modal screen. You probably cannot use transparentModal then because it disables touches on the screens under it.
About the second question, I am not sure what you mean. If you mean to control the transition of the modal appearing then no, since it is controlled by a native UINavigationController.
global toasts are great when you have a background task ( socket connection or even an api request ). and you wanna notify the user when the task is finish ( success | error ). there is no way to find out where the user is on the app.
global toasts & loaders have a single mount point which is really great for those cases and convenient for almost all other cases.
I'm not really that familiar with IOS but do u think there is a way to do that on ios Natively ?
You can read more about how certain interactions with user on iOS should be implemented in Apple's HIG. You can look at e.g. Alert Views and then look for libraries in react-native that implement those things. Also, I think it is just not possible to have the listener for such events in one place only when trying to use native iOS modal views since they simply aren't children of RCTRootView. Can I help you more with it?
@WoLewicki thank you very much, I'll be reading more about it.