Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.swmansion.gesturehandler.BuildConfig
import com.swmansion.gesturehandler.RNSVGHitTester
import com.swmansion.gesturehandler.react.RNGestureHandlerTouchEvent
import com.swmansion.gesturehandler.react.eventbuilders.GestureHandlerEventDataBuilder
import com.swmansion.gesturehandler.react.isHoverAction
import java.lang.IllegalStateException
import java.util.*

Expand Down Expand Up @@ -385,10 +386,7 @@ open class GestureHandler {
setPointerType(sourceEvent)
}

if (sourceEvent.action == MotionEvent.ACTION_HOVER_ENTER ||
sourceEvent.action == MotionEvent.ACTION_HOVER_MOVE ||
sourceEvent.action == MotionEvent.ACTION_HOVER_EXIT
) {
if (sourceEvent.isHoverAction()) {
onHandleHover(adaptedTransformedEvent, adaptedSourceEvent)
} else {
onHandle(adaptedTransformedEvent, adaptedSourceEvent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.widget.EditText
import com.facebook.react.uimanager.RootView
import com.swmansion.gesturehandler.react.RNGestureHandlerRootHelper
import com.swmansion.gesturehandler.react.RNGestureHandlerRootView
import com.swmansion.gesturehandler.react.isHoverAction
import java.util.*

class GestureHandlerOrchestrator(
Expand Down Expand Up @@ -517,18 +518,12 @@ class GestureHandlerOrchestrator(
// There's only one exception - RootViewGestureHandler. TalkBack uses hover events,
// so we need to pass them into RootViewGestureHandler, otherwise press and hold
// gesture stops working correctly (see https://github.com/software-mansion/react-native-gesture-handler/issues/3407)
private fun shouldHandlerSkipHoverEvents(handler: GestureHandler, action: Int): Boolean {
private fun shouldHandlerSkipHoverEvents(handler: GestureHandler, event: MotionEvent): Boolean {
val shouldSkipHoverEvents =
handler !is HoverGestureHandler &&
handler !is RNGestureHandlerRootHelper.RootViewGestureHandler

return shouldSkipHoverEvents &&
action in
listOf(
MotionEvent.ACTION_HOVER_EXIT,
MotionEvent.ACTION_HOVER_ENTER,
MotionEvent.ACTION_HOVER_MOVE,
)
return shouldSkipHoverEvents && event.isHoverAction()
}

private fun recordViewHandlersForPointer(
Expand All @@ -546,7 +541,7 @@ class GestureHandlerOrchestrator(
continue
}

if (shouldHandlerSkipHoverEvents(handler, event.action)) {
if (shouldHandlerSkipHoverEvents(handler, event)) {
continue
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.swmansion.gesturehandler.react

import android.content.Context
import android.view.MotionEvent
import android.view.accessibility.AccessibilityManager
import com.facebook.react.bridge.ReactContext
import com.facebook.react.modules.core.DeviceEventManagerModule
Expand All @@ -14,3 +15,7 @@ val ReactContext.UIManager: UIManagerModule

fun Context.isScreenReaderOn() =
(getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager).isTouchExplorationEnabled

fun MotionEvent.isHoverAction(): Boolean = action == MotionEvent.ACTION_HOVER_MOVE ||
action == MotionEvent.ACTION_HOVER_ENTER ||
action == MotionEvent.ACTION_HOVER_EXIT
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class RNGestureHandlerRootView(context: Context?) : ReactViewGroup(context) {
}

override fun dispatchGenericMotionEvent(ev: MotionEvent) =
if (rootViewEnabled && rootHelper!!.dispatchTouchEvent(ev)) {
if (rootViewEnabled && ev.isHoverAction() && rootHelper!!.dispatchTouchEvent(ev)) {
true
} else {
super.dispatchGenericMotionEvent(ev)
Expand Down