Commit 7dd5f05c by G

updated a little bit the rendering condition and export the modal z index os…

updated a little bit the rendering condition and export the modal z index os that other component can increment their based on this value
parent 197cada0
import { createContext, useContext, useState } from "react"; import { createContext, useContext, useEffect, useState } from "react";
import { View } from "react-native"; import { View } from "react-native";
export interface ImodalsManagerContext { export interface ImodalsManagerContext {
...@@ -26,6 +26,13 @@ export const ModalsManagerProvider = ({ children }: { children: React.ReactNode ...@@ -26,6 +26,13 @@ export const ModalsManagerProvider = ({ children }: { children: React.ReactNode
setShowBackdrop(false); setShowBackdrop(false);
}; };
useEffect(() => {
return () => {
setShowBackdrop(false);
setModalElement(null);
};
}, []);
return ( return (
<ModalsManagerContext.Provider <ModalsManagerContext.Provider
value={{ value={{
...@@ -34,8 +41,13 @@ export const ModalsManagerProvider = ({ children }: { children: React.ReactNode ...@@ -34,8 +41,13 @@ export const ModalsManagerProvider = ({ children }: { children: React.ReactNode
}} }}
> >
{children} {children}
{showBackdrop && <OverlayBackdrop />}
{modalElement && modalElement} {modalElement && (
<>
<OverlayBackdrop />
{modalElement}
</>
)}
</ModalsManagerContext.Provider> </ModalsManagerContext.Provider>
); );
}; };
...@@ -44,6 +56,8 @@ export const useModalsManagerContext = () => { ...@@ -44,6 +56,8 @@ export const useModalsManagerContext = () => {
return useContext(ModalsManagerContext); return useContext(ModalsManagerContext);
}; };
export const OVERLAY_BACKDROP_Z_INDEX = 10;
const OverlayBackdrop = () => { const OverlayBackdrop = () => {
return ( return (
<View <View
...@@ -53,7 +67,7 @@ const OverlayBackdrop = () => { ...@@ -53,7 +67,7 @@ const OverlayBackdrop = () => {
height: "100%", height: "100%",
// justifyContent: "center", // justifyContent: "center",
// alignItems: "center", // alignItems: "center",
zIndex: 10, zIndex: OVERLAY_BACKDROP_Z_INDEX,
backgroundColor: "black", backgroundColor: "black",
opacity: 0.5, opacity: 0.5,
position: "absolute", position: "absolute",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment