11import React , { useCallback , useRef } from 'react' ;
22import { Platform } from 'react-native' ;
33
4- import type { ButtonProps } from '../../../components/GestureHandlerButton' ;
54import GestureHandlerButton from '../../../components/GestureHandlerButton' ;
6- import createNativeWrapper from '../../createNativeWrapper' ;
5+ import { NativeDetector } from '../../detectors/NativeDetector' ;
6+ import { useNativeGesture } from '../../hooks' ;
77import type {
88 CallbackEventType ,
99 EndCallbackEventType ,
1010 TouchableProps ,
1111} from './TouchableProps' ;
1212
13- const TouchableButton = createNativeWrapper <
14- React . ComponentRef < typeof GestureHandlerButton > ,
15- ButtonProps
16- > ( GestureHandlerButton , {
17- shouldCancelWhenOutside : true ,
18- shouldActivateOnStart : false ,
19- disallowInterruption : true ,
20- } ) ;
21-
2213const isAndroid = Platform . OS === 'android' ;
2314const TRANSPARENT_RIPPLE = { rippleColor : 'transparent' as const } ;
2415
@@ -135,6 +126,20 @@ export const Touchable = (props: TouchableProps) => {
135126 [ onPressIn , onPressOut ]
136127 ) ;
137128
129+ const nativeGesture = useNativeGesture ( {
130+ onBegin,
131+ onActivate,
132+ onFinalize,
133+ onUpdate,
134+ hitSlop : props . hitSlop ,
135+ testID : props . testID ,
136+ enabled : ! disabled ,
137+ shouldCancelWhenOutside : cancelOnLeave ,
138+ disableReanimated : true ,
139+ shouldActivateOnStart : false ,
140+ disallowInterruption : true ,
141+ } ) ;
142+
138143 const rippleProps = shouldUseNativeRipple
139144 ? {
140145 rippleColor : androidRipple ?. color ,
@@ -145,20 +150,17 @@ export const Touchable = (props: TouchableProps) => {
145150 : TRANSPARENT_RIPPLE ;
146151
147152 return (
148- < TouchableButton
149- { ...rest }
150- { ...rippleProps }
151- ref = { ref ?? null }
152- enabled = { ! disabled }
153- onBegin = { onBegin }
154- onActivate = { onActivate }
155- onFinalize = { onFinalize }
156- onUpdate = { onUpdate }
157- defaultOpacity = { defaultOpacity }
158- defaultUnderlayOpacity = { defaultUnderlayOpacity }
159- underlayColor = { underlayColor }
160- shouldCancelWhenOutside = { cancelOnLeave } >
161- { children }
162- </ TouchableButton >
153+ < NativeDetector gesture = { nativeGesture } >
154+ < GestureHandlerButton
155+ { ...rest }
156+ { ...rippleProps }
157+ ref = { ref ?? null }
158+ enabled = { ! disabled }
159+ defaultOpacity = { defaultOpacity }
160+ defaultUnderlayOpacity = { defaultUnderlayOpacity }
161+ underlayColor = { underlayColor } >
162+ { children }
163+ </ GestureHandlerButton >
164+ </ NativeDetector >
163165 ) ;
164166} ;
0 commit comments