From f27236daef1f9c4acd597db5fc4d97e18e2f36f0 Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Wed, 1 May 2024 15:09:47 -0700 Subject: [PATCH] Fix onKeyLongPress() in RELEASE Summary: In RELEASE mode, the `devSupportManager` received is ReleaseDevSupportManager for which `showDevOptionsDialog()` is a no-op https://github.com/facebook/react-native/blob/main/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/ReleaseDevSupportManager.java#L66 Which is expected since this is a capability only in Dev mode(useDeveloperSupport = true). However, ATM `onKeyLongPresss()` returns true in RELEASE as well which is a bug. Since there is no need for `onKeyLongPress()` in RELEASE, changing it's logic to introduce that check and return false in case of RELEASE. Changelog: [Android][Fixed] onKeyLongPress() in RELEASE mode Differential Revision: D56850466 --- .../main/java/com/facebook/react/ReactDelegate.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactDelegate.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactDelegate.java index 6aeb8f8aff8181..a35a69c712d5c0 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactDelegate.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactDelegate.java @@ -220,11 +220,12 @@ && getReactNativeHost().getUseDeveloperSupport()))) { public boolean onKeyLongPress(int keyCode) { if (keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD) { - if (ReactFeatureFlags.enableBridgelessArchitecture - && mReactHost != null - && mReactHost.getDevSupportManager() != null) { - mReactHost.getDevSupportManager().showDevOptionsDialog(); - return true; + if (ReactFeatureFlags.enableBridgelessArchitecture && mReactHost != null) { + DevSupportManager devSupportManager = mReactHost.getDevSupportManager(); + if (devSupportManager != null && !(devSupportManager instanceof ReleaseDevSupportManager)) { + devSupportManager.showDevOptionsDialog(); + return true; + } } else { if (getReactNativeHost().hasInstance() && getReactNativeHost().getUseDeveloperSupport()) { getReactNativeHost().getReactInstanceManager().showDevOptionsDialog();