From 7dd5f05c2ec90f663f1e49f4286352762599b639 Mon Sep 17 00:00:00 2001 From: G Date: Wed, 11 Sep 2024 15:32:33 +0000 Subject: [PATCH] updated a little bit the rendering condition and export the modal z index os that other component can increment their based on this value --- src/contexts/ModalsManagerContext.tsx | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/contexts/ModalsManagerContext.tsx b/src/contexts/ModalsManagerContext.tsx index abe286e..5d83af6 100644 --- a/src/contexts/ModalsManagerContext.tsx +++ b/src/contexts/ModalsManagerContext.tsx @@ -1,4 +1,4 @@ -import { createContext, useContext, useState } from "react"; +import { createContext, useContext, useEffect, useState } from "react"; import { View } from "react-native"; export interface ImodalsManagerContext { @@ -26,6 +26,13 @@ export const ModalsManagerProvider = ({ children }: { children: React.ReactNode setShowBackdrop(false); }; + useEffect(() => { + return () => { + setShowBackdrop(false); + setModalElement(null); + }; + }, []); + return ( {children} - {showBackdrop && } - {modalElement && modalElement} + + {modalElement && ( + <> + + {modalElement} + + )} ); }; @@ -44,6 +56,8 @@ export const useModalsManagerContext = () => { return useContext(ModalsManagerContext); }; +export const OVERLAY_BACKDROP_Z_INDEX = 10; + const OverlayBackdrop = () => { return ( { height: "100%", // justifyContent: "center", // alignItems: "center", - zIndex: 10, + zIndex: OVERLAY_BACKDROP_Z_INDEX, backgroundColor: "black", opacity: 0.5, position: "absolute", -- libgit2 0.27.1