
The Card Input Component is used to collect card information from the user. It consists of three fields: PAN, Expiry Date, and CVV. The component also includes a field for the cardholder’s name.
Parameters
| Parameter | Description |
|---|---|
backgroundRadius |
(optional): The radius of the background in the card input. Default value is 0.dp. |
labelLocation |
(optional): The location of the label in the card input. Default value is LabelLocation.TOP. |
labelTextSize |
(optional): The size of the label text in the card input. Default value is 14.sp. |
labelTextFontWeight |
(optional): The font weight of the label text in the card input. Default value is ComponentFontWeight.NORMAL. |
labelComponent |
(optional): The component to display the label in the card input. Default value is a Text component. |
fieldTextSize |
(optional): The size of the field text in the card input. Default value is 14.sp. |
fieldTextFontWeight |
(optional): The font weight of the field text in the card input. Default value is ComponentFontWeight.NORMAL. |
showCardHolderName |
(optional): If true, the cardholder’s name field will be shown. Default is true. |
modifier |
(optional): Modifier for styling the card input component. |
For other uses beside Compose you can use the CardInputStyleState to define the styling of it.
Example Usage
Compose Multiplatform
CardInput(
backgroundRadius = 8.dp,
labelLocation = LabelLocation.TOP,
labelTextSize = 16.sp,
labelTextFontWeight = ComponentFontWeight.BOLD,
labelComponent = { label, labelTextStyle ->
Text(
text = label,
style = labelTextStyle,
modifier = Modifier.padding(vertical = 8.dp)
)
}
fieldTextSize = 16.sp,
fieldTextFontWeight = ComponentFontWeight.NORMAL,
showCardHolderName = true,
modifier = Modifier.padding(16.dp)
)
Android View
<com.accesspaysuite.mobilesdk.ui.card.CardInputView
android:id="@+id/cardInput"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
val cardInput = findViewById<CardInputView>(R.id.cardInput)
cardInput.init(state = CardInputStyleState())
iOS
Create the Controller Representable
Example
import SwiftUI
import mobilesdk
struct CardInputControllerRepresentable: UIViewControllerRepresentable {
@Binding var state: CardInputStyleState
init(state: Binding<CardInputStyleState>) {
self._state = state
}
func makeUIViewController(context: Context) -> UIViewController {
return CardInputController().make()
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
CardInputController().update(state: state)
}
}
Create the CardInput View
Example
import SwiftUI
import mobilesdk
struct CardInput: View {
@Binding var state: CardInputStyleState
init(state: Binding<CardInputStyleState>) {
self._state = state
}
var body: some View {
CardInputControllerRepresentable(
state: $state
)
.frame(height: 400)
.ignoresSafeArea(.keyboard)
.onTapGesture {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
}
}
Use the CardInput View
Example
import SwiftUI
import mobilesdk
struct PaymentView: View {
@State private var styleState = CardInputStyleState()
var body: some View {
CardInput(
state: $styleState
)
}
}