From 6835caa7609259a64ba0aa2c9ddb34b7d5eb7793 Mon Sep 17 00:00:00 2001
From: Paul Frazee <pfrazee@gmail.com>
Date: Fri, 2 Sep 2022 11:51:46 -0500
Subject: Add more robust modals controller

---
 src/view/com/modals/Modal.tsx | 45 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 src/view/com/modals/Modal.tsx

(limited to 'src/view/com/modals/Modal.tsx')

diff --git a/src/view/com/modals/Modal.tsx b/src/view/com/modals/Modal.tsx
new file mode 100644
index 000000000..172dd0ad4
--- /dev/null
+++ b/src/view/com/modals/Modal.tsx
@@ -0,0 +1,45 @@
+import React, {useRef} from 'react'
+import {View} from 'react-native'
+import {observer} from 'mobx-react-lite'
+import BottomSheet from '@gorhom/bottom-sheet'
+import {useStores} from '../../../state'
+import {createCustomBackdrop} from '../util/BottomSheetCustomBackdrop'
+
+import * as LinkActionsModal from './LinkActions'
+
+export const Modal = observer(function Modal() {
+  const store = useStores()
+  const bottomSheetRef = useRef<BottomSheet>(null)
+
+  const onShareBottomSheetChange = (snapPoint: number) => {
+    if (snapPoint === -1) {
+      store.shell.closeModal()
+    }
+  }
+  const onClose = () => {
+    bottomSheetRef.current?.close()
+  }
+
+  if (!store.shell.isModalActive) {
+    return <View />
+  }
+
+  let snapPoints, element
+  if (store.shell.activeModal?.name === 'link-actions') {
+    snapPoints = LinkActionsModal.snapPoints
+    element = <LinkActionsModal.Component {...store.shell.activeModal} />
+  } else {
+    return <View />
+  }
+
+  return (
+    <BottomSheet
+      ref={bottomSheetRef}
+      snapPoints={snapPoints}
+      enablePanDownToClose
+      backdropComponent={createCustomBackdrop(onClose)}
+      onChange={onShareBottomSheetChange}>
+      {element}
+    </BottomSheet>
+  )
+})
-- 
cgit 1.4.1

