Skip to content

Commit 36f07a1

Browse files
fabriziocuccimeta-codesync[bot]
authored andcommitted
Fix importantForInteraction mapping for AUTO and BOX_ONLY pointer events (#55336)
Summary: Pull Request resolved: #55336 Changelog: [Internal] The previous mapping was conceptually incorrect: - `pointerEvents=auto -> importantForInteraction=yes` was wrong because a view with `pointerEvents=auto` that is not clickable shouldn't have `importantForInteraction=yes` - `pointerEvents=box-only -> importantForInteraction=yes | excludeDescendants` was also wrong for the same reason - the view itself being important for interaction depends on whether it's clickable, not just on pointer events The fix: - For `AUTO`: Skip setting the tag entirely and let the view's own state (e.g., isClickable) determine whether it's important for interaction - For `BOX_ONLY`: Only set `excludeDescendants` to indicate descendants are not important, but let the view's own state determine if the view itself is important for interaction This ensures that views are only marked as important for interaction when they are actually interactive (clickable), rather than incorrectly assuming importance based solely on pointer events. Reviewed By: twasilczyk, tomscallon Differential Revision: D91606360 fbshipit-source-id: a2eb2272c44cf44379011294a3f18fdb93bf7425
1 parent 0cde8ed commit 36f07a1

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ImportantForInteractionHelper.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,17 @@ internal object ImportantForInteractionHelper {
3434
/**
3535
* Sets the important_for_interaction tag on a view based on the given [PointerEvents] value.
3636
*
37+
* Note: The pointer events value alone does not determine if a view is important for interaction.
38+
* A view with pointerEvents=auto or pointerEvents=box-only is only important for interaction if
39+
* it is also clickable. Therefore, for these cases we let the view's own state determine whether
40+
* it's important for interaction rather than setting the tag.
41+
*
3742
* The mapping is as follows:
38-
* - [PointerEvents.AUTO] -> [IMPORTANT_FOR_INTERACTION_YES]
43+
* - [PointerEvents.AUTO] -> No tag set (i.e. the view's own state determines importance)
3944
* - [PointerEvents.NONE] -> [IMPORTANT_FOR_INTERACTION_NO] |
4045
* [IMPORTANT_FOR_INTERACTION_EXCLUDE_DESCENDANTS]
41-
* - [PointerEvents.BOX_ONLY] -> [IMPORTANT_FOR_INTERACTION_YES] |
42-
* [IMPORTANT_FOR_INTERACTION_EXCLUDE_DESCENDANTS]
46+
* - [PointerEvents.BOX_ONLY] -> [IMPORTANT_FOR_INTERACTION_EXCLUDE_DESCENDANTS] (i.e. the view's
47+
* own state determines importance but its descendants are excluded)
4348
* - [PointerEvents.BOX_NONE] -> [IMPORTANT_FOR_INTERACTION_NO]
4449
*
4550
* @param view The view to set the tag on
@@ -49,11 +54,10 @@ internal object ImportantForInteractionHelper {
4954
fun setImportantForInteraction(view: View, pointerEvents: PointerEvents) {
5055
val value =
5156
when (pointerEvents) {
52-
PointerEvents.AUTO -> IMPORTANT_FOR_INTERACTION_YES
57+
PointerEvents.AUTO -> return
5358
PointerEvents.NONE ->
5459
IMPORTANT_FOR_INTERACTION_NO or IMPORTANT_FOR_INTERACTION_EXCLUDE_DESCENDANTS
55-
PointerEvents.BOX_ONLY ->
56-
IMPORTANT_FOR_INTERACTION_YES or IMPORTANT_FOR_INTERACTION_EXCLUDE_DESCENDANTS
60+
PointerEvents.BOX_ONLY -> IMPORTANT_FOR_INTERACTION_EXCLUDE_DESCENDANTS
5761
PointerEvents.BOX_NONE -> IMPORTANT_FOR_INTERACTION_NO
5862
}
5963
view.setTag(R.id.important_for_interaction, value)

0 commit comments

Comments
 (0)