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

Tolu/link verf UI #9541

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft
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
75 changes: 58 additions & 17 deletions link/api/link.api
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,6 @@ public final class com/stripe/android/link/BuildConfig {
public fun <init> ()V
}

public final class com/stripe/android/link/ComposableSingletons$LinkActivityKt {
public static final field INSTANCE Lcom/stripe/android/link/ComposableSingletons$LinkActivityKt;
public static field lambda-1 Lkotlin/jvm/functions/Function4;
public static field lambda-2 Lkotlin/jvm/functions/Function4;
public static field lambda-3 Lkotlin/jvm/functions/Function4;
public static field lambda-4 Lkotlin/jvm/functions/Function4;
public static field lambda-5 Lkotlin/jvm/functions/Function4;
public static field lambda-6 Lkotlin/jvm/functions/Function4;
public fun <init> ()V
public final fun getLambda-1$link_release ()Lkotlin/jvm/functions/Function4;
public final fun getLambda-2$link_release ()Lkotlin/jvm/functions/Function4;
public final fun getLambda-3$link_release ()Lkotlin/jvm/functions/Function4;
public final fun getLambda-4$link_release ()Lkotlin/jvm/functions/Function4;
public final fun getLambda-5$link_release ()Lkotlin/jvm/functions/Function4;
public final fun getLambda-6$link_release ()Lkotlin/jvm/functions/Function4;
}

public final class com/stripe/android/link/LinkActivityContract$Companion {
}

Expand Down Expand Up @@ -97,6 +80,31 @@ public final class com/stripe/android/link/NativeLinkArgs$Creator : android/os/P
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/link/ui/ComposableSingletons$LinkAppBarKt {
public static final field INSTANCE Lcom/stripe/android/link/ui/ComposableSingletons$LinkAppBarKt;
public static field lambda-1 Lkotlin/jvm/functions/Function3;
public static field lambda-10 Lkotlin/jvm/functions/Function2;
public static field lambda-2 Lkotlin/jvm/functions/Function2;
public static field lambda-3 Lkotlin/jvm/functions/Function2;
public static field lambda-4 Lkotlin/jvm/functions/Function2;
public static field lambda-5 Lkotlin/jvm/functions/Function2;
public static field lambda-6 Lkotlin/jvm/functions/Function2;
public static field lambda-7 Lkotlin/jvm/functions/Function2;
public static field lambda-8 Lkotlin/jvm/functions/Function2;
public static field lambda-9 Lkotlin/jvm/functions/Function2;
public fun <init> ()V
public final fun getLambda-1$link_release ()Lkotlin/jvm/functions/Function3;
public final fun getLambda-10$link_release ()Lkotlin/jvm/functions/Function2;
public final fun getLambda-2$link_release ()Lkotlin/jvm/functions/Function2;
public final fun getLambda-3$link_release ()Lkotlin/jvm/functions/Function2;
public final fun getLambda-4$link_release ()Lkotlin/jvm/functions/Function2;
public final fun getLambda-5$link_release ()Lkotlin/jvm/functions/Function2;
public final fun getLambda-6$link_release ()Lkotlin/jvm/functions/Function2;
public final fun getLambda-7$link_release ()Lkotlin/jvm/functions/Function2;
public final fun getLambda-8$link_release ()Lkotlin/jvm/functions/Function2;
public final fun getLambda-9$link_release ()Lkotlin/jvm/functions/Function2;
}

public final class com/stripe/android/link/ui/ComposableSingletons$LinkButtonKt {
public static final field INSTANCE Lcom/stripe/android/link/ui/ComposableSingletons$LinkButtonKt;
public static field lambda-1 Lkotlin/jvm/functions/Function2;
Expand All @@ -108,6 +116,23 @@ public final class com/stripe/android/link/ui/ComposableSingletons$LinkButtonKt
public final fun getLambda-3$link_release ()Lkotlin/jvm/functions/Function2;
}

public final class com/stripe/android/link/ui/ComposableSingletons$LinkContentKt {
public static final field INSTANCE Lcom/stripe/android/link/ui/ComposableSingletons$LinkContentKt;
public static field lambda-1 Lkotlin/jvm/functions/Function3;
public static field lambda-2 Lkotlin/jvm/functions/Function4;
public static field lambda-3 Lkotlin/jvm/functions/Function4;
public static field lambda-4 Lkotlin/jvm/functions/Function4;
public static field lambda-5 Lkotlin/jvm/functions/Function4;
public static field lambda-6 Lkotlin/jvm/functions/Function4;
public fun <init> ()V
public final fun getLambda-1$link_release ()Lkotlin/jvm/functions/Function3;
public final fun getLambda-2$link_release ()Lkotlin/jvm/functions/Function4;
public final fun getLambda-3$link_release ()Lkotlin/jvm/functions/Function4;
public final fun getLambda-4$link_release ()Lkotlin/jvm/functions/Function4;
public final fun getLambda-5$link_release ()Lkotlin/jvm/functions/Function4;
public final fun getLambda-6$link_release ()Lkotlin/jvm/functions/Function4;
}

public final class com/stripe/android/link/ui/ComposableSingletons$LinkTermsKt {
public static final field INSTANCE Lcom/stripe/android/link/ui/ComposableSingletons$LinkTermsKt;
public static field lambda-1 Lkotlin/jvm/functions/Function2;
Expand All @@ -117,6 +142,13 @@ public final class com/stripe/android/link/ui/ComposableSingletons$LinkTermsKt {
public final fun getLambda-2$link_release ()Lkotlin/jvm/functions/Function2;
}

public final class com/stripe/android/link/ui/ComposableSingletons$PrimaryButtonKt {
public static final field INSTANCE Lcom/stripe/android/link/ui/ComposableSingletons$PrimaryButtonKt;
public static field lambda-1 Lkotlin/jvm/functions/Function2;
public fun <init> ()V
public final fun getLambda-1$link_release ()Lkotlin/jvm/functions/Function2;
}

public final class com/stripe/android/link/ui/ErrorMessage$FromResources$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/link/ui/ErrorMessage$FromResources;
Expand Down Expand Up @@ -170,6 +202,15 @@ public final class com/stripe/android/link/ui/inline/ComposableSingletons$LinkOp
public final fun getLambda-6$link_release ()Lkotlin/jvm/functions/Function2;
}

public final class com/stripe/android/link/ui/signup/ComposableSingletons$SignUpScreenKt {
public static final field INSTANCE Lcom/stripe/android/link/ui/signup/ComposableSingletons$SignUpScreenKt;
public static field lambda-1 Lkotlin/jvm/functions/Function2;
public static field lambda-2 Lkotlin/jvm/functions/Function2;
public fun <init> ()V
public final fun getLambda-1$link_release ()Lkotlin/jvm/functions/Function2;
public final fun getLambda-2$link_release ()Lkotlin/jvm/functions/Function2;
}

public final class com/stripe/android/link/utils/ComposableSingletons$InlineContentTemplateBuilderKt {
public static final field INSTANCE Lcom/stripe/android/link/utils/ComposableSingletons$InlineContentTemplateBuilderKt;
public static field lambda-1 Lkotlin/jvm/functions/Function2;
Expand Down
11 changes: 11 additions & 0 deletions link/res/drawable/stripe_link_back.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:autoMirrored="true"
android:width="14dp"
android:height="13dp"
android:viewportWidth="14"
android:viewportHeight="13">
<path
android:pathData="M3.0728,5.6L7.1364,1.5364C7.4879,1.1849 7.4879,0.6151 7.1364,0.2636C6.7849,-0.0879 6.2151,-0.0879 5.8636,0.2636L0.2636,5.8636C-0.0879,6.2151 -0.0879,6.7849 0.2636,7.1364L5.8636,12.7364C6.2151,13.0879 6.7849,13.0879 7.1364,12.7364C7.4879,12.3849 7.4879,11.8151 7.1364,11.4636L3.0728,7.4H13.1C13.5971,7.4 14,6.9971 14,6.5C14,6.0029 13.5971,5.6 13.1,5.6H3.0728Z"
android:fillColor="#000000"
android:fillType="evenOdd" />
</vector>
10 changes: 10 additions & 0 deletions link/res/drawable/stripe_link_close.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="14dp"
android:height="14dp"
android:viewportWidth="14"
android:viewportHeight="14">
<path
android:pathData="M7.0007,5.5853L11.5926,0.9934C11.9835,0.6025 12.6173,0.6025 13.0082,0.9934C13.399,1.3843 13.399,2.018 13.0082,2.4089L8.4168,7.0002L13.0082,11.5915C13.399,11.9824 13.399,12.6161 13.0082,13.007C12.6173,13.3979 11.9835,13.3979 11.5926,13.007L7.0007,8.4151L2.4087,13.007C2.0178,13.3979 1.3841,13.3979 0.9932,13.007C0.6023,12.6161 0.6023,11.9824 0.9932,11.5915L5.5845,7.0002L0.9932,2.4089C0.6023,2.018 0.6023,1.3843 0.9932,0.9934C1.3841,0.6025 2.0178,0.6025 2.4087,0.9934L7.0007,5.5853Z"
android:fillColor="#000000"
android:fillType="evenOdd"/>
</vector>
17 changes: 17 additions & 0 deletions link/res/drawable/stripe_link_complete.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="25dp"
android:height="24dp"
android:viewportWidth="25"
android:viewportHeight="24">
<path
android:strokeWidth="1"
android:pathData="M10.649,14.606L8.146,12.127C7.951,11.93 7.951,11.611 8.146,11.414C8.342,11.217 8.658,11.217 8.854,11.414L11,13.527L15.144,9.398C15.34,9.201 15.656,9.201 15.851,9.398C16.047,9.595 16.047,9.914 15.851,10.111L11.35,14.604C11.156,14.798 10.844,14.799 10.649,14.606Z"
android:fillColor="#1D3944"
android:fillType="evenOdd"
android:strokeColor="#1D3944"/>
<path
android:pathData="M12,12m-8,0a8,8 0,1 1,16 0a8,8 0,1 1,-16 0"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#1D3944"/>
</vector>
4 changes: 0 additions & 4 deletions link/res/values/donottranslate.xml

This file was deleted.

30 changes: 30 additions & 0 deletions link/src/main/java/com/stripe/android/link/ComposeExtensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.stripe.android.link

import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewmodel.compose.viewModel
import com.stripe.android.link.injection.NativeLinkComponent
import com.stripe.android.uicore.utils.extractActivity

/**
* Retrieves or builds a ViewModel instance, providing the [NativeLinkComponent] (activity
* retained component) to the factory to facilitate its creation via dependency injection.
*/
@Composable
internal inline fun <reified T : ViewModel> linkViewModel(
factory: (NativeLinkComponent) -> ViewModelProvider.Factory
): T {
val component = parentActivity().viewModel?.activityRetainedComponent
?: throw IllegalStateException("no viewmodel in parent activity")
return viewModel<T>(factory = factory(component))
}

/**
* Retrieves the parent [LinkActivity] from the current Compose context.
*/
@Composable
internal fun parentActivity(): LinkActivity {
return LocalContext.current.extractActivity() as LinkActivity
}
90 changes: 43 additions & 47 deletions link/src/main/java/com/stripe/android/link/LinkActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,34 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.annotation.VisibleForTesting
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.ModalBottomSheetValue
import androidx.compose.material.rememberModalBottomSheetState
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.core.os.bundleOf
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.stripe.android.core.Logger
import com.stripe.android.link.ui.cardedit.CardEditScreen
import com.stripe.android.link.ui.paymentmenthod.PaymentMethodScreen
import com.stripe.android.link.ui.signup.SignUpScreen
import com.stripe.android.link.ui.verification.VerificationScreen
import com.stripe.android.link.ui.wallet.WalletScreen
import com.stripe.android.ui.core.CircularProgressIndicator
import com.stripe.android.link.ui.BottomSheetContent
import com.stripe.android.link.ui.LinkContent
import kotlinx.coroutines.launch

internal class LinkActivity : ComponentActivity() {
internal var viewModel: LinkActivityViewModel? = null

@VisibleForTesting
internal lateinit var navController: NavHostController

@OptIn(ExperimentalMaterialApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Expand All @@ -44,48 +46,42 @@ internal class LinkActivity : ComponentActivity() {
finish()
}

val vm = viewModel ?: return
setContent {
var bottomSheetContent by remember { mutableStateOf<BottomSheetContent?>(null) }
val sheetState = rememberModalBottomSheetState(ModalBottomSheetValue.Hidden)
val coroutineScope = rememberCoroutineScope()
val appBarState by vm.linkState.collectAsState()

if (bottomSheetContent != null) {
DisposableEffect(bottomSheetContent) {
coroutineScope.launch { sheetState.show() }
onDispose {
coroutineScope.launch { sheetState.hide() }
}
}
}
navController = rememberNavController()

LaunchedEffect(Unit) {
viewModel?.navController = navController
viewModel?.dismissWithResult = ::dismissWithResult
viewModel?.let {
it.navController = navController
it.dismissWithResult = ::dismissWithResult
lifecycle.addObserver(it)
}
}

NavHost(
LinkContent(
viewModel = vm,
navController = navController,
startDestination = LinkScreen.Loading.route
) {
composable(LinkScreen.Loading.route) {
Box(
modifier = Modifier
.fillMaxSize(),
contentAlignment = Alignment.Center
) {
CircularProgressIndicator()
}
}

composable(LinkScreen.SignUp.route) {
SignUpScreen()
}

composable(LinkScreen.Verification.route) {
VerificationScreen()
}

composable(LinkScreen.Wallet.route) {
WalletScreen()
}

composable(LinkScreen.CardEdit.route) {
CardEditScreen()
}

composable(LinkScreen.PaymentMethod.route) {
PaymentMethodScreen()
}
}
appBarState = appBarState,
sheetState = sheetState,
bottomSheetContent = bottomSheetContent,
onUpdateSheetContent = {
bottomSheetContent = it
},
onBackPressed = onBackPressedDispatcher::onBackPressed,
)
}
}

Expand Down
Loading