Skip to content

Commit

Permalink
Hide Link header on certain screens (#5435)
Browse files Browse the repository at this point in the history
* Hide Link header if not on root screen

* Omit top padding if header is hidden

* Update Link API

* Make minor UX tweak

* Hide header only on card add and update screens

* Use LinkAppBarState and add tests
  • Loading branch information
tillh-stripe committed Aug 24, 2022
1 parent d138617 commit d8f7323
Show file tree
Hide file tree
Showing 9 changed files with 333 additions and 37 deletions.
12 changes: 12 additions & 0 deletions link/api/link.api
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,21 @@ 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/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 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 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 class com/stripe/android/link/ui/ComposableSingletons$PrimaryButtonKt {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
package com.stripe.android.link.ui

import androidx.activity.ComponentActivity
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import com.stripe.android.link.LinkScreen
import com.stripe.android.link.R
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
internal class LinkAppBarStateTest {

@get:Rule
val composeTestRule = createAndroidComposeRule<ComponentActivity>()

@Test
fun rejectsBlankEmailAddress() {
val state = buildLinkAppBarState(
isRootScreen = true,
currentRoute = LinkScreen.Wallet.route,
email = " "
)

assertThat(state.email).isNull()
}

@Test
fun loadingScreenShowsCorrectAppBarState() {
val state = buildLinkAppBarState(
isRootScreen = true,
currentRoute = LinkScreen.Loading.route,
email = null
)

val expected = LinkAppBarState(
navigationIcon = R.drawable.ic_link_close,
hideHeader = false,
email = null
)

assertThat(state).isEqualTo(expected)
}

@Test
fun verificationScreenShowsCorrectAppBarState() {
val state = buildLinkAppBarState(
isRootScreen = true,
currentRoute = LinkScreen.Verification.route,
email = "someone@stripe.com"
)

val expected = LinkAppBarState(
navigationIcon = R.drawable.ic_link_close,
hideHeader = false,
email = null
)

assertThat(state).isEqualTo(expected)
}

@Test
fun verificationDialogShowsCorrectAppBarState() {
val state = buildLinkAppBarState(
isRootScreen = true,
currentRoute = LinkScreen.VerificationDialog.route,
email = "someone@stripe.com"
)

val expected = LinkAppBarState(
navigationIcon = R.drawable.ic_link_close,
hideHeader = false,
email = "someone@stripe.com"
)

assertThat(state).isEqualTo(expected)
}

@Test
fun walletScreenShowsCorrectAppBarState() {
val state = buildLinkAppBarState(
isRootScreen = true,
currentRoute = LinkScreen.Wallet.route,
email = "someone@stripe.com"
)

val expected = LinkAppBarState(
navigationIcon = R.drawable.ic_link_close,
hideHeader = false,
email = "someone@stripe.com"
)

assertThat(state).isEqualTo(expected)
}

@Test
fun paymentMethodScreenShowsCorrectAppBarState() {
val state = buildLinkAppBarState(
isRootScreen = false,
currentRoute = LinkScreen.PaymentMethod.route,
email = "someone@stripe.com"
)

val expected = LinkAppBarState(
navigationIcon = R.drawable.ic_link_back,
hideHeader = true,
email = null
)

assertThat(state).isEqualTo(expected)
}

@Test
fun cardEditScreenShowsCorrectAppBarState() {
val state = buildLinkAppBarState(
isRootScreen = false,
currentRoute = LinkScreen.CardEdit.route,
email = "someone@stripe.com"
)

val expected = LinkAppBarState(
navigationIcon = R.drawable.ic_link_back,
hideHeader = true,
email = null
)

assertThat(state).isEqualTo(expected)
}

@Test
fun signupScreenShowsCorrectAppBarState() {
val state = buildLinkAppBarState(
isRootScreen = true,
currentRoute = LinkScreen.SignUp.route,
email = null
)

val expected = LinkAppBarState(
navigationIcon = R.drawable.ic_link_close,
hideHeader = false,
email = null
)

assertThat(state).isEqualTo(expected)
}

private fun buildLinkAppBarState(
isRootScreen: Boolean,
currentRoute: String?,
email: String?
): LinkAppBarState {
var state: LinkAppBarState? = null

composeTestRule.setContent {
state = rememberLinkAppBarState(isRootScreen, currentRoute, email)
}

return state ?: throw AssertionError(
"buildLinkAppBarState should not produce null result"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import com.stripe.android.link.R
import com.stripe.android.link.theme.DefaultLinkTheme
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -40,8 +41,11 @@ internal class LinkAppBarTest {
) = composeTestRule.setContent {
DefaultLinkTheme {
LinkAppBar(
email = email,
isRootScreen = true,
state = LinkAppBarState(
navigationIcon = R.drawable.ic_link_close,
hideHeader = false,
email = email
),
onButtonClick = onButtonClick
)
}
Expand Down
12 changes: 10 additions & 2 deletions link/src/main/java/com/stripe/android/link/LinkActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import androidx.navigation.NavHostController
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import com.stripe.android.link.model.AccountStatus
Expand All @@ -45,6 +46,7 @@ import com.stripe.android.link.ui.BottomSheetContent
import com.stripe.android.link.ui.LinkAppBar
import com.stripe.android.link.ui.cardedit.CardEditBody
import com.stripe.android.link.ui.paymentmethod.PaymentMethodBody
import com.stripe.android.link.ui.rememberLinkAppBarState
import com.stripe.android.link.ui.signup.SignUpBody
import com.stripe.android.link.ui.verification.VerificationBodyFullFlow
import com.stripe.android.link.ui.wallet.WalletBody
Expand Down Expand Up @@ -108,9 +110,15 @@ internal class LinkActivity : ComponentActivity() {
val linkAccount by viewModel.linkAccount.collectAsState(null)
val isOnRootScreen by isRootScreenFlow().collectAsState(true)

LinkAppBar(
email = linkAccount?.email,
val backStackEntry by navController.currentBackStackEntryAsState()
val appBarState = rememberLinkAppBarState(
isRootScreen = isOnRootScreen,
currentRoute = backStackEntry?.destination?.route,
email = linkAccount?.email
)

LinkAppBar(
state = appBarState,
onButtonClick = { viewModel.navigator.onBack() }
)

Expand Down
1 change: 1 addition & 0 deletions link/src/main/java/com/stripe/android/link/LinkScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ internal sealed class LinkScreen(
) {
object Loading : LinkScreen("Loading")
object Verification : LinkScreen("Verification")
object VerificationDialog : LinkScreen("VerificationDialog")
object Wallet : LinkScreen("Wallet")

class PaymentMethod(loadFromArgs: Boolean = false) :
Expand Down
3 changes: 1 addition & 2 deletions link/src/main/java/com/stripe/android/link/ui/Common.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ internal fun ScrollableTopLevelColumn(
content: @Composable ColumnScope.() -> Unit
) {
Box(
modifier = Modifier
.verticalScroll(rememberScrollState())
modifier = Modifier.verticalScroll(rememberScrollState())
) {
Column(
modifier = Modifier
Expand Down

0 comments on commit d8f7323

Please sign in to comment.