From b14f7d58e3537b9bfa2638d1d71ec3dc908f4b8d Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Thu, 14 Mar 2024 12:10:57 -0700 Subject: [PATCH] Support onKeyDown in Bridgeless (#43466) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43466 Implement `onKeyDown` in Bridgeless by adding it to ReactHostImpl Changelog: [Android][Breaking] Implement `onKeyDown` in Bridgeless Reviewed By: cortinico Differential Revision: D54870966 fbshipit-source-id: 0f8e48b29679f1bca92f6ac7b6ebf1592cdc5dac --- .../react-native/ReactAndroid/api/ReactAndroid.api | 1 + .../com/facebook/react/ReactActivityDelegate.java | 12 +----------- .../main/java/com/facebook/react/ReactDelegate.java | 13 +++++++++++++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index cb71470eead4dd..a65138321a8db8 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -154,6 +154,7 @@ public class com/facebook/react/ReactDelegate { public fun onHostDestroy ()V public fun onHostPause ()V public fun onHostResume ()V + public fun onKeyDown (ILandroid/view/KeyEvent;)Z public fun onNewIntent (Landroid/content/Intent;)Z public fun onWindowFocusChanged (Z)V public fun shouldShowDevMenuOrReload (ILandroid/view/KeyEvent;)Z diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java index 7079133f7d5149..45d6877405a3e6 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java @@ -147,17 +147,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { } public boolean onKeyDown(int keyCode, KeyEvent event) { - if (ReactFeatureFlags.enableBridgelessArchitecture) { - // TODO T156475655: support onKeyDown - } else { - if (getReactNativeHost().hasInstance() - && getReactNativeHost().getUseDeveloperSupport() - && keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD) { - event.startTracking(); - return true; - } - } - return false; + return mReactDelegate.onKeyDown(keyCode, event); } public boolean onKeyUp(int keyCode, KeyEvent event) { 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 1cda3ab15411ce..78f34a177cdd60 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 @@ -184,6 +184,19 @@ public void onConfigurationChanged(Configuration newConfig) { } } + public boolean onKeyDown(int keyCode, KeyEvent event) { + if (keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD + && ((ReactFeatureFlags.enableBridgelessArchitecture + && mReactHost != null + && mReactHost.getDevSupportManager() != null) + || (getReactNativeHost().hasInstance() + && getReactNativeHost().getUseDeveloperSupport()))) { + event.startTracking(); + return true; + } + return false; + } + public void loadApp() { loadApp(mMainComponentName); }