@@ -11,7 +11,7 @@ import Reanimated, {
11
11
} from 'react-native-reanimated' ;
12
12
import { TapGestureHandler , LongPressGestureHandler , State } from 'react-native-gesture-handler' ;
13
13
import { asBaseComponent , forwardRef , BaseComponentInjectedProps , ForwardRefInjectedProps } from '../commons/new' ;
14
- import { ViewProps } from '../components/view' ;
14
+ import View , { ViewProps } from '../components/view' ;
15
15
16
16
export type TouchableOpacityProps = {
17
17
/**
@@ -107,23 +107,24 @@ function TouchableOpacity(props: Props) {
107
107
} ,
108
108
onEnd : ( ) => {
109
109
toggleActive ( 0 ) ;
110
-
111
110
runOnJS ( onPress ) ( ) ;
112
111
} ,
113
112
onFail : ( ) => {
114
- toggleActive ( 0 ) ;
113
+ if ( ! isLongPressed . value ) {
114
+ toggleActive ( 0 ) ;
115
+ }
115
116
}
116
117
} ) ;
117
118
118
119
const longPressGestureHandler = useAnimatedGestureHandler ( {
119
120
onActive : ( ) => {
120
121
if ( ! isLongPressed . value ) {
121
122
isLongPressed . value = true ;
122
- toggleActive ( 0 ) ;
123
123
runOnJS ( onLongPress ) ( ) ;
124
124
}
125
125
} ,
126
126
onFinish : ( ) => {
127
+ toggleActive ( 0 ) ;
127
128
isLongPressed . value = false ;
128
129
}
129
130
} ) ;
@@ -140,6 +141,8 @@ function TouchableOpacity(props: Props) {
140
141
} ;
141
142
} , [ backgroundColor , feedbackColor ] ) ;
142
143
144
+ const Container = props . onLongPress ? LongPressGestureHandler : View ;
145
+
143
146
return (
144
147
< TapGestureHandler
145
148
// @ts -expect-error
@@ -149,7 +152,7 @@ function TouchableOpacity(props: Props) {
149
152
>
150
153
< Reanimated . View >
151
154
{ /* @ts -expect-error */ }
152
- < LongPressGestureHandler onGestureEvent = { longPressGestureHandler } shouldCancelWhenOutside >
155
+ < Container onGestureEvent = { longPressGestureHandler } shouldCancelWhenOutside >
153
156
< Reanimated . View
154
157
{ ...others }
155
158
ref = { forwardedRef }
@@ -166,7 +169,7 @@ function TouchableOpacity(props: Props) {
166
169
>
167
170
{ children }
168
171
</ Reanimated . View >
169
- </ LongPressGestureHandler >
172
+ </ Container >
170
173
</ Reanimated . View >
171
174
</ TapGestureHandler >
172
175
) ;
0 commit comments