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

Fix transparent background for Link FullScreen state #10109

Merged
merged 3 commits into from
Feb 8, 2025
Merged
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
111 changes: 57 additions & 54 deletions paymentsheet/src/main/java/com/stripe/android/link/ui/LinkContent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.MaterialTheme
import androidx.compose.material.ModalBottomSheetLayout
import androidx.compose.material.ModalBottomSheetState
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -61,65 +62,67 @@ internal fun LinkContent(
) {
val coroutineScope = rememberCoroutineScope()
DefaultLinkTheme {
ModalBottomSheetLayout(
sheetContent = bottomSheetContent ?: {
// Must have some content at startup or bottom sheet crashes when
// calculating its initial size
Box(Modifier.defaultMinSize(minHeight = 1.dp)) {}
},
modifier = Modifier.fillMaxHeight(),
sheetState = sheetState,
sheetShape = MaterialTheme.linkShapes.large.copy(
bottomStart = CornerSize(0.dp),
bottomEnd = CornerSize(0.dp)
),
scrimColor = MaterialTheme.linkColors.sheetScrim
) {
Column(
modifier = Modifier
.fillMaxWidth()
Surface {
ModalBottomSheetLayout(
sheetContent = bottomSheetContent ?: {
// Must have some content at startup or bottom sheet crashes when
// calculating its initial size
Box(Modifier.defaultMinSize(minHeight = 1.dp)) {}
},
modifier = Modifier.fillMaxHeight(),
sheetState = sheetState,
sheetShape = MaterialTheme.linkShapes.large.copy(
bottomStart = CornerSize(0.dp),
bottomEnd = CornerSize(0.dp)
),
scrimColor = MaterialTheme.linkColors.sheetScrim
) {
BackHandler {
handleViewAction(LinkAction.BackPressed)
}
Column(
modifier = Modifier
.fillMaxWidth()
) {
BackHandler {
handleViewAction(LinkAction.BackPressed)
}

LinkAppBar(
state = appBarState,
onBackPressed = onBackPressed,
showBottomSheetContent = {
if (it == null) {
coroutineScope.launch {
sheetState.hide()
onUpdateSheetContent(null)
LinkAppBar(
state = appBarState,
onBackPressed = onBackPressed,
showBottomSheetContent = {
if (it == null) {
coroutineScope.launch {
sheetState.hide()
onUpdateSheetContent(null)
}
} else {
onUpdateSheetContent(it)
}
} else {
onUpdateSheetContent(it)
},
onLogoutClicked = {
handleViewAction(LinkAction.LogoutClicked)
}
},
onLogoutClicked = {
handleViewAction(LinkAction.LogoutClicked)
}
)
)

Screens(
navController = navController,
goBack = goBack,
moveToWeb = moveToWeb,
navigate = { screen ->
navigate(screen, false)
},
navigateAndClearStack = { screen ->
navigate(screen, true)
},
dismissWithResult = { result ->
dismissWithResult?.invoke(result)
},
getLinkAccount = getLinkAccount,
showBottomSheetContent = onUpdateSheetContent,
hideBottomSheetContent = {
onUpdateSheetContent(null)
}
)
Screens(
navController = navController,
goBack = goBack,
moveToWeb = moveToWeb,
navigate = { screen ->
navigate(screen, false)
},
navigateAndClearStack = { screen ->
navigate(screen, true)
},
dismissWithResult = { result ->
dismissWithResult?.invoke(result)
},
getLinkAccount = getLinkAccount,
showBottomSheetContent = onUpdateSheetContent,
hideBottomSheetContent = {
onUpdateSheetContent(null)
}
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.stripe.android.link.ui

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.ModalBottomSheetState
import androidx.compose.material.ModalBottomSheetValue
import androidx.compose.material.Text
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp
import androidx.lifecycle.ViewModelStore
import androidx.lifecycle.ViewModelStoreOwner
import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner
import androidx.navigation.compose.rememberNavController
import com.stripe.android.paymentsheet.R
import com.stripe.android.screenshottesting.FontSize
import com.stripe.android.screenshottesting.PaparazziRule
import com.stripe.android.screenshottesting.SystemAppearance
import org.junit.Rule
import org.junit.Test

internal class LinkContentScreenshotTest {
@get:Rule
val paparazziRule = PaparazziRule(
SystemAppearance.entries,
FontSize.entries,
boxModifier = Modifier
.padding(0.dp)
.fillMaxWidth(),
)

@OptIn(ExperimentalMaterialApi::class)
@Test
fun testLinkContentScreenHasOpaqueBackground() {
paparazziRule.snapshot {
val viewModelStoreOwner = object : ViewModelStoreOwner {
override val viewModelStore = ViewModelStore()
}
CompositionLocalProvider(LocalViewModelStoreOwner provides viewModelStoreOwner) {
val navController = rememberNavController()
Box {
Text(
modifier = Modifier
.align(Alignment.TopStart),
text = "Hello!"
)
LinkContent(
navController = navController,
appBarState = LinkAppBarState(
navigationIcon = R.drawable.stripe_link_close,
showHeader = false,
showOverflowMenu = false,
email = null
),
Comment on lines +45 to +58
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Text will be visible in background if this surface gets removed
com stripe android link ui_LinkContentScreenshotTest_testContent DarkTheme,LargeFont

Copy link
Collaborator

Choose a reason for hiding this comment

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

nice!

sheetState = ModalBottomSheetState(
initialValue = ModalBottomSheetValue.Hidden,
density = Density(1f)
),
onUpdateSheetContent = {},
bottomSheetContent = null,
handleViewAction = {},
navigate = { _, _ -> },
dismissWithResult = null,
getLinkAccount = { null },
onBackPressed = {},
moveToWeb = {},
goBack = {}
)
}
}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading