softchatjs-react-native
Version:
React native UI SDK for softchatjs-core. Create a free account at: https://www.softchatjs.com
77 lines • 1.9 kB
JavaScript
// src/contexts/ModalProvider.tsx
import React, { createContext, useContext, useState } from "react";
import {
Modal,
View
} from "react-native";
var initial = {
displayModal: () => {
},
resetModal: () => {
},
modalProps: {
dismissable: true,
justifyContent: "center",
children: null,
animation: "slide",
containerWidth: "100%"
}
};
var ModalProviderContext = createContext(initial);
var useModalProvider = () => useContext(ModalProviderContext);
function ModalProvider(props) {
const { children } = props;
const [modal, showModal] = useState(false);
const [modalProps, setModalProps] = useState(initial.modalProps);
const displayModal = (props2) => {
showModal(true);
setModalProps({ ...initial.modalProps, ...props2 });
};
const dismiss = () => {
if (modalProps?.dismissable) {
showModal(false);
}
};
const resetModal = (cb) => {
showModal(false);
cb?.();
};
return /* @__PURE__ */ React.createElement(
ModalProviderContext.Provider,
{
value: {
displayModal,
resetModal
}
},
children,
/* @__PURE__ */ React.createElement(
Modal,
{
animationType: modalProps?.animation,
style: { height: "100%", width: "100%" },
visible: modal,
transparent: true
},
/* @__PURE__ */ React.createElement(
View,
{
style: {
flex: 1,
height: "100%",
width: "100%",
alignItems: "center",
justifyContent: modalProps?.justifyContent,
backgroundColor: "rgba(0,0,0,.3)"
}
},
/* @__PURE__ */ React.createElement(View, { style: { flex: 1, width: "100%", height: "100%" } }, modalProps?.children)
)
)
);
}
export {
ModalProvider as default,
useModalProvider
};
//# sourceMappingURL=ModalProvider.mjs.map