Start CustomTab from Activity
This commit is contained in:
committed by
Benoit Marty
parent
d33fbaf89f
commit
dbc13a3a3c
@@ -16,9 +16,12 @@
|
||||
|
||||
package io.element.android.features.login.impl
|
||||
|
||||
import android.app.Activity
|
||||
import android.os.Parcelable
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import com.bumble.appyx.core.composable.Children
|
||||
import com.bumble.appyx.core.modality.BuildContext
|
||||
import com.bumble.appyx.core.node.Node
|
||||
@@ -54,6 +57,8 @@ class LoginFlowNode @AssistedInject constructor(
|
||||
buildContext = buildContext,
|
||||
plugins = plugins,
|
||||
) {
|
||||
private var activity: Activity? = null
|
||||
|
||||
sealed interface NavTarget : Parcelable {
|
||||
@Parcelize
|
||||
object Root : NavTarget
|
||||
@@ -76,7 +81,7 @@ class LoginFlowNode @AssistedInject constructor(
|
||||
override fun onOidcDetails(oidcDetails: OidcDetails) {
|
||||
if (customTabAvailabilityChecker.supportCustomTab()) {
|
||||
// In this case open a Chrome Custom tab
|
||||
customTabHandler.open(oidcDetails.url)
|
||||
activity?.let { customTabHandler.open(it, oidcDetails.url) }
|
||||
} else {
|
||||
// Fallback to WebView mode
|
||||
backstack.push(NavTarget.OidcView(oidcDetails))
|
||||
@@ -96,6 +101,12 @@ class LoginFlowNode @AssistedInject constructor(
|
||||
|
||||
@Composable
|
||||
override fun View(modifier: Modifier) {
|
||||
activity = LocalContext.current as? Activity
|
||||
DisposableEffect(lifecycle) {
|
||||
onDispose {
|
||||
activity = null
|
||||
}
|
||||
}
|
||||
Children(
|
||||
navModel = backstack,
|
||||
modifier = modifier,
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package io.element.android.features.login.impl.oidc.customtab
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
@@ -71,7 +72,7 @@ class CustomTabHandler @Inject constructor(
|
||||
customTabsServiceConnection = null
|
||||
}
|
||||
|
||||
fun open(url: String) {
|
||||
context.openUrlInChromeCustomTab(customTabsSession, false, url)
|
||||
fun open(activity: Activity, url: String) {
|
||||
activity.openUrlInChromeCustomTab(customTabsSession, false, url)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,8 @@
|
||||
|
||||
package io.element.android.features.login.impl.oidc.customtab
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.browser.customtabs.CustomTabColorSchemeParams
|
||||
import androidx.browser.customtabs.CustomTabsIntent
|
||||
@@ -29,7 +28,7 @@ import androidx.browser.customtabs.CustomTabsSession
|
||||
* If several compatible browsers are installed, the user will be proposed to choose one.
|
||||
* Ref: https://developer.chrome.com/multidevice/android/customtabs.
|
||||
*/
|
||||
fun Context.openUrlInChromeCustomTab(
|
||||
fun Activity.openUrlInChromeCustomTab(
|
||||
session: CustomTabsSession?,
|
||||
darkTheme: Boolean,
|
||||
url: String
|
||||
@@ -54,9 +53,6 @@ fun Context.openUrlInChromeCustomTab(
|
||||
// .setExitAnimations(context, R.anim.enter_fade_in, R.anim.exit_fade_out)
|
||||
.apply { session?.let { setSession(it) } }
|
||||
.build()
|
||||
.apply {
|
||||
intent.flags += Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
}
|
||||
.launchUrl(this, Uri.parse(url))
|
||||
} catch (activityNotFoundException: ActivityNotFoundException) {
|
||||
// TODO context.toast(R.string.error_no_external_application_found)
|
||||
|
||||
Reference in New Issue
Block a user