Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.boltreactnativesdk

import android.content.Context
import android.graphics.Outline
import android.view.View
import android.view.ViewOutlineProvider
import android.widget.FrameLayout
import com.facebook.react.bridge.ReactContext
import com.facebook.react.uimanager.UIManagerHelper
Expand All @@ -20,25 +17,16 @@ class GooglePayButtonView(context: Context) : FrameLayout(context) {

private var currentButtonType: String = "plain"
private var currentButtonTheme: String = "dark"
private var cornerRadiusPx: Float = 0f
private var cornerRadiusPx: Int = 0

init {
rebuildButton()
}

fun updateBorderRadius(radiusPx: Float) {
fun updateBorderRadius(radiusPx: Int) {
if (radiusPx == cornerRadiusPx) return
cornerRadiusPx = radiusPx
if (radiusPx > 0f) {
outlineProvider = object : ViewOutlineProvider() {
override fun getOutline(view: View, outline: Outline) {
outline.setRoundRect(0, 0, view.width, view.height, radiusPx)
}
}
clipToOutline = true
} else {
outlineProvider = ViewOutlineProvider.BACKGROUND
clipToOutline = false
}
rebuildButton()
}

fun updateButtonType(type: String) {
Expand All @@ -60,6 +48,7 @@ class GooglePayButtonView(context: Context) : FrameLayout(context) {
val options = ButtonOptions.newBuilder()
.setButtonType(mapButtonType(currentButtonType))
.setButtonTheme(mapButtonTheme(currentButtonTheme))
.setCornerRadius(cornerRadiusPx)
.setAllowedPaymentMethods(ALLOWED_PAYMENT_METHODS)
.build()
button.initialize(options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class GooglePayButtonViewManager :

@ReactProp(name = "borderRadius", defaultFloat = 0f)
override fun setBorderRadius(view: GooglePayButtonView, borderRadius: Float) {
view.updateBorderRadius(PixelUtil.toPixelFromDIP(borderRadius))
val radiusPx = PixelUtil.toPixelFromDIP(borderRadius).toInt().coerceAtLeast(0)
view.updateBorderRadius(radiusPx)
}
}
1 change: 1 addition & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ const AddCardScreen = () => {
onComplete={handleGooglePayComplete}
onError={handleWalletError}
style={styles.walletButton}
borderRadius={25}
/>
)}

Expand Down
Loading