Skip to content

Commit

Permalink
Introduce the enableEventEmitterRetentionDuringGesturesOnAndroid to g…
Browse files Browse the repository at this point in the history
…ate the Pressable fix (facebook#45930)

Summary:
Pull Request resolved: facebook#45930

This introduces the `enableEventEmitterRetentionDuringGesturesOnAndroid` that allows us to gate the
fix for bug facebook#45126 and facebook#44610.

Changelog:
[Internal] [Changed] - Introduce the enableEventEmitterRetentionDuringGesturesOnAndroid to gate the Pressable fix

Differential Revision: D60908117
  • Loading branch information
cortinico authored and facebook-github-bot committed Aug 7, 2024
1 parent 34ffccb commit 81f1683
Show file tree
Hide file tree
Showing 22 changed files with 174 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public object DefaultNewArchitectureEntryPoint {
override fun useFabricInterop(): Boolean = fabricEnabled

override fun useTurboModuleInterop(): Boolean = bridgelessEnabled

// We turn this feature flag to true for OSS to fix #44610 and #45126 and other
// similar bugs related to pressable.
override fun enableEventEmitterRetentionDuringGesturesOnAndroid(): Boolean =
fabricEnabled
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,8 @@ public void deleteView(int reactTag) {
return;
}

if (mViewsWithActiveTouches.contains(reactTag)) {
if (ReactNativeFeatureFlags.enableEventEmitterRetentionDuringGesturesOnAndroid()
&& mViewsWithActiveTouches.contains(reactTag)) {
// If the view that went offscreen is still being touched, we can't delete it yet.
// We have to delay the deletion till the touch is completed.
// This is causing bugs like those otherwise:
Expand Down Expand Up @@ -1181,10 +1182,16 @@ public void run() {
}

public void markActiveTouchForTag(int reactTag) {
if (!ReactNativeFeatureFlags.enableEventEmitterRetentionDuringGesturesOnAndroid()) {
return;
}
mViewsWithActiveTouches.add(reactTag);
}

public void sweepActiveTouchForTag(int reactTag) {
if (!ReactNativeFeatureFlags.enableEventEmitterRetentionDuringGesturesOnAndroid()) {
return;
}
mViewsWithActiveTouches.remove(reactTag);
if (mViewsToDeleteAfterTouchFinishes.contains(reactTag)) {
mViewsToDeleteAfterTouchFinishes.remove(reactTag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<11bd299e21bf2eb1c320e657885826e4>>
* @generated SignedSource<<275859c437f60e7733da2b238c911152>>
*/

/**
Expand Down Expand Up @@ -88,6 +88,12 @@ public object ReactNativeFeatureFlags {
@JvmStatic
public fun enableEagerRootViewAttachment(): Boolean = accessor.enableEagerRootViewAttachment()

/**
* Enables the retention of EventEmitterWrapper on Android till the touch gesture is over to fix a bug on pressable (#44610)
*/
@JvmStatic
public fun enableEventEmitterRetentionDuringGesturesOnAndroid(): Boolean = accessor.enableEventEmitterRetentionDuringGesturesOnAndroid()

/**
* This feature flag enables logs for Fabric.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<c646b32a6639fdb0e794f3a2b6e01171>>
* @generated SignedSource<<e58ecac6e67cd870b8ac077cbdfd7469>>
*/

/**
Expand All @@ -30,6 +30,7 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
private var enableBackgroundStyleApplicatorCache: Boolean? = null
private var enableCleanTextInputYogaNodeCache: Boolean? = null
private var enableEagerRootViewAttachmentCache: Boolean? = null
private var enableEventEmitterRetentionDuringGesturesOnAndroidCache: Boolean? = null
private var enableFabricLogsCache: Boolean? = null
private var enableFabricRendererExclusivelyCache: Boolean? = null
private var enableGranularShadowTreeStateReconciliationCache: Boolean? = null
Expand Down Expand Up @@ -154,6 +155,15 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
return cached
}

override fun enableEventEmitterRetentionDuringGesturesOnAndroid(): Boolean {
var cached = enableEventEmitterRetentionDuringGesturesOnAndroidCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.enableEventEmitterRetentionDuringGesturesOnAndroid()
enableEventEmitterRetentionDuringGesturesOnAndroidCache = cached
}
return cached
}

override fun enableFabricLogs(): Boolean {
var cached = enableFabricLogsCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<fec9ad21cd603e23ef38d926ba693340>>
* @generated SignedSource<<1d79b037e6e8cf2e7306b7f5b3798b9a>>
*/

/**
Expand Down Expand Up @@ -48,6 +48,8 @@ public object ReactNativeFeatureFlagsCxxInterop {

@DoNotStrip @JvmStatic public external fun enableEagerRootViewAttachment(): Boolean

@DoNotStrip @JvmStatic public external fun enableEventEmitterRetentionDuringGesturesOnAndroid(): Boolean

@DoNotStrip @JvmStatic public external fun enableFabricLogs(): Boolean

@DoNotStrip @JvmStatic public external fun enableFabricRendererExclusively(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<06c99ad6853216864f14c96fdc9704dd>>
* @generated SignedSource<<c9d11f2cf414d546f5c9be0a05b22e85>>
*/

/**
Expand Down Expand Up @@ -43,6 +43,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi

override fun enableEagerRootViewAttachment(): Boolean = false

override fun enableEventEmitterRetentionDuringGesturesOnAndroid(): Boolean = false

override fun enableFabricLogs(): Boolean = false

override fun enableFabricRendererExclusively(): Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<a0b0cc1b62abded9dd8a7b70f8d897da>>
* @generated SignedSource<<408d66cdad8b708c06ca844cd6524ba4>>
*/

/**
Expand Down Expand Up @@ -34,6 +34,7 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
private var enableBackgroundStyleApplicatorCache: Boolean? = null
private var enableCleanTextInputYogaNodeCache: Boolean? = null
private var enableEagerRootViewAttachmentCache: Boolean? = null
private var enableEventEmitterRetentionDuringGesturesOnAndroidCache: Boolean? = null
private var enableFabricLogsCache: Boolean? = null
private var enableFabricRendererExclusivelyCache: Boolean? = null
private var enableGranularShadowTreeStateReconciliationCache: Boolean? = null
Expand Down Expand Up @@ -168,6 +169,16 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
return cached
}

override fun enableEventEmitterRetentionDuringGesturesOnAndroid(): Boolean {
var cached = enableEventEmitterRetentionDuringGesturesOnAndroidCache
if (cached == null) {
cached = currentProvider.enableEventEmitterRetentionDuringGesturesOnAndroid()
accessedFeatureFlags.add("enableEventEmitterRetentionDuringGesturesOnAndroid")
enableEventEmitterRetentionDuringGesturesOnAndroidCache = cached
}
return cached
}

override fun enableFabricLogs(): Boolean {
var cached = enableFabricLogsCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<6c32d13e793895356e70e01c2fa784b6>>
* @generated SignedSource<<040b9cb9cec727e2eb31769712980528>>
*/

/**
Expand Down Expand Up @@ -43,6 +43,8 @@ public interface ReactNativeFeatureFlagsProvider {

@DoNotStrip public fun enableEagerRootViewAttachment(): Boolean

@DoNotStrip public fun enableEventEmitterRetentionDuringGesturesOnAndroid(): Boolean

@DoNotStrip public fun enableFabricLogs(): Boolean

@DoNotStrip public fun enableFabricRendererExclusively(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.UIManager;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
import com.facebook.react.uimanager.common.UIManagerType;
import com.facebook.react.uimanager.events.EventDispatcher;
import com.facebook.react.uimanager.events.TouchEvent;
Expand Down Expand Up @@ -191,6 +192,9 @@ public void handleTouchEvent(

private void markActiveTouchForTag(
int surfaceId, int reactTag, @Nullable ReactContext reactContext) {
if (!ReactNativeFeatureFlags.enableEventEmitterRetentionDuringGesturesOnAndroid()) {
return;
}
if (reactContext == null) {
return;
}
Expand All @@ -202,6 +206,9 @@ private void markActiveTouchForTag(

private void sweepActiveTouchForTag(
int surfaceId, int reactTag, @Nullable ReactContext reactContext) {
if (!ReactNativeFeatureFlags.enableEventEmitterRetentionDuringGesturesOnAndroid()) {
return;
}
if (reactContext == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<12c6250b601db5f8db15dc1bed57405c>>
* @generated SignedSource<<d9fe713f8bbf188b2f47e7798b939351>>
*/

/**
Expand Down Expand Up @@ -99,6 +99,12 @@ class ReactNativeFeatureFlagsProviderHolder
return method(javaProvider_);
}

bool enableEventEmitterRetentionDuringGesturesOnAndroid() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableEventEmitterRetentionDuringGesturesOnAndroid");
return method(javaProvider_);
}

bool enableFabricLogs() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableFabricLogs");
Expand Down Expand Up @@ -351,6 +357,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enableEagerRootViewAttachment(
return ReactNativeFeatureFlags::enableEagerRootViewAttachment();
}

bool JReactNativeFeatureFlagsCxxInterop::enableEventEmitterRetentionDuringGesturesOnAndroid(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::enableEventEmitterRetentionDuringGesturesOnAndroid();
}

bool JReactNativeFeatureFlagsCxxInterop::enableFabricLogs(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::enableFabricLogs();
Expand Down Expand Up @@ -563,6 +574,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"enableEagerRootViewAttachment",
JReactNativeFeatureFlagsCxxInterop::enableEagerRootViewAttachment),
makeNativeMethod(
"enableEventEmitterRetentionDuringGesturesOnAndroid",
JReactNativeFeatureFlagsCxxInterop::enableEventEmitterRetentionDuringGesturesOnAndroid),
makeNativeMethod(
"enableFabricLogs",
JReactNativeFeatureFlagsCxxInterop::enableFabricLogs),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<5399269d162bd4823a7ec36198c0604f>>
* @generated SignedSource<<d53535b04b78e24612042ba9b39f26a8>>
*/

/**
Expand Down Expand Up @@ -60,6 +60,9 @@ class JReactNativeFeatureFlagsCxxInterop
static bool enableEagerRootViewAttachment(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool enableEventEmitterRetentionDuringGesturesOnAndroid(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool enableFabricLogs(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<ed768614ca40990bc4cb67fd30c62274>>
* @generated SignedSource<<d6fc68526bed62a7aa33973b2cb1eec8>>
*/

/**
Expand Down Expand Up @@ -61,6 +61,10 @@ bool ReactNativeFeatureFlags::enableEagerRootViewAttachment() {
return getAccessor().enableEagerRootViewAttachment();
}

bool ReactNativeFeatureFlags::enableEventEmitterRetentionDuringGesturesOnAndroid() {
return getAccessor().enableEventEmitterRetentionDuringGesturesOnAndroid();
}

bool ReactNativeFeatureFlags::enableFabricLogs() {
return getAccessor().enableFabricLogs();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<93b1717fb2e45f00fb068a4ffa248afe>>
* @generated SignedSource<<45ae072fb6a0b1ec404b3dc8adc13186>>
*/

/**
Expand Down Expand Up @@ -87,6 +87,11 @@ class ReactNativeFeatureFlags {
*/
RN_EXPORT static bool enableEagerRootViewAttachment();

/**
* Enables the retention of EventEmitterWrapper on Android till the touch gesture is over to fix a bug on pressable (#44610)
*/
RN_EXPORT static bool enableEventEmitterRetentionDuringGesturesOnAndroid();

/**
* This feature flag enables logs for Fabric.
*/
Expand Down
Loading

0 comments on commit 81f1683

Please sign in to comment.