Skip to content

Commit

Permalink
Add playground support for vertical mode. (#8414)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaynewstrom-stripe committed May 9, 2024
1 parent a65f507 commit b0175a1
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Brush
Expand Down Expand Up @@ -96,7 +95,6 @@ internal class AppearanceBottomSheetDialogFragment : BottomSheetDialogFragment()
}
}

@OptIn(ExperimentalComposeUiApi::class)
@Composable
private fun AppearancePicker(
currentAppearance: PaymentSheet.Appearance,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.stripe.android.paymentsheet.example.playground.settings

import com.stripe.android.paymentsheet.PaymentSheet
import com.stripe.android.paymentsheet.example.playground.PlaygroundState
import com.stripe.android.paymentsheet.example.playground.activity.AppearanceStore

internal object LayoutSettingsDefinition : BooleanSettingsDefinition(
key = "layout",
displayName = "Vertical Mode",
defaultValue = false,
) {
override fun configure(
value: Boolean,
configurationBuilder: PaymentSheet.Configuration.Builder,
playgroundState: PlaygroundState,
configurationData: PlaygroundSettingDefinition.PaymentSheetConfigurationData
) {
configurationBuilder.appearance(
AppearanceStore.state.copy(
layout = if (value) {
PaymentSheet.Appearance.Layout.Vertical
} else {
PaymentSheet.Appearance.Layout.Horizontal
}
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ internal class PlaygroundSettings private constructor(
AllowsRemovalOfLastSavedPaymentMethodSettingsDefinition,
PaymentMethodOrderSettingsDefinition,
ExternalPaymentMethodSettingsDefinition,
LayoutSettingsDefinition,
IntegrationTypeSettingsDefinition,
)

Expand Down
4 changes: 2 additions & 2 deletions paymentsheet/api/paymentsheet.api
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ public final class com/stripe/android/paymentsheet/PaymentSheet$Appearance : and
public final fun component3 ()Lcom/stripe/android/paymentsheet/PaymentSheet$Shapes;
public final fun component4 ()Lcom/stripe/android/paymentsheet/PaymentSheet$Typography;
public final fun component5 ()Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButton;
public final fun copy (Lcom/stripe/android/paymentsheet/PaymentSheet$Colors;Lcom/stripe/android/paymentsheet/PaymentSheet$Colors;Lcom/stripe/android/paymentsheet/PaymentSheet$Shapes;Lcom/stripe/android/paymentsheet/PaymentSheet$Typography;Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButton;)Lcom/stripe/android/paymentsheet/PaymentSheet$Appearance;
public static synthetic fun copy$default (Lcom/stripe/android/paymentsheet/PaymentSheet$Appearance;Lcom/stripe/android/paymentsheet/PaymentSheet$Colors;Lcom/stripe/android/paymentsheet/PaymentSheet$Colors;Lcom/stripe/android/paymentsheet/PaymentSheet$Shapes;Lcom/stripe/android/paymentsheet/PaymentSheet$Typography;Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButton;ILjava/lang/Object;)Lcom/stripe/android/paymentsheet/PaymentSheet$Appearance;
public final fun copy (Lcom/stripe/android/paymentsheet/PaymentSheet$Colors;Lcom/stripe/android/paymentsheet/PaymentSheet$Colors;Lcom/stripe/android/paymentsheet/PaymentSheet$Shapes;Lcom/stripe/android/paymentsheet/PaymentSheet$Typography;Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButton;Lcom/stripe/android/paymentsheet/PaymentSheet$Appearance$Layout;)Lcom/stripe/android/paymentsheet/PaymentSheet$Appearance;
public static synthetic fun copy$default (Lcom/stripe/android/paymentsheet/PaymentSheet$Appearance;Lcom/stripe/android/paymentsheet/PaymentSheet$Colors;Lcom/stripe/android/paymentsheet/PaymentSheet$Colors;Lcom/stripe/android/paymentsheet/PaymentSheet$Shapes;Lcom/stripe/android/paymentsheet/PaymentSheet$Typography;Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButton;Lcom/stripe/android/paymentsheet/PaymentSheet$Appearance$Layout;ILjava/lang/Object;)Lcom/stripe/android/paymentsheet/PaymentSheet$Appearance;
public fun describeContents ()I
public fun equals (Ljava/lang/Object;)Z
public final fun getColors (Z)Lcom/stripe/android/paymentsheet/PaymentSheet$Colors;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.stripe.android.paymentsheet

import androidx.annotation.RestrictTo

@RequiresOptIn(message = "Layout support is beta. It may be changed in the future without notice.")
@Retention(AnnotationRetention.BINARY)
@Target(
AnnotationTarget.CLASS,
AnnotationTarget.FUNCTION,
AnnotationTarget.PROPERTY
)
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
annotation class ExperimentalPaymentSheetLayoutApi
Original file line number Diff line number Diff line change
Expand Up @@ -700,43 +700,97 @@ class PaymentSheet internal constructor(
}

@Parcelize
data class Appearance(
data class Appearance internal constructor(
/**
* Describes the colors used while the system is in light mode.
*/
val colorsLight: Colors = Colors.defaultLight,
val colorsLight: Colors,

/**
* Describes the colors used while the system is in dark mode.
*/
val colorsDark: Colors = Colors.defaultDark,
val colorsDark: Colors,

/**
* Describes the appearance of shapes.
*/
val shapes: Shapes = Shapes.default,
val shapes: Shapes,

/**
* Describes the typography used for text.
*/
val typography: Typography = Typography.default,
val typography: Typography,

/**
* Describes the appearance of the primary button (e.g., the "Pay" button).
*/
val primaryButton: PrimaryButton = PrimaryButton()
val primaryButton: PrimaryButton,

internal val layout: Layout,
) : Parcelable {
constructor() : this(
colorsLight = Colors.defaultLight,
colorsDark = Colors.defaultDark,
shapes = Shapes.default,
typography = Typography.default,
primaryButton = PrimaryButton(),
layout = Layout.default,
)

constructor(
/**
* Describes the colors used while the system is in light mode.
*/
colorsLight: Colors = Colors.defaultLight,

/**
* Describes the colors used while the system is in dark mode.
*/
colorsDark: Colors = Colors.defaultDark,

/**
* Describes the appearance of shapes.
*/
shapes: Shapes = Shapes.default,

/**
* Describes the typography used for text.
*/
typography: Typography = Typography.default,

/**
* Describes the appearance of the primary button (e.g., the "Pay" button).
*/
primaryButton: PrimaryButton = PrimaryButton(),
) : this(
colorsLight = colorsLight,
colorsDark = colorsDark,
shapes = shapes,
typography = typography,
primaryButton = primaryButton,
layout = Layout.default,
)

fun getColors(isDark: Boolean): Colors {
return if (isDark) colorsDark else colorsLight
}

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
enum class Layout {
Horizontal, Vertical;

internal companion object {
internal val default: Layout = Horizontal
}
}

class Builder {
private var colorsLight = Colors.defaultLight
private var colorsDark = Colors.defaultDark
private var shapes = Shapes.default
private var typography = Typography.default
private var primaryButton: PrimaryButton = PrimaryButton()
private var layout: Layout = Layout.default

fun colorsLight(colors: Colors) = apply {
this.colorsLight = colors
Expand All @@ -758,8 +812,14 @@ class PaymentSheet internal constructor(
this.primaryButton = primaryButton
}

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@ExperimentalPaymentSheetLayoutApi
fun layout(layout: Layout) = apply {
this.layout = layout
}

fun build(): Appearance {
return Appearance(colorsLight, colorsDark, shapes, typography, primaryButton)
return Appearance(colorsLight, colorsDark, shapes, typography, primaryButton, layout)
}
}
}
Expand Down

0 comments on commit b0175a1

Please sign in to comment.