From 972b33265e9ffde37d1efdb284035c9f284efb79 Mon Sep 17 00:00:00 2001 From: G Date: Mon, 27 May 2024 16:56:12 +0000 Subject: [PATCH] changed the name of the context to ModalsManager --- App.tsx | 27 +++++++++++++++------------ src/contexts/ModalsManagerContext.tsx | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/contexts/Overlay.tsx | 67 ------------------------------------------------------------------- 3 files changed, 98 insertions(+), 79 deletions(-) create mode 100644 src/contexts/ModalsManagerContext.tsx delete mode 100644 src/contexts/Overlay.tsx diff --git a/App.tsx b/App.tsx index 7f5bf89..2704a37 100644 --- a/App.tsx +++ b/App.tsx @@ -1,3 +1,4 @@ +import { ModalsManagerProvider } from "@/contexts/ModalsManagerContext"; import { UserAuthenticationContextProvider } from "@/contexts/UserAuthenticationContext"; import AppMainStackNavigator from "@/navigations/AppMainStackNavigator"; import theme from "@/themes/Theme"; @@ -13,21 +14,23 @@ export default function App() { log.verbose("App started..."); return ( - - - - - {/* */} - {/* + + + + + + {/* */} + {/* */} - - {/* */} - - - - + + {/* */} + + + + + ); } diff --git a/src/contexts/ModalsManagerContext.tsx b/src/contexts/ModalsManagerContext.tsx new file mode 100644 index 0000000..d2348be --- /dev/null +++ b/src/contexts/ModalsManagerContext.tsx @@ -0,0 +1,83 @@ +import ErrorModal from "@components/modals/ErrorModal"; +import LoadingModal from "@components/modals/LoadingModal"; +import { createContext, useContext, useState } from "react"; +import { View } from "react-native"; + +export interface ImodalsManagerContext { + showLoadingModal(): void; + closeLoadingModal(): void; + showErrorModal(): void; + closeErrorModal(): void; +} + +export const ModalsManagerContext = createContext({ + showLoadingModal: () => {}, + closeLoadingModal: () => {}, + showErrorModal: () => {}, + closeErrorModal: () => {}, +}); + +export const ModalsManagerProvider = ({ children }: { children: React.ReactNode }) => { + const [showBackdrop, setShowBackdrop] = useState(false); + const [loadingModalVisible, setLoadingModalVisible] = useState(false); + const [errorModalVisible, setErrorModalVisible] = useState(false); + + const showLoadingModal = () => { + setShowBackdrop(true); + setLoadingModalVisible(true); + }; + + const closeLoadingModal = () => { + setShowBackdrop(false); + setLoadingModalVisible(false); + }; + + const showErrorModal = () => { + setShowBackdrop(true); + setErrorModalVisible(true); + }; + + const closeErrorModal = () => { + setShowBackdrop(false); + setErrorModalVisible(false); + }; + + return ( + + {children} + {showBackdrop && } + + {loadingModalVisible && } + {errorModalVisible && } + + ); +}; + +export const useOverlayContext = () => { + return useContext(ModalsManagerContext); +}; + +const OverlayBackdrop = () => { + return ( + + ); +}; diff --git a/src/contexts/Overlay.tsx b/src/contexts/Overlay.tsx deleted file mode 100644 index 3f5ba2d..0000000 --- a/src/contexts/Overlay.tsx +++ /dev/null @@ -1,67 +0,0 @@ -import ErrorModal from "@components/modals/ErrorModal"; -import LoadingModal from "@components/modals/LoadingModal"; -import { createContext, useContext, useState } from "react"; -import { View } from "react-native"; - -export interface IoverlayContext { - showOverlay(): void; - hideOverlay(): void; -} - -export const OverlayContext = createContext({ - showOverlay: () => {}, - hideOverlay: () => {}, -}); - -export const OverlayProvider = ({ children }: { children: React.ReactNode }) => { - const [showBackdrop, setShowBackdrop] = useState(true); - const [loadingModalVisible, setLoadingModalVisible] = useState(false); - const [errorModalVisible, setErrorModalVisible] = useState(true); - - const showOverlay = () => { - setShowBackdrop(true); - setLoadingModalVisible(true); - }; - - const hideOverlay = () => { - setShowBackdrop(false); - setLoadingModalVisible(false); - }; - - return ( - - {children} - {showBackdrop && } - - {loadingModalVisible && } - {errorModalVisible && } - - ); -}; - -export const useOverlayContext = () => { - return useContext(OverlayContext); -}; - -const OverlayBackdrop = () => { - return ( - - ); -}; -- libgit2 0.27.1