Skip to content

Commit ae28247

Browse files
committed
SectionList long press
1 parent b2ee903 commit ae28247

5 files changed

Lines changed: 12 additions & 12 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ class GestureHandlerOrchestrator(
392392
/**
393393
* Cancels handlers whose view opted out of surviving a native view taking over the touch stream.
394394
*/
395-
fun cancelHandlersOnNativeTouchGrab() = cancelTrackedHandlers {
396-
it is NativeViewGestureHandler && it.shouldCancelOnNativeTouchGrab()
395+
fun cancelHandlersOnNativeTouchGrab(grabbedMidGesture: Boolean) = cancelTrackedHandlers {
396+
it is NativeViewGestureHandler && it.shouldCancelOnNativeTouchGrab(grabbedMidGesture)
397397
}
398398

399399
/**

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ class NativeViewGestureHandler : GestureHandler() {
241241

242242
override fun wantsToAttachDirectlyToView() = true
243243

244-
fun shouldCancelOnNativeTouchGrab(): Boolean = hook.shouldCancelOnNativeTouchGrab()
244+
fun shouldCancelOnNativeTouchGrab(grabbedMidGesture: Boolean): Boolean =
245+
hook.shouldCancelOnNativeTouchGrab(grabbedMidGesture)
245246

246247
data class HitSlop(
247248
val left: Float = HIT_SLOP_NONE,
@@ -364,10 +365,10 @@ class NativeViewGestureHandler : GestureHandler() {
364365
fun shouldRecognizeSimultaneously(handler: GestureHandler): Boolean? = null
365366

366367
/**
367-
* Called after a native view grabbed the touch lock during a native dispatch pass.
368-
* Return true to cancel the handler.
368+
* Called after a native view grabbed the touch lock; return true to cancel the handler.
369+
* [grabbedMidGesture] distinguishes a real take-over from a defensive DOWN-pass disallow.
369370
*/
370-
fun shouldCancelOnNativeTouchGrab() = false
371+
fun shouldCancelOnNativeTouchGrab(grabbedMidGesture: Boolean) = false
371372

372373
/**
373374
* shouldActivateOnStart and tryIntercept have priority over this method

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,7 @@ class RNGestureHandlerButtonViewManager :
748748
val localLastEventWasInside = lastEventWasInside
749749

750750
if (newState == GestureHandler.STATE_BEGAN) {
751-
// Reset for the new gesture - BEGAN precedes the native dispatch of DOWN, which
752-
// sets the flag.
751+
// Reset for the new gesture - BEGAN precedes the native dispatch of DOWN that sets the flag.
753752
receivedNativeDown = false
754753
dispatchJSEvent(EventType.PressIn, handler)
755754
longPressDetected = false
@@ -830,7 +829,7 @@ class RNGestureHandlerButtonViewManager :
830829
return super.dispatchTouchEvent(event)
831830
}
832831

833-
override fun shouldCancelOnNativeTouchGrab() = !receivedNativeDown
832+
override fun shouldCancelOnNativeTouchGrab(grabbedMidGesture: Boolean) = grabbedMidGesture || !receivedNativeDown
834833

835834
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
836835
if (super.onInterceptTouchEvent(event)) {

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
@@ -131,10 +131,10 @@ class RNGestureHandlerRootHelper(private val context: ReactContext, wrappedView:
131131
* defensive call from a view that lets the event through (e.g. a nested pager). The two can only
132132
* be told apart after the native dispatch completes, so cancellation runs here, not at request time.
133133
*/
134-
fun onNativeDispatchEnd() {
134+
fun onNativeDispatchEnd(event: MotionEvent) {
135135
if (nativeTouchGrabRequested) {
136136
nativeTouchGrabRequested = false
137-
orchestrator?.cancelHandlersOnNativeTouchGrab()
137+
orchestrator?.cancelHandlersOnNativeTouchGrab(event.actionMasked != MotionEvent.ACTION_DOWN)
138138
}
139139
}
140140

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class RNGestureHandlerRootView(context: Context?) : ReactViewGroup(context) {
6363
true
6464
} else {
6565
val handled = super.dispatchTouchEvent(event)
66-
rootHelper?.onNativeDispatchEnd()
66+
rootHelper?.onNativeDispatchEnd(event)
6767
handled
6868
}
6969
}

0 commit comments

Comments
 (0)