about summary refs log tree commit diff
path: root/src/view/com/util/EventStopper.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/view/com/util/EventStopper.tsx')
-rw-r--r--src/view/com/util/EventStopper.tsx22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/view/com/util/EventStopper.tsx b/src/view/com/util/EventStopper.tsx
new file mode 100644
index 000000000..1e672e945
--- /dev/null
+++ b/src/view/com/util/EventStopper.tsx
@@ -0,0 +1,22 @@
+import React from 'react'
+import {View} from 'react-native'
+
+/**
+ * This utility function captures events and stops
+ * them from propagating upwards.
+ */
+export function EventStopper({children}: React.PropsWithChildren<{}>) {
+  const stop = (e: any) => {
+    e.stopPropagation()
+  }
+  return (
+    <View
+      onStartShouldSetResponder={_ => true}
+      onTouchEnd={stop}
+      // @ts-ignore web only -prf
+      onClick={stop}
+      onKeyDown={stop}>
+      {children}
+    </View>
+  )
+}