Skip to content

Commit fd57422

Browse files
committed
rename to cancelsJsResponder
1 parent ca4c6d3 commit fd57422

11 files changed

Lines changed: 42 additions & 42 deletions

File tree

apps/common-app/src/new_api/tests/rnResponderCancellation/index.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function SingleHandlerExample() {
5353
const feedbackRef = useRef<FeedbackHandle>(null);
5454
const sequenceRef = useRef(0);
5555
const [events, setEvents] = useState<string[]>([]);
56-
const [preventRecognizers, setPreventRecognizers] = useState(true);
56+
const [cancelsJSResponder, setCancelsJSResponder] = useState(true);
5757

5858
const pushEvent = useCallback((label: string) => {
5959
sequenceRef.current += 1;
@@ -67,7 +67,7 @@ function SingleHandlerExample() {
6767
const panGesture = usePanGesture({
6868
minDistance: 12,
6969
runOnJS: true,
70-
preventRecognizers,
70+
cancelsJSResponder,
7171
onActivate: () => {
7272
pushEvent('GH pan ACTIVE');
7373
},
@@ -80,13 +80,13 @@ function SingleHandlerExample() {
8080
<View style={singleStyles.container}>
8181
<Text style={commonStyles.header}>RN responder cancellation</Text>
8282
<Text style={commonStyles.instructions}>
83-
Toggle preventRecognizers and drag inside the box to compare behavior.
83+
Toggle cancelsJSResponder and drag inside the box to compare behavior.
8484
</Text>
8585
<View style={singleStyles.settingsRow}>
86-
<Text style={singleStyles.settingsLabel}>preventRecognizers</Text>
86+
<Text style={singleStyles.settingsLabel}>cancelsJSResponder</Text>
8787
<Switch
88-
value={preventRecognizers}
89-
onValueChange={setPreventRecognizers}
88+
value={cancelsJSResponder}
89+
onValueChange={setCancelsJSResponder}
9090
/>
9191
</View>
9292

@@ -199,9 +199,9 @@ const singleStyles = StyleSheet.create({
199199

200200
// ---------- Multi handler ---------------------------------------------------
201201
// Validates that when two Gesture Handler recognizers are active at the same
202-
// time, both with preventRecognizers set to true, finishing ONE of them does
202+
// time, both with cancelsJSResponder set to true, finishing ONE of them does
203203
// NOT unblock React Native JS responders — the block must stay in place until
204-
// the LAST preventing recognizer finishes.
204+
// the LAST cancelling recognizer finishes.
205205
//
206206
// Expected interaction to reproduce:
207207
// 1. Finger 1: drag inside "Pan A" → GH_A ACTIVE (RN blocked)
@@ -221,7 +221,7 @@ function MultiHandlerExample() {
221221
const feedbackRef = useRef<FeedbackHandle>(null);
222222
const sequenceRef = useRef(0);
223223
const [events, setEvents] = useState<string[]>([]);
224-
const [preventRecognizers, setPreventRecognizers] = useState(true);
224+
const [cancelsJSResponder, setCancelsJSResponder] = useState(true);
225225

226226
const pushEvent = useCallback((label: string) => {
227227
sequenceRef.current += 1;
@@ -235,7 +235,7 @@ function MultiHandlerExample() {
235235
const panA = usePanGesture({
236236
minDistance: 8,
237237
runOnJS: true,
238-
preventRecognizers,
238+
cancelsJSResponder,
239239
onActivate: () => pushEvent('GH_A ACTIVE'),
240240
onFinalize: (_e, success) =>
241241
pushEvent(`GH_A finalize (${success ? 'success' : 'cancel/fail'})`),
@@ -244,7 +244,7 @@ function MultiHandlerExample() {
244244
const panB = usePanGesture({
245245
minDistance: 8,
246246
runOnJS: true,
247-
// preventRecognizers,
247+
cancelsJSResponder,
248248
onActivate: () => pushEvent('GH_B ACTIVE'),
249249
onFinalize: (_e, success) =>
250250
pushEvent(`GH_B finalize (${success ? 'success' : 'cancel/fail'})`),
@@ -257,17 +257,17 @@ function MultiHandlerExample() {
257257

258258
return (
259259
<View style={multiStyles.container}>
260-
<Text style={commonStyles.header}>preventRecognizers — multi</Text>
260+
<Text style={commonStyles.header}>cancelsJSResponder — multi</Text>
261261
<Text style={commonStyles.instructions}>
262262
Drag A and B with two fingers simultaneously, then tap the RN zone with
263263
a third finger. Release one finger at a time and re-tap.
264264
</Text>
265265

266266
<View style={multiStyles.settingsRow}>
267-
<Text style={multiStyles.settingsLabel}>preventRecognizers</Text>
267+
<Text style={multiStyles.settingsLabel}>cancelsJSResponder</Text>
268268
<Switch
269-
value={preventRecognizers}
270-
onValueChange={setPreventRecognizers}
269+
value={cancelsJSResponder}
270+
onValueChange={setCancelsJSResponder}
271271
/>
272272
<Text onPress={clearLog} style={multiStyles.clearButton}>
273273
clear

packages/docs-gesture-handler/docs/gestures/_shared/base-gesture-config.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,16 @@ activeCursor: ActiveCursor | SharedValue<ActiveCursor>;
150150
This parameter allows specifying which cursor should be used when the gesture activates. Supports all [CSS cursor values](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/cursor#keyword) (e.g. `"grab"`, `"zoom-in"`). Default value is set to `"auto"`.
151151

152152
<HeaderWithBadges platforms={['ios', 'android']}>
153-
### preventRecognizers
153+
### cancelsJSResponder
154154
</HeaderWithBadges>
155155

156156
```ts
157-
preventRecognizers?: boolean;
157+
cancelsJSResponder?: boolean;
158158
```
159159

160160
Controls whether activating a Gesture Handler recognizer should cancel React Native JS responders.
161161

162-
This option is configured per gesture handler (for example in `usePanGesture({ preventRecognizers: ... })`).
162+
This option is configured per gesture handler (for example in `usePanGesture({ cancelsJSResponder: ... })`).
163163

164164
- `true` (default): when this gesture activates, it cancels React Native JS responders in the same root view.
165165
- `false`: disables that cancellation, so Gesture Handler callbacks and RN responder callbacks can run at the same time.

packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ open class GestureHandler {
8383
var needsPointerData = false
8484
var dispatchesAnimatedEvents = false
8585
var dispatchesReanimatedEvents = false
86-
var preventRecognizers = true
86+
var cancelsJSResponder = true
8787

8888
private var hitSlop: FloatArray? = null
8989
var eventCoalescingKey: Short = 0
@@ -138,7 +138,7 @@ open class GestureHandler {
138138
mouseButton = DEFAULT_MOUSE_BUTTON
139139
dispatchesAnimatedEvents = DEFAULT_DISPATCHES_ANIMATED_EVENTS
140140
dispatchesReanimatedEvents = DEFAULT_DISPATCHES_REANIMATED_EVENTS
141-
preventRecognizers = DEFAULT_PREVENT_RECOGNIZERS
141+
cancelsJSResponder = DEFAULT_CANCELS_JS_RESPONDER
142142
}
143143

144144
fun hasCommonPointers(other: GestureHandler): Boolean {
@@ -963,8 +963,8 @@ open class GestureHandler {
963963
if (config.hasKey(KEY_TEST_ID)) {
964964
handler.testID = config.getString(KEY_TEST_ID)
965965
}
966-
if (config.hasKey(KEY_PREVENT_RECOGNIZERS)) {
967-
handler.preventRecognizers = config.getBoolean(KEY_PREVENT_RECOGNIZERS)
966+
if (config.hasKey(KEY_CANCELS_JS_RESPONDER)) {
967+
handler.cancelsJSResponder = config.getBoolean(KEY_CANCELS_JS_RESPONDER)
968968
}
969969
}
970970

@@ -988,7 +988,7 @@ open class GestureHandler {
988988
private const val KEY_HIT_SLOP_WIDTH = "width"
989989
private const val KEY_HIT_SLOP_HEIGHT = "height"
990990
private const val KEY_TEST_ID = "testID"
991-
private const val KEY_PREVENT_RECOGNIZERS = "preventRecognizers"
991+
private const val KEY_CANCELS_JS_RESPONDER = "cancelsJSResponder"
992992

993993
private fun handleHitSlopProperty(handler: GestureHandler, config: ReadableMap) {
994994
if (config.getType(KEY_HIT_SLOP) == ReadableType.Number) {
@@ -1052,7 +1052,7 @@ open class GestureHandler {
10521052
private const val DEFAULT_MOUSE_BUTTON = 0
10531053
private const val DEFAULT_DISPATCHES_ANIMATED_EVENTS = false
10541054
private const val DEFAULT_DISPATCHES_REANIMATED_EVENTS = false
1055-
private const val DEFAULT_PREVENT_RECOGNIZERS = true
1055+
private const val DEFAULT_CANCELS_JS_RESPONDER = true
10561056

10571057
const val STATE_UNDETERMINED = 0
10581058
const val STATE_FAILED = 1

packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class GestureHandlerOrchestrator(
4242
private var finishedHandlersCleanupScheduled = false
4343
private var activationIndex = 0
4444

45-
var onPreventRecognizersRequested: ((GestureHandler) -> Unit)? = null
46-
var onPreventRecognizersReleased: ((GestureHandler) -> Unit)? = null
45+
var onCancelJSResponderRequested: ((GestureHandler) -> Unit)? = null
46+
var onCancelJSResponderReleased: ((GestureHandler) -> Unit)? = null
4747

4848
/**
4949
* Should be called from the view wrapper
@@ -147,10 +147,10 @@ class GestureHandlerOrchestrator(
147147
fun onHandlerStateChange(handler: GestureHandler, newState: Int, prevState: Int) {
148148
handlingChangeSemaphore += 1
149149

150-
if (isFinished(newState) && handler.isActive && handler.preventRecognizers) {
151-
// Check if there are any other active handlers that are preventing recognizers.
152-
if (gestureHandlers.none { it !== handler && it.isActive && it.preventRecognizers }) {
153-
onPreventRecognizersReleased?.invoke(handler)
150+
if (isFinished(newState) && handler.isActive && handler.cancelsJSResponder) {
151+
// Check if there are any other active handlers that still request the JS responder to be cancelled.
152+
if (gestureHandlers.none { it !== handler && it.isActive && it.cancelsJSResponder }) {
153+
onCancelJSResponderReleased?.invoke(handler)
154154
}
155155
}
156156

@@ -252,8 +252,8 @@ class GestureHandlerOrchestrator(
252252
return
253253
}
254254

255-
if (handler.preventRecognizers) {
256-
onPreventRecognizersRequested?.invoke(handler)
255+
if (handler.cancelsJSResponder) {
256+
onCancelJSResponderRequested?.invoke(handler)
257257
}
258258

259259
handler.dispatchStateChange(GestureHandler.STATE_ACTIVE, GestureHandler.STATE_BEGAN)

packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class RNGestureHandlerRootHelper(private val context: ReactContext, wrappedView:
4141
rootView,
4242
).apply {
4343
minimumAlphaForTraversal = MIN_ALPHA_FOR_TOUCH
44-
onPreventRecognizersRequested = { _ ->
44+
onCancelJSResponderRequested = { _ ->
4545
shouldIntercept = true
4646
val time = SystemClock.uptimeMillis()
4747
val event = MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0f, 0f, 0)
@@ -50,7 +50,7 @@ class RNGestureHandlerRootHelper(private val context: ReactContext, wrappedView:
5050
}
5151
event.recycle()
5252
}
53-
onPreventRecognizersReleased = { _ ->
53+
onCancelJSResponderReleased = { _ ->
5454
shouldIntercept = false
5555
}
5656
}

packages/react-native-gesture-handler/apple/RNGestureHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
@property (nonatomic) BOOL shouldCancelWhenOutside;
8282
@property (nonatomic) BOOL needsPointerData;
8383
@property (nonatomic) BOOL manualActivation;
84-
@property (nonatomic) BOOL preventRecognizers;
84+
@property (nonatomic) BOOL cancelsJSResponder;
8585
@property (nonatomic) BOOL dispatchesAnimatedEvents;
8686
@property (nonatomic) BOOL dispatchesReanimatedEvents;
8787
@property (nonatomic, weak, nullable) RNGHUIView *hostDetectorView;

packages/react-native-gesture-handler/apple/RNGestureHandler.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ - (void)resetConfig
105105
self.testID = nil;
106106
self.manualActivation = NO;
107107
_shouldCancelWhenOutside = NO;
108-
_preventRecognizers = YES;
108+
_cancelsJSResponder = YES;
109109
_hitSlop = RNGHHitSlopEmpty;
110110
_needsPointerData = NO;
111111
_dispatchesAnimatedEvents = NO;
@@ -165,9 +165,9 @@ - (void)updateConfig:(NSDictionary *)config
165165
self.manualActivation = [RCTConvert BOOL:prop];
166166
}
167167

168-
prop = config[@"preventRecognizers"];
168+
prop = config[@"cancelsJSResponder"];
169169
if (prop != nil) {
170-
_preventRecognizers = [RCTConvert BOOL:prop];
170+
_cancelsJSResponder = [RCTConvert BOOL:prop];
171171
}
172172

173173
prop = config[@"hitSlop"];

packages/react-native-gesture-handler/apple/RNRootViewGestureRecognizer.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ - (BOOL)canBePreventedByGestureRecognizer:(UIGestureRecognizer *)preventingGestu
5656
// to send an info to JS so that it cancels all JS responders, as long as the preventing
5757
// recognizer is from Gesture Handler, otherwise we might break some interactions
5858
RNGestureHandler *handler = [RNGestureHandler findGestureHandlerByRecognizer:preventingGestureRecognizer];
59-
if (handler != nil && handler.preventRecognizers) {
59+
if (handler != nil && handler.cancelsJSResponder) {
6060
[self.delegate gestureRecognizer:preventingGestureRecognizer didActivateInViewWithTouchHandler:self.view];
6161
}
6262

packages/react-native-gesture-handler/src/handlers/gestures/GestureDetector/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626

2727
export const ALLOWED_PROPS = [
2828
...baseGestureHandlerWithDetectorProps,
29-
'preventRecognizers',
29+
'cancelsJSResponder',
3030
...tapGestureHandlerProps,
3131
...panGestureHandlerProps,
3232
...panGestureHandlerCustomNativeProps,

packages/react-native-gesture-handler/src/v3/hooks/utils/propsWhiteList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const CommonConfig = new Set<keyof CommonGestureConfig>([
2323
'mouseButton',
2424
'testID',
2525
'cancelsTouchesInView',
26-
'preventRecognizers',
26+
'cancelsJSResponder',
2727
'manualActivation',
2828
]);
2929

0 commit comments

Comments
 (0)