Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support onKeyLongPress in Bridgeless #43472

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,35 +147,15 @@ 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) {
return mReactDelegate.shouldShowDevMenuOrReload(keyCode, 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()) {
Expand All @@ -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) {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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) {
Expand All @@ -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()) {
Expand All @@ -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()) {
Expand All @@ -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);
}
Expand Down
Loading