@@ -24,46 +24,44 @@ import androidx.compose.runtime.setValue
2424import androidx.compose.ui.Modifier
2525import androidx.compose.ui.platform.LocalDensity
2626import androidx.compose.ui.unit.Dp
27- import androidx.compose.ui.unit.dp
2827import androidx.compose.ui.viewinterop.AndroidView
2928import com.google.android.gms.wallet.button.ButtonConstants
3029import com.google.android.gms.wallet.button.ButtonOptions
3130import com.google.android.gms.wallet.button.PayButton as GmsPayButton
3231
33- enum class ButtonTheme (val value : Int ) {
34- Dark (ButtonConstants .ButtonTheme .DARK ),
35- Light (ButtonConstants .ButtonTheme .LIGHT ),
36- }
32+ private const val FULL_ALPHA = 1f
33+ private const val HALF_ALPHA = 0.5f
3734
38- enum class ButtonType (val value : Int ) {
39- Book (ButtonConstants .ButtonType .BOOK ),
40- Buy (ButtonConstants .ButtonType .BUY ),
41- Checkout (ButtonConstants .ButtonType .CHECKOUT ),
42- Donate (ButtonConstants .ButtonType .DONATE ),
43- Order (ButtonConstants .ButtonType .ORDER ),
44- Pay (ButtonConstants .ButtonType .PAY ),
45- Plain (ButtonConstants .ButtonType .PLAIN ),
46- Subscribe (ButtonConstants .ButtonType .SUBSCRIBE ),
47- PIX (ButtonConstants .ButtonType .PIX ),
48- EWALLET (ButtonConstants .ButtonType .EWALLET )
35+ private fun ButtonTheme.toAndroidValue (): Int = when (this ) {
36+ ButtonTheme .Dark -> ButtonConstants .ButtonTheme .DARK
37+ ButtonTheme .Light -> ButtonConstants .ButtonTheme .LIGHT
4938}
5039
51- private const val FULL_ALPHA = 1f
52- private const val HALF_ALPHA = 0.5f
40+ private fun ButtonType.toAndroidValue (): Int = when (this ) {
41+ ButtonType .Book -> ButtonConstants .ButtonType .BOOK
42+ ButtonType .Buy -> ButtonConstants .ButtonType .BUY
43+ ButtonType .Checkout -> ButtonConstants .ButtonType .CHECKOUT
44+ ButtonType .Donate -> ButtonConstants .ButtonType .DONATE
45+ ButtonType .Order -> ButtonConstants .ButtonType .ORDER
46+ ButtonType .Pay -> ButtonConstants .ButtonType .PAY
47+ ButtonType .Plain -> ButtonConstants .ButtonType .PLAIN
48+ ButtonType .Subscribe -> ButtonConstants .ButtonType .SUBSCRIBE
49+ ButtonType .PIX -> ButtonConstants .ButtonType .PIX
50+ ButtonType .EWALLET -> ButtonConstants .ButtonType .EWALLET
51+ }
5352
5453@Composable
55- fun PayButton (
54+ actual fun PayButton (
5655 onClick : () -> Unit ,
5756 allowedPaymentMethods : String ,
58- modifier : Modifier = Modifier ,
59- theme : ButtonTheme = ButtonTheme . Dark ,
60- type : ButtonType = ButtonType . Buy ,
61- radius : Dp = 100.dp ,
62- enabled : Boolean = true ,
63- onError : (Throwable ) -> Unit = {} ,
64- fallbackUi : @Composable (() -> Unit )? = null ,
57+ modifier : Modifier ,
58+ theme : ButtonTheme ,
59+ type : ButtonType ,
60+ radius : Dp ,
61+ enabled : Boolean ,
62+ onError : (Throwable ) -> Unit ,
63+ fallbackUi : @Composable (() -> Unit )? ,
6564) {
66-
6765 var showFallback by remember { mutableStateOf(false ) }
6866
6967 val radiusPixelValue = with (LocalDensity .current) { radius.toPx().toInt() }
@@ -76,8 +74,8 @@ fun PayButton(
7674 kotlin.runCatching {
7775 this .initialize(
7876 ButtonOptions .newBuilder()
79- .setButtonTheme(theme.value )
80- .setButtonType(type.value )
77+ .setButtonTheme(theme.toAndroidValue() )
78+ .setButtonType(type.toAndroidValue() )
8179 .setCornerRadius(radiusPixelValue)
8280 .setAllowedPaymentMethods(allowedPaymentMethods)
8381 .build()
0 commit comments