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,18 @@ export const Touchable = (props: TouchableProps) => {
135126 [ onPressIn , onPressOut ]
136127 ) ;
137128
129+ const nativeGesture = useNativeGesture ( {
130+ onBegin,
131+ onActivate,
132+ onFinalize,
133+ onUpdate,
134+ enabled : ! disabled ,
135+ shouldCancelWhenOutside : cancelOnLeave ,
136+ disableReanimated : true ,
137+ shouldActivateOnStart : false ,
138+ disallowInterruption : true ,
139+ } ) ;
140+
138141 const rippleProps = shouldUseNativeRipple
139142 ? {
140143 rippleColor : androidRipple ?. color ,
@@ -145,20 +148,17 @@ export const Touchable = (props: TouchableProps) => {
145148 : TRANSPARENT_RIPPLE ;
146149
147150 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 >
151+ < NativeDetector gesture = { nativeGesture } >
152+ < GestureHandlerButton
153+ { ...rest }
154+ { ...rippleProps }
155+ ref = { ref ?? null }
156+ enabled = { ! disabled }
157+ defaultOpacity = { defaultOpacity }
158+ defaultUnderlayOpacity = { defaultUnderlayOpacity }
159+ underlayColor = { underlayColor } >
160+ { children }
161+ </ GestureHandlerButton >
162+ </ NativeDetector >
163163 ) ;
164164} ;
0 commit comments