mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Support onActivityResult in Bridgeless (#43351)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43351 Implement `onActivityResult` on Bridgeless Changelog: [Internal] internal Reviewed By: cortinico Differential Revision: D54574139 fbshipit-source-id: f2369077199186ac6ef0187b5dfe7ed95f3b87fc
This commit is contained in:
committed by
Alex Hunt
parent
31b62ab7f0
commit
10d65924ee
@@ -196,6 +196,7 @@ public abstract interface class com/facebook/react/ReactHost {
|
||||
public abstract fun getJsEngineResolutionAlgorithm ()Lcom/facebook/react/JSEngineResolutionAlgorithm;
|
||||
public abstract fun getLifecycleState ()Lcom/facebook/react/common/LifecycleState;
|
||||
public abstract fun getReactQueueConfiguration ()Lcom/facebook/react/bridge/queue/ReactQueueConfiguration;
|
||||
public abstract fun onActivityResult (Landroid/app/Activity;IILandroid/content/Intent;)V
|
||||
public abstract fun onBackPressed ()Z
|
||||
public abstract fun onHostDestroy ()V
|
||||
public abstract fun onHostDestroy (Landroid/app/Activity;)V
|
||||
@@ -3602,6 +3603,7 @@ public class com/facebook/react/runtime/ReactHostImpl : com/facebook/react/React
|
||||
public fun getLifecycleState ()Lcom/facebook/react/common/LifecycleState;
|
||||
public fun getMemoryPressureRouter ()Lcom/facebook/react/MemoryPressureRouter;
|
||||
public fun getReactQueueConfiguration ()Lcom/facebook/react/bridge/queue/ReactQueueConfiguration;
|
||||
public fun onActivityResult (Landroid/app/Activity;IILandroid/content/Intent;)V
|
||||
public fun onBackPressed ()Z
|
||||
public fun onHostDestroy ()V
|
||||
public fun onHostDestroy (Landroid/app/Activity;)V
|
||||
|
||||
+1
-2
@@ -139,8 +139,7 @@ public class ReactDelegate {
|
||||
public void onActivityResult(
|
||||
int requestCode, int resultCode, Intent data, boolean shouldForwardToReactInstance) {
|
||||
if (ReactFeatureFlags.enableBridgelessArchitecture) {
|
||||
// TODO T156475655: Implement onActivityResult for Bridgeless
|
||||
return;
|
||||
mReactHost.onActivityResult(mActivity, requestCode, resultCode, data);
|
||||
} else {
|
||||
if (getReactNativeHost().hasInstance() && shouldForwardToReactInstance) {
|
||||
getReactNativeHost()
|
||||
|
||||
@@ -9,6 +9,7 @@ package com.facebook.react
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import com.facebook.react.bridge.ReactContext
|
||||
import com.facebook.react.bridge.queue.ReactQueueConfiguration
|
||||
@@ -111,6 +112,14 @@ public interface ReactHost {
|
||||
*/
|
||||
public fun destroy(reason: String, ex: Exception?): TaskInterface<Void>
|
||||
|
||||
/* To be called when the host activity receives an activity result. */
|
||||
public fun onActivityResult(
|
||||
activity: Activity,
|
||||
requestCode: Int,
|
||||
resultCode: Int,
|
||||
data: Intent?,
|
||||
)
|
||||
|
||||
public fun addBeforeDestroyListener(onBeforeDestroy: () -> Unit)
|
||||
|
||||
public fun removeBeforeDestroyListener(onBeforeDestroy: () -> Unit)
|
||||
|
||||
+32
@@ -15,6 +15,7 @@ import static java.lang.Boolean.TRUE;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -600,6 +601,37 @@ public class ReactHostImpl implements ReactHost {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* To be called when the host activity receives an activity result.
|
||||
*
|
||||
* @param activity The host activity
|
||||
*/
|
||||
@ThreadConfined(UI)
|
||||
@Override
|
||||
public void onActivityResult(
|
||||
Activity activity, int requestCode, int resultCode, @Nullable Intent data) {
|
||||
final String method =
|
||||
"onActivityResult(activity = \""
|
||||
+ activity
|
||||
+ "\", requestCode = \""
|
||||
+ requestCode
|
||||
+ "\", resultCode = \""
|
||||
+ resultCode
|
||||
+ "\", data = \""
|
||||
+ data
|
||||
+ "\")";
|
||||
log(method);
|
||||
|
||||
ReactContext currentContext = getCurrentReactContext();
|
||||
if (currentContext != null) {
|
||||
currentContext.onActivityResult(activity, requestCode, resultCode, data);
|
||||
}
|
||||
ReactSoftExceptionLogger.logSoftException(
|
||||
TAG,
|
||||
new ReactNoCrashSoftException(
|
||||
"Tried to access onActivityResult while context is not ready"));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
JavaScriptContextHolder getJavaScriptContextHolder() {
|
||||
final ReactInstance reactInstance = mReactInstanceTaskRef.get().getResult();
|
||||
|
||||
Reference in New Issue
Block a user