Skip to content
Open
Changes from 2 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 @@ -305,6 +305,66 @@ public open class ReactViewGroup public constructor(context: Context?) :
return false
}

// For accessibility services (TalkBack), check if hover is within any child's hitSlop area.
// Only apply this logic when accessibility services are enabled to avoid interfering with
// other input methods (VR, mouse, stylus, etc.)
val accessibilityManager = context.getSystemService(Context.ACCESSIBILITY_SERVICE) as? AccessibilityManager
if (accessibilityManager?.isTouchExplorationEnabled == true &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still pretty expensive to do on a per-input basis (I think it needs to a Binder call)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah that makes sense. I've added some internal state to ReactViewGroup and a TouchExplorationStateChangeListener to manage it.

ev.isFromSource(android.view.InputDevice.SOURCE_CLASS_POINTER) &&
(ev.action == MotionEvent.ACTION_HOVER_ENTER || ev.action == MotionEvent.ACTION_HOVER_MOVE)) {
val x = ev.x
val y = ev.y

// Check each child in reverse order (front-to-back, matching touch behavior)
for (i in childCount - 1 downTo 0) {
val child = getChildAt(i)
if (child == null || child.visibility != VISIBLE) {
continue
}

// Check if child has hitSlop
if (child is ReactHitSlopView) {
val hitSlopRect = child.hitSlopRect
if (hitSlopRect != null) {
// Calculate child-relative coordinates
val childX = x - child.left
val childY = y - child.top

// Check if within hitSlop-extended bounds
if (childX >= -hitSlopRect.left &&
childX < child.width + hitSlopRect.right &&
childY >= -hitSlopRect.top &&
childY < child.height + hitSlopRect.bottom) {

// Only intercept if OUTSIDE normal bounds but WITHIN hitSlop
// This prevents interfering with normal child event handling
val inNormalBounds = childX >= 0 && childX < child.width &&
childY >= 0 && childY < child.height

if (!inNormalBounds) {
// For TalkBack accessibility, request focus on the child
if (ev.action == MotionEvent.ACTION_HOVER_ENTER) {
child.performAccessibilityAction(
android.view.accessibility.AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS,
null
)
return true
}
// Transform event coordinates to child's coordinate system
ev.offsetLocation(-child.left.toFloat(), -child.top.toFloat())
val handled = child.dispatchGenericMotionEvent(ev)
// Restore original coordinates
ev.offsetLocation(child.left.toFloat(), child.top.toFloat())
if (handled) {
return true
}
}
}
}
}
}
}

return super.dispatchGenericMotionEvent(ev)
}

Expand Down