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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.activityresult;

import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContract;

abstract class ActivityResultLauncherCompat<I> extends ActivityResultLauncher<I> {
private final ActivityResultContract<I, ?> contract;

ActivityResultLauncherCompat(ActivityResultContract<I, ?> contract) {
this.contract = contract;
}

@Override
public ActivityResultContract<I, ?> getContract() {
return contract;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import com.facebook.react.common.ReactConstants
*/
internal class DeferredActivityResultLauncher<I>(
private val key: String,
override val contract: ActivityResultContract<I, *>,
contract: ActivityResultContract<I, *>,
private val onUnregister: () -> Unit,
private val onLaunchFailure: (RuntimeException) -> Unit = {},
) : ActivityResultLauncher<I>() {
) : ActivityResultLauncherCompat<I>(contract) {

private class PendingLaunch<I>(val input: I, val options: ActivityOptionsCompat?)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ class ReactActivityResultCallerImplTest {
caller = ReactActivityResultCallerImpl(reactContext)
}

@Test
fun launcherExposesRegisteredContract() {
val contract = GetContent()
val launcher = caller.registerForActivityResult(moduleA, contract) {}

assertThat(launcher.contract).isSameAs(contract)
}

@Test
fun twoOwnersMayRegisterTheSameStockContract() {
caller.registerForActivityResult(moduleA, GetContent()) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import android.app.Activity
import android.content.ActivityNotFoundException
import android.os.Bundle
import android.os.Looper
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.ActivityResultRegistry
import androidx.activity.result.ActivityResultRegistryOwner
import androidx.activity.result.contract.ActivityResultContract
Expand Down Expand Up @@ -65,8 +64,7 @@ class ReactActivityResultCallerThreadingTest {
.orEmpty()
}

private class ThrowingLauncher : ActivityResultLauncher<String>() {
override val contract: ActivityResultContract<String, *> = GetContent()
private class ThrowingLauncher : ActivityResultLauncherCompat<String>(GetContent()) {
var launchCount = 0

override fun launch(input: String, options: ActivityOptionsCompat?) {
Expand Down
Loading