diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 7f2be705b81168..f1bff1dbed5d7e 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -154,6 +154,8 @@ 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 onKeyLongPress (I)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..54022ed27d5918 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) { @@ -165,17 +155,7 @@ public boolean onKeyUp(int keyCode, KeyEvent event) { } public boolean onKeyLongPress(int keyCode, KeyEvent event) { - if (ReactFeatureFlags.enableBridgelessArchitecture) { - // TODO T156475655: support onKeyLongPress - } else { - if (getReactNativeHost().hasInstance() - && getReactNativeHost().getUseDeveloperSupport() - && keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD) { - getReactNativeHost().getReactInstanceManager().showDevOptionsDialog(); - return true; - } - } - return false; + return mReactDelegate.onKeyLongPress(keyCode); } public boolean onBackPressed() { 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..97c4a70a3b6e0c 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 @@ -84,6 +84,7 @@ public ReactDelegate( public void onHostResume() { if (ReactFeatureFlags.enableBridgelessArchitecture) { if (mActivity instanceof DefaultHardwareBackBtnHandler) { + assert mReactHost != null : "Tried to access onHostResume while ReactHost is null"; mReactHost.onHostResume(mActivity, (DefaultHardwareBackBtnHandler) mActivity); } } else { @@ -102,6 +103,7 @@ public void onHostResume() { public void onHostPause() { if (ReactFeatureFlags.enableBridgelessArchitecture) { + assert mReactHost != null : "Tried to access onHostPause while ReactHost is null"; mReactHost.onHostPause(mActivity); } else { if (getReactNativeHost().hasInstance()) { @@ -112,6 +114,7 @@ public void onHostPause() { public void onHostDestroy() { if (ReactFeatureFlags.enableBridgelessArchitecture) { + assert mReactHost != null : "Tried to access onHostDestroy while ReactHost is null"; mReactHost.onHostDestroy(mActivity); } else { if (mReactRootView != null) { @@ -126,6 +129,7 @@ public void onHostDestroy() { public boolean onBackPressed() { if (ReactFeatureFlags.enableBridgelessArchitecture) { + assert mReactHost != null : "Tried to access onBackPressed while ReactHost is null"; mReactHost.onBackPressed(); return true; } else { @@ -139,6 +143,7 @@ public boolean onBackPressed() { public boolean onNewIntent(Intent intent) { if (ReactFeatureFlags.enableBridgelessArchitecture) { + assert mReactHost != null : "Tried to access onNewIntent while ReactHost is null"; mReactHost.onNewIntent(intent); return true; } else { @@ -153,6 +158,7 @@ public boolean onNewIntent(Intent intent) { public void onActivityResult( int requestCode, int resultCode, Intent data, boolean shouldForwardToReactInstance) { if (ReactFeatureFlags.enableBridgelessArchitecture) { + assert mReactHost != null : "Tried to access onActivityResult while ReactHost is null"; mReactHost.onActivityResult(mActivity, requestCode, resultCode, data); } else { if (getReactNativeHost().hasInstance() && shouldForwardToReactInstance) { @@ -165,6 +171,7 @@ public void onActivityResult( public void onWindowFocusChanged(boolean hasFocus) { if (ReactFeatureFlags.enableBridgelessArchitecture) { + assert mReactHost != null : "Tried to access onWindowFocusChanged while ReactHost is null"; mReactHost.onWindowFocusChange(hasFocus); } else { if (getReactNativeHost().hasInstance()) { @@ -175,6 +182,7 @@ public void onWindowFocusChanged(boolean hasFocus) { public void onConfigurationChanged(Configuration newConfig) { if (ReactFeatureFlags.enableBridgelessArchitecture) { + assert mReactHost != null : "Tried to access onConfigurationChanged while ReactHost is null"; mReactHost.onConfigurationChanged(Assertions.assertNotNull(mActivity)); } else { if (getReactNativeHost().hasInstance()) { @@ -184,6 +192,36 @@ 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 boolean onKeyLongPress(int keyCode) { + if (keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD) { + if (ReactFeatureFlags.enableBridgelessArchitecture + && mReactHost != null + && mReactHost.getDevSupportManager() != null) { + mReactHost.getDevSupportManager().showDevOptionsDialog(); + return true; + } else { + if (getReactNativeHost().hasInstance() && getReactNativeHost().getUseDeveloperSupport()) { + getReactNativeHost().getReactInstanceManager().showDevOptionsDialog(); + return true; + } + } + } + return false; + } + public void loadApp() { loadApp(mMainComponentName); }