Skip to content

Commit

Permalink
Mark HoverEvents as handled when pointer event dispatching is enabled (
Browse files Browse the repository at this point in the history
…facebook#46445)

Summary:
Pull Request resolved: facebook#46445

Similarly to onTouchEvent, we should return true from onHoverEvent to signal to Android that the hover event is "handled" (because we've dispatched the event to JS). This is important to be able to distinguish multiple stacked React roots on top of each other.

Changelog: [Android][Fixed] Hover events were dispatched incorrectly when multiple ReactRoots were layered.

Reviewed By: mdvacca

Differential Revision: D62529586

fbshipit-source-id: d007c44b8ef56989888eb9a993e1428bd0b72a7b
  • Loading branch information
javache authored and facebook-github-bot committed Sep 12, 2024
1 parent c942469 commit 533ef2c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -8279,6 +8279,7 @@ public class com/facebook/react/views/view/ReactViewGroup : android/view/ViewGro
public fun getZIndexMappedChildIndex (I)I
public fun hasOverlappingRendering ()Z
protected fun onAttachedToWindow ()V
public fun onHoverEvent (Landroid/view/MotionEvent;)Z
public fun onInterceptTouchEvent (Landroid/view/MotionEvent;)Z
protected fun onLayout (ZIIII)V
protected fun onMeasure (II)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class JSPointerDispatcher {
private static final int UNSELECTED_VIEW_TAG = -1;
private static final int UNSET_POINTER_ID = -1;
private static final float ONMOVE_EPSILON = 0.1f;
private static final String TAG = "POINTER EVENTS";
private static final String TAG = "PointerEvents";

private Map<Integer, List<ViewTarget>> mLastHitPathByPointerId;
private Map<Integer, float[]> mLastEventCoordinatesByPointerId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.common.annotations.UnstableReactNativeAPI;
import com.facebook.react.common.annotations.VisibleForTesting;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
import com.facebook.react.modules.i18nmanager.I18nUtil;
import com.facebook.react.touch.OnInterceptTouchEventListener;
Expand Down Expand Up @@ -309,6 +310,15 @@ public boolean onTouchEvent(MotionEvent ev) {
return true;
}

@Override
public boolean onHoverEvent(MotionEvent event) {
if (ReactFeatureFlags.dispatchPointerEvents) {
// Match the logic from onTouchEvent if pointer events are enabled
return PointerEvents.canBeTouchTarget(mPointerEvents);
}
return super.onHoverEvent(event);
}

@Override
public boolean dispatchGenericMotionEvent(MotionEvent ev) {
// We do not dispatch the motion event if its children are not supposed to receive it
Expand Down

0 comments on commit 533ef2c

Please sign in to comment.