diff --git a/src/components/AppActionSheet.js b/src/components/AppActionSheet.js index 51efc1a..98312c2 100644 --- a/src/components/AppActionSheet.js +++ b/src/components/AppActionSheet.js @@ -18,15 +18,17 @@ const AppActionSheet = ({ if (isWeb && webModal) { return ( - + - - {children} - + + + {children} + + ); @@ -70,10 +72,18 @@ export default AppActionSheet; const styles = StyleSheet.create({ webOverlay: { ...StyleSheet.absoluteFillObject, + position: "fixed", + zIndex: 100, + }, + webBackdrop: { + ...StyleSheet.absoluteFillObject, + backgroundColor: "rgba(0, 0, 0, 0.55)", + }, + webModalWrapper: { + flex: 1, alignItems: "center", justifyContent: "center", padding: 24, - backgroundColor: "rgba(0, 0, 0, 0.55)", }, webModalCard: { width: 480, diff --git a/src/components/modal/ShareModal.js b/src/components/modal/ShareModal.js index 306b20a..ee6ca7b 100644 --- a/src/components/modal/ShareModal.js +++ b/src/components/modal/ShareModal.js @@ -18,6 +18,7 @@ import { StyleSheet, Text, View, + findNodeHandle, } from "react-native"; import { SheetManager } from "react-native-actions-sheet"; @@ -45,15 +46,33 @@ const ShareModal = ({ payload }) => { const [copied, setCopied] = useState(false); const copyTimeout = useRef(null); + const modalRef = useRef(null); + const [webVisible, setWebVisible] = useState(true); const blurProps = Platform.OS === "android" ? { experimentalBlurMethod: "dimezisBlurView" } : {}; const closeSheet = useCallback(() => { - return SheetManager.hide("Share"); + if (isWeb) { + setWebVisible(false); + } + + try { + const maybePromise = SheetManager.hide("Share"); + return Promise.resolve(maybePromise); + } catch (error) { + console.error("share.sheet.close", error); + return Promise.resolve(); + } }, []); + useEffect(() => { + if (isWeb) { + setWebVisible(true); + } + }, [payload]); + const shareText = useMemo(() => { return [shareMessage, url].filter(Boolean).join(" "); }, [shareMessage, url]); @@ -72,6 +91,46 @@ const ShareModal = ({ payload }) => { }; }, []); + useEffect(() => { + if (!isWeb || typeof document === "undefined" || !webVisible) { + return; + } + + const handlePointerDown = (event) => { + const node = modalRef.current; + if (!node) { + return; + } + + const domNode = findNodeHandle(node); + if (domNode && typeof domNode.contains === "function") { + if (domNode.contains(event.target)) { + return; + } + } + + if (domNode === event.target) { + return; + } + + closeSheet(); + }; + + const handleKeyDown = (event) => { + if (event.key === "Escape") { + closeSheet(); + } + }; + + document.addEventListener("pointerdown", handlePointerDown); + document.addEventListener("keydown", handleKeyDown); + + return () => { + document.removeEventListener("pointerdown", handlePointerDown); + document.removeEventListener("keydown", handleKeyDown); + }; + }, [closeSheet, webVisible]); + const handleCopy = useCallback(async () => { try { if (copyTimeout.current) { @@ -288,85 +347,93 @@ const ShareModal = ({ payload }) => { ); - const webContent = ( - - - {heading} - - - - - - {shareMessage} - - - - {linkLabel} - - - - - {copied ? "Lien copiƩ" : "Copier le lien"} - - - - - - Partager - - - - - - {sectionTitle} - - {shareOptions.map((option, index) => { - const Icon = option?.Icon ?? Feather; - return ( - handleShareOption(option)} - style={styles.webOptionRow} - > - - - - {option?.label} - - - ); - })} - - - - - ); + if (isWeb && !webVisible) { + return null; + } return ( - {isWeb ? webContent : mobileContent} + {isWeb ? ( + + + {heading} + + + + + + {shareMessage} + + + + {linkLabel} + + + + + {copied ? "Lien copiƩ" : "Copier le lien"} + + + + + + Partager + + + + + + {sectionTitle} + + {shareOptions.map((option, index) => { + const Icon = option?.Icon ?? Feather; + return ( + handleShareOption(option)} + style={styles.webOptionRow} + > + + + + {option?.label} + + + ); + })} + + + + + ) : ( + mobileContent + )} ); }; diff --git a/src/components/modal/ShareQrModal.js b/src/components/modal/ShareQrModal.js index d339263..461842d 100644 --- a/src/components/modal/ShareQrModal.js +++ b/src/components/modal/ShareQrModal.js @@ -23,10 +23,11 @@ const ShareQrModal = ({ return ( - + @@ -71,7 +72,12 @@ const ShareQrModal = ({ }; const styles = StyleSheet.create({ + overlay: { + ...StyleSheet.absoluteFillObject, + zIndex: 200, + }, backdrop: { + ...StyleSheet.absoluteFillObject, backgroundColor: "rgba(0, 0, 0, 0.65)", }, centerWrapper: {