about summary refs log tree commit diff
path: root/src/view/com/util/EventStopper.tsx
blob: e743e89bbe9d63333288afa39de293cb7cca43b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import React from 'react'
import {View, ViewStyle} from 'react-native'

/**
 * This utility function captures events and stops
 * them from propagating upwards.
 */
export function EventStopper({
  children,
  style,
}: React.PropsWithChildren<{style?: ViewStyle | ViewStyle[]}>) {
  const stop = (e: any) => {
    e.stopPropagation()
  }
  return (
    <View
      onStartShouldSetResponder={_ => true}
      onTouchEnd={stop}
      // @ts-ignore web only -prf
      onClick={stop}
      onKeyDown={stop}
      style={style}>
      {children}
    </View>
  )
}