Skip to content

Commit cfd25c8

Browse files
authored
Mark responder-driven views as interactive on Android (#57859)
Summary: Changelog: [Internal] Reviewed By: rozele Differential Revision: D115204834 Pull Request resolved: #57859
1 parent 6990b94 commit cfd25c8

22 files changed

Lines changed: 221 additions & 80 deletions

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<a89ede36c4631b7a7709899858a7f9c9>>
7+
* @generated SignedSource<<6b457b1b41a17fa2065720edc82939e3>>
88
*/
99

1010
/**
@@ -258,6 +258,12 @@ public object ReactNativeFeatureFlags {
258258
@JvmStatic
259259
public fun enableImperativeFocus(): Boolean = accessor.enableImperativeFocus()
260260

261+
/**
262+
* Android views that declare a gesture-responder handler (e.g. PanResponder) register a no-op touch listener so they can be recognized as interactable.
263+
*/
264+
@JvmStatic
265+
public fun enableInteractableResponderViews(): Boolean = accessor.enableInteractableResponderViews()
266+
261267
/**
262268
* This is to fix the issue with interop view manager where component descriptor lookup is causing ViewManager to preload.
263269
*/

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<cd3b4f6a7fb4e616d3f56ab8c9eb9658>>
7+
* @generated SignedSource<<0fdae97a0b469d01bad69d0d05c79121>>
88
*/
99

1010
/**
@@ -58,6 +58,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
5858
private var enableImmediateUpdateModeForContentOffsetChangesCache: Boolean? = null
5959
private var enableImperativeEventsCache: Boolean? = null
6060
private var enableImperativeFocusCache: Boolean? = null
61+
private var enableInteractableResponderViewsCache: Boolean? = null
6162
private var enableInteropViewManagerClassLookUpOptimizationIOSCache: Boolean? = null
6263
private var enableIntersectionObserverByDefaultCache: Boolean? = null
6364
private var enableKeyEventsCache: Boolean? = null
@@ -460,6 +461,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
460461
return cached
461462
}
462463

464+
override fun enableInteractableResponderViews(): Boolean {
465+
var cached = enableInteractableResponderViewsCache
466+
if (cached == null) {
467+
cached = ReactNativeFeatureFlagsCxxInterop.enableInteractableResponderViews()
468+
enableInteractableResponderViewsCache = cached
469+
}
470+
return cached
471+
}
472+
463473
override fun enableInteropViewManagerClassLookUpOptimizationIOS(): Boolean {
464474
var cached = enableInteropViewManagerClassLookUpOptimizationIOSCache
465475
if (cached == null) {

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<6d86d4adbc261c9271b5bed72bd12dcf>>
7+
* @generated SignedSource<<e7d0d9416b8e1fa2a9f6246050cc06b0>>
88
*/
99

1010
/**
@@ -104,6 +104,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
104104

105105
@DoNotStrip @JvmStatic public external fun enableImperativeFocus(): Boolean
106106

107+
@DoNotStrip @JvmStatic public external fun enableInteractableResponderViews(): Boolean
108+
107109
@DoNotStrip @JvmStatic public external fun enableInteropViewManagerClassLookUpOptimizationIOS(): Boolean
108110

109111
@DoNotStrip @JvmStatic public external fun enableIntersectionObserverByDefault(): Boolean

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<a6e126a832b5fd1f74aa8f2d02280f2e>>
7+
* @generated SignedSource<<92e293070f5407d0096ab7f3fd208d45>>
88
*/
99

1010
/**
@@ -99,6 +99,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
9999

100100
override fun enableImperativeFocus(): Boolean = false
101101

102+
override fun enableInteractableResponderViews(): Boolean = false
103+
102104
override fun enableInteropViewManagerClassLookUpOptimizationIOS(): Boolean = false
103105

104106
override fun enableIntersectionObserverByDefault(): Boolean = false

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<c305274be2fc6720b6c0eb75e78bd6b0>>
7+
* @generated SignedSource<<17a4a2a29b0480e06ed3e8ed71fd908f>>
88
*/
99

1010
/**
@@ -62,6 +62,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
6262
private var enableImmediateUpdateModeForContentOffsetChangesCache: Boolean? = null
6363
private var enableImperativeEventsCache: Boolean? = null
6464
private var enableImperativeFocusCache: Boolean? = null
65+
private var enableInteractableResponderViewsCache: Boolean? = null
6566
private var enableInteropViewManagerClassLookUpOptimizationIOSCache: Boolean? = null
6667
private var enableIntersectionObserverByDefaultCache: Boolean? = null
6768
private var enableKeyEventsCache: Boolean? = null
@@ -502,6 +503,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
502503
return cached
503504
}
504505

506+
override fun enableInteractableResponderViews(): Boolean {
507+
var cached = enableInteractableResponderViewsCache
508+
if (cached == null) {
509+
cached = currentProvider.enableInteractableResponderViews()
510+
accessedFeatureFlags.add("enableInteractableResponderViews")
511+
enableInteractableResponderViewsCache = cached
512+
}
513+
return cached
514+
}
515+
505516
override fun enableInteropViewManagerClassLookUpOptimizationIOS(): Boolean {
506517
var cached = enableInteropViewManagerClassLookUpOptimizationIOSCache
507518
if (cached == null) {

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<da45e41e9a58711ee3b68a38965938fb>>
7+
* @generated SignedSource<<3c3e22fe0cffa5498750e91ad05df9a8>>
88
*/
99

1010
/**
@@ -99,6 +99,8 @@ public interface ReactNativeFeatureFlagsProvider {
9999

100100
@DoNotStrip public fun enableImperativeFocus(): Boolean
101101

102+
@DoNotStrip public fun enableInteractableResponderViews(): Boolean
103+
102104
@DoNotStrip public fun enableInteropViewManagerClassLookUpOptimizationIOS(): Boolean
103105

104106
@DoNotStrip public fun enableIntersectionObserverByDefault(): Boolean

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.facebook.react.bridge.ReadableType;
3434
import com.facebook.react.common.MapBuilder;
3535
import com.facebook.react.common.ReactConstants;
36+
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
3637
import com.facebook.react.uimanager.ReactAccessibilityDelegate.AccessibilityRole;
3738
import com.facebook.react.uimanager.ReactAccessibilityDelegate.Role;
3839
import com.facebook.react.uimanager.annotations.ReactProp;
@@ -70,6 +71,8 @@ public abstract class BaseViewManager<T extends View, C extends LayoutShadowNode
7071
private static final String STATE_EXPANDED = "expanded";
7172
private static final String STATE_MIXED = "mixed";
7273

74+
private static final View.OnTouchListener NOOP_LISTENER = (v, event) -> false;
75+
7376
public BaseViewManager() {
7477
super(null);
7578
}
@@ -165,6 +168,7 @@ public BaseViewManager(@Nullable ReactApplicationContext reactContext) {
165168
// NOTE: setClickable MUST be called AFTER setOnClickListener because
166169
// the latter has the side effect of setting isClickable=true on some views!
167170
view.setOnClickListener(null);
171+
setInteractable(view, false);
168172
view.setClickable(false);
169173
view.setFocusable(false);
170174
view.setFocusableInTouchMode(false);
@@ -980,7 +984,24 @@ public void setMoveShouldSetResponderCapture(@NonNull T view, boolean value) {
980984

981985
@ReactProp(name = "onStartShouldSetResponder")
982986
public void setStartShouldSetResponder(@NonNull T view, boolean value) {
983-
// no-op, handled by JSResponder
987+
// Touch handled by the JSResponder system, but listener is needed to indicate interactability.
988+
setInteractable(view, value);
989+
}
990+
991+
private static void setInteractable(@NonNull View view, boolean interactable) {
992+
if (!ReactNativeFeatureFlags.enableInteractableResponderViews()) {
993+
return;
994+
}
995+
boolean noopListener = view.getTag(R.id.noop_touch_listener) != null;
996+
if (interactable) {
997+
if (!noopListener) {
998+
view.setOnTouchListener(NOOP_LISTENER);
999+
view.setTag(R.id.noop_touch_listener, Boolean.TRUE);
1000+
}
1001+
} else if (noopListener) {
1002+
view.setOnTouchListener(null);
1003+
view.setTag(R.id.noop_touch_listener, null);
1004+
}
9841005
}
9851006

9861007
@ReactProp(name = "onStartShouldSetResponderCapture")

‎packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<944781e7a547e601f0637869a3a3ec5e>>
7+
* @generated SignedSource<<f9c238d577cf696d9baed365741d3d5a>>
88
*/
99

1010
/**
@@ -267,6 +267,12 @@ class ReactNativeFeatureFlagsJavaProvider
267267
return method(javaProvider_);
268268
}
269269

270+
bool enableInteractableResponderViews() override {
271+
static const auto method =
272+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableInteractableResponderViews");
273+
return method(javaProvider_);
274+
}
275+
270276
bool enableInteropViewManagerClassLookUpOptimizationIOS() override {
271277
static const auto method =
272278
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableInteropViewManagerClassLookUpOptimizationIOS");
@@ -815,6 +821,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enableImperativeFocus(
815821
return ReactNativeFeatureFlags::enableImperativeFocus();
816822
}
817823

824+
bool JReactNativeFeatureFlagsCxxInterop::enableInteractableResponderViews(
825+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
826+
return ReactNativeFeatureFlags::enableInteractableResponderViews();
827+
}
828+
818829
bool JReactNativeFeatureFlagsCxxInterop::enableInteropViewManagerClassLookUpOptimizationIOS(
819830
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
820831
return ReactNativeFeatureFlags::enableInteropViewManagerClassLookUpOptimizationIOS();
@@ -1255,6 +1266,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
12551266
makeNativeMethod(
12561267
"enableImperativeFocus",
12571268
JReactNativeFeatureFlagsCxxInterop::enableImperativeFocus),
1269+
makeNativeMethod(
1270+
"enableInteractableResponderViews",
1271+
JReactNativeFeatureFlagsCxxInterop::enableInteractableResponderViews),
12581272
makeNativeMethod(
12591273
"enableInteropViewManagerClassLookUpOptimizationIOS",
12601274
JReactNativeFeatureFlagsCxxInterop::enableInteropViewManagerClassLookUpOptimizationIOS),

‎packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<ad9275a6afb74520bec7d446faafd1bc>>
7+
* @generated SignedSource<<8d25ec35055628073cf8cd61f8cc838e>>
88
*/
99

1010
/**
@@ -144,6 +144,9 @@ class JReactNativeFeatureFlagsCxxInterop
144144
static bool enableImperativeFocus(
145145
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
146146

147+
static bool enableInteractableResponderViews(
148+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
149+
147150
static bool enableInteropViewManagerClassLookUpOptimizationIOS(
148151
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
149152

‎packages/react-native/ReactAndroid/src/main/res/views/uimanager/values/ids.xml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,7 @@
8888

8989
<!-- tag is used to store the safe area insets observer attached to the view -->
9090
<item type="id" name="safe_area_insets_observer"/>
91+
92+
<!-- tag marks that BaseViewManager installed the no-op touch listener -->
93+
<item type="id" name="noop_touch_listener"/>
9194
</resources>

0 commit comments

Comments
 (0)