11import React , { useRef , useEffect } from 'react' ;
2- import { Pressable } from 'react-native' ;
2+ import { View , Platform } from 'react-native' ;
3+ import type { ViewProps } from 'react-native' ;
34import useEvent from '../hooks/use-event' ;
45import deepClone from '../utils/deep-clone' ;
56
6- interface IOutsidePressHandlerProps {
7- children : JSX . Element ;
7+ interface IOutsidePressHandlerProps extends ViewProps {
88 onOutsidePress : ( ) => void ;
99}
1010
1111export default function OutsidePressHandler ( props : IOutsidePressHandlerProps ) {
1212 const { children, onOutsidePress } = props ;
13- const id = useRef ( Math . random ( ) . toString ( ) ) . current ;
13+ const id : string = useRef ( Math . random ( ) . toString ( ) ) . current ;
1414 const { appendEvent, removeEvent, setSkippedEventId } = useEvent ( ) ;
1515 const setSkippedEventIdFunc = ( ) => setSkippedEventId ( id ) ;
1616
@@ -20,9 +20,21 @@ export default function OutsidePressHandler(props: IOutsidePressHandlerProps) {
2020 return ( ) => removeEvent ( id ) ;
2121 } , [ onOutsidePress ] ) ;
2222
23- return (
24- < Pressable onPress = { setSkippedEventIdFunc } >
25- { deepClone ( children , setSkippedEventIdFunc ) }
26- </ Pressable >
27- ) ;
23+ return Platform . select ( {
24+ web : (
25+ < View
26+ { ...props }
27+ /*
28+ // @ts -ignore */
29+ onClick = { setSkippedEventIdFunc }
30+ >
31+ { deepClone ( children , setSkippedEventIdFunc ) }
32+ </ View >
33+ ) ,
34+ default : (
35+ < View { ...props } onTouchStart = { setSkippedEventIdFunc } >
36+ { children }
37+ </ View >
38+ ) ,
39+ } ) ;
2840}
0 commit comments