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 onNewIntent in Bridgeless #43401

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
3 changes: 3 additions & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public class com/facebook/react/ReactDelegate {
public fun onHostDestroy ()V
public fun onHostPause ()V
public fun onHostResume ()V
public fun onNewIntent (Landroid/content/Intent;)Z
public fun onWindowFocusChanged (Z)V
public fun shouldShowDevMenuOrReload (ILandroid/view/KeyEvent;)Z
}
Expand Down Expand Up @@ -204,6 +205,7 @@ public abstract interface class com/facebook/react/ReactHost {
public abstract fun onHostPause (Landroid/app/Activity;)V
public abstract fun onHostResume (Landroid/app/Activity;)V
public abstract fun onHostResume (Landroid/app/Activity;Lcom/facebook/react/modules/core/DefaultHardwareBackBtnHandler;)V
public abstract fun onNewIntent (Landroid/content/Intent;)V
public abstract fun onWindowFocusChange (Z)V
public abstract fun reload (Ljava/lang/String;)Lcom/facebook/react/interfaces/TaskInterface;
public abstract fun removeBeforeDestroyListener (Lkotlin/jvm/functions/Function0;)V
Expand Down Expand Up @@ -3643,6 +3645,7 @@ public class com/facebook/react/runtime/ReactHostImpl : com/facebook/react/React
public fun onHostPause (Landroid/app/Activity;)V
public fun onHostResume (Landroid/app/Activity;)V
public fun onHostResume (Landroid/app/Activity;Lcom/facebook/react/modules/core/DefaultHardwareBackBtnHandler;)V
public fun onNewIntent (Landroid/content/Intent;)V
public fun onWindowFocusChange (Z)V
public fun reload (Ljava/lang/String;)Lcom/facebook/react/interfaces/TaskInterface;
public fun removeBeforeDestroyListener (Lkotlin/jvm/functions/Function0;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,7 @@ public boolean onBackPressed() {
}

public boolean onNewIntent(Intent intent) {
if (ReactFeatureFlags.enableBridgelessArchitecture) {
// TODO T156475655: support onNewIntent
} else {
if (getReactNativeHost().hasInstance()) {
getReactNativeHost().getReactInstanceManager().onNewIntent(intent);
return true;
}
}
return false;
return mReactDelegate.onNewIntent(intent);
}

public void onWindowFocusChanged(boolean hasFocus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,19 @@ public boolean onBackPressed() {
return false;
}

public boolean onNewIntent(Intent intent) {
if (ReactFeatureFlags.enableBridgelessArchitecture) {
mReactHost.onNewIntent(intent);
return true;
} else {
if (getReactNativeHost().hasInstance()) {
getReactNativeHost().getReactInstanceManager().onNewIntent(intent);
return true;
}
}
return false;
}

public void onActivityResult(
int requestCode, int resultCode, Intent data, boolean shouldForwardToReactInstance) {
if (ReactFeatureFlags.enableBridgelessArchitecture) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ public interface ReactHost {
/* To be called when focus has changed for the hosting window. */
public fun onWindowFocusChange(hasFocus: Boolean)

/* This method will give JS the opportunity to receive intents via Linking. */
public fun onNewIntent(intent: Intent)

public fun addBeforeDestroyListener(onBeforeDestroy: () -> Unit)

public fun removeBeforeDestroyListener(onBeforeDestroy: () -> Unit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.nfc.NfcAdapter;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -667,6 +669,36 @@ public void onWindowFocusChange(boolean hasFocus) {
"Tried to access onWindowFocusChange while context is not ready"));
}

/* This method will give JS the opportunity to receive intents via Linking.
*
* @param intent The incoming intent
*/
@ThreadConfined(UI)
@Override
public void onNewIntent(Intent intent) {
log("onNewIntent()");

ReactContext currentContext = getCurrentReactContext();
if (currentContext != null) {
String action = intent.getAction();
Uri uri = intent.getData();

if (uri != null
&& (Intent.ACTION_VIEW.equals(action)
|| NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))) {
DeviceEventManagerModule deviceEventManagerModule =
currentContext.getNativeModule(DeviceEventManagerModule.class);
if (deviceEventManagerModule != null) {
deviceEventManagerModule.emitNewIntentReceived(uri);
}
}
currentContext.onNewIntent(getCurrentActivity(), intent);
}
ReactSoftExceptionLogger.logSoftException(
TAG,
new ReactNoCrashSoftException("Tried to access onNewIntent while context is not ready"));
}

@Nullable
JavaScriptContextHolder getJavaScriptContextHolder() {
final ReactInstance reactInstance = mReactInstanceTaskRef.get().getResult();
Expand Down
Loading