blob: 24bc47afd2af7ae7377dc704dce011619c557845 (
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
27
28
29
30
31
32
33
|
import {View, type ViewStyle} from 'react-native'
import type React from 'react'
/**
* This utility function captures events and stops
* them from propagating upwards.
*/
export function EventStopper({
children,
style,
onKeyDown = true,
}: React.PropsWithChildren<{
style?: ViewStyle | ViewStyle[]
/**
* Default `true`. Set to `false` to allow onKeyDown to propagate
*/
onKeyDown?: boolean
}>) {
const stop = (e: any) => {
e.stopPropagation()
}
return (
<View
onStartShouldSetResponder={_ => true}
onTouchEnd={stop}
// @ts-ignore web only -prf
onClick={stop}
onKeyDown={onKeyDown ? stop : undefined}
style={style}>
{children}
</View>
)
}
|