Skip to content

Commit

Permalink
Fix LinkButton shape (#10094)
Browse files Browse the repository at this point in the history
* Fix LinkButton shape

* Remove surface wrapping in DefaultLinkTheme

* Test rounded corner background is correctly tinted

* Update paymentsheet/src/test/java/com/stripe/android/link/ui/LinkButtonScreenshotTest.kt

Co-authored-by: Jay Newstrom <[email protected]>

* Restore missing tests

* Update screenshot test ground truth

---------

Co-authored-by: Jay Newstrom <[email protected]>
  • Loading branch information
cttsai-stripe and jaynewstrom-stripe authored Feb 6, 2025
1 parent e4d987b commit 2095d93
Show file tree
Hide file tree
Showing 47 changed files with 51 additions and 16 deletions.
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.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ package com.stripe.android.link.theme

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.unit.dp

private val LocalColors = staticCompositionLocalOf { LinkThemeConfig.colors(false) }
Expand All @@ -21,7 +18,6 @@ internal val HorizontalPadding = 20.dp
@Composable
internal fun DefaultLinkTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
contentShape: Shape = RectangleShape,
content: @Composable () -> Unit
) {
val colors = LinkThemeConfig.colors(darkTheme)
Expand All @@ -32,11 +28,7 @@ internal fun DefaultLinkTheme(
typography = Typography,
shapes = MaterialTheme.shapes,
) {
Surface(
shape = contentShape
) {
content()
}
content()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
Expand Down Expand Up @@ -109,11 +108,10 @@ internal fun LinkButton(
modifier = modifier
.fillMaxWidth()
.defaultMinSize(minHeight = 48.dp)
.clip(LinkButtonShape)
.testTag(LinkButtonTestTag),
enabled = enabled,
elevation = ButtonDefaults.elevation(0.dp, 0.dp, 0.dp, 0.dp, 0.dp),
shape = LinkButtonShape,
elevation = ButtonDefaults.elevation(0.dp, 0.dp, 0.dp, 0.dp, 0.dp),
colors = ButtonDefaults.buttonColors(
backgroundColor = MaterialTheme.colors.primary,
disabledBackgroundColor = MaterialTheme.colors.primary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.stripe.android.link.ui.verification

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -46,10 +47,10 @@ internal fun VerificationDialogBody(
viewModel.onBack()
}
) {
DefaultLinkTheme(
contentShape = RoundedCornerShape(16.dp)
) {
VerificationScreen(viewModel)
DefaultLinkTheme {
Surface(shape = RoundedCornerShape(16.dp)) {
VerificationScreen(viewModel)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
package com.stripe.android.link.ui

import android.graphics.Color
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.stripe.android.paymentsheet.PaymentSheet
import com.stripe.android.paymentsheet.parseAppearance
import com.stripe.android.screenshottesting.FontSize
import com.stripe.android.screenshottesting.Locale
import com.stripe.android.screenshottesting.PaparazziConfigOption
import com.stripe.android.screenshottesting.PaparazziRule
import com.stripe.android.screenshottesting.SystemAppearance
import com.stripe.android.utils.screenshots.PaymentSheetAppearance.DefaultAppearance
import org.junit.Rule
import org.junit.Test

private enum class LinkButtonAppearance(private val appearance: PaymentSheet.Appearance) : PaparazziConfigOption {

TestSurfaceBackgroundAppearance(
appearance = PaymentSheet.Appearance(
colorsLight = PaymentSheet.Colors.defaultLight.copy(
surface = Color.RED,
),
colorsDark = PaymentSheet.Colors.defaultDark.copy(
surface = Color.RED,
),
),
);

override fun initialize() {
appearance.parseAppearance()
}

override fun reset() {
DefaultAppearance.appearance.parseAppearance()
}
}

internal class LinkButtonScreenshotTest {
@get:Rule
val paparazziRule = PaparazziRule(
Expand All @@ -31,6 +58,16 @@ internal class LinkButtonScreenshotTest {
.fillMaxWidth(),
)

@get:Rule
val surfacePaparazziRule = PaparazziRule(
SystemAppearance.entries,
LinkButtonAppearance.entries,
FontSize.entries,
boxModifier = Modifier
.padding(0.dp)
.fillMaxWidth(),
)

@Test
fun testNewUser() {
paparazziRule.snapshot {
Expand Down Expand Up @@ -79,4 +116,11 @@ internal class LinkButtonScreenshotTest {
LinkButton(email = "[email protected]", enabled = false, onClick = { })
}
}

@Test
fun testRoundedCornerSurfaceColor() {
surfacePaparazziRule.snapshot {
LinkButton(email = null, enabled = true, onClick = { })
}
}
}
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
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
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
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
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
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.

0 comments on commit 2095d93

Please sign in to comment.