Skip to content
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 @@ -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
Expand Down Expand Up @@ -3645,6 +3646,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public boolean onBackPressed() {
public void onActivityResult(
int requestCode, int resultCode, Intent data, boolean shouldForwardToReactInstance) {
if (ReactFeatureFlags.enableBridgelessArchitecture) {
// TODO T156475655: Implement onActivityResult for Bridgeless
mReactHost.onActivityResult(mActivity, requestCode, resultCode, data);
} else {
if (getReactNativeHost().hasInstance() && shouldForwardToReactInstance) {
getReactNativeHost()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -603,6 +604,37 @@ RuntimeExecutor getRuntimeExecutor() {
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"));
}
Comment on lines +632 to +636
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be called unconditionally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this only makes sense in case the context is null ?


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