Package-level declarations

Types

Link copied to clipboard

Horizontal position of an OTP component. START and END follow the surrounding layout direction, so they mirror in RTL. Entries may be added in future versions; handle unknown values with an else branch when matching exhaustively.

Link copied to clipboard

Colors of an OTP button. content should have at least 4.5:1 contrast against container (WCAG 1.4.3); violations are logged and listed in contrastWarnings, never thrown, so brand colors remain usable. The disabled pair is exempt from WCAG contrast requirements.

Colors of an OTP button, created with OtpButtonDefaults.colors. content should have at least 4.5:1 contrast against container (WCAG 1.4.3); violations are logged once and listed in contrastWarnings, never thrown, so brand colors remain usable. The disabled pair is exempt.

Link copied to clipboard

Default styles for OtpVerifyButton and OtpResendButton.

Default styles for OtpVerifyButton and OtpResendButton. From Swift, call for example OtpButtonDefaults.shared.style().

Link copied to clipboard

Style of OtpVerifyButton and OtpResendButton, created with OtpButtonDefaults.style. minHeight is raised to 48dp. A disabled button always draws at least a 1dp border so its state is not shown by color alone. colors null (the default) follows the system light or dark theme; pass OtpButtonDefaults.colors or OtpButtonDefaults.darkColors to force one.

Style of OtpVerifyButton and OtpResendButton, created with OtpButtonDefaults.style. minHeight is in points at the default text size, scales with Dynamic Type, and is raised to

Link copied to clipboard

Characters an OtpState.code may contain.

Link copied to clipboard

WCAG contrast checks shared by the Android and iOS components.

Link copied to clipboard

WCAG contrast requirement that a color pair is checked against.

Link copied to clipboard

Remaining resend time, passed to OtpResendAccessibility.countdownDescription so hosts can localize with plural rules.

Link copied to clipboard
class OtpField(state: OtpState, accessibility: OtpFieldAccessibility, doneButtonTitle: String)

One-time-code input built on UIKit. Visually it is a row of cells; for VoiceOver and Voice Control it is one text field (the cells, separators, placeholder, and error text are not accessibility elements). Embed view in SwiftUI with a UIViewRepresentable and keep this object alive, for example in the coordinator.

Link copied to clipboard
class OtpFieldAccessibility(val label: String, val errorMessage: String, val progressDescription: (OtpProgress) -> String, val inputRejectedMessage: (OtpInputRejection) -> String)

Required, localized accessibility text for an OTP field. There are deliberately no defaults so the component cannot be shown without it.

Link copied to clipboard

Colors of an OtpField, created with OtpFieldDefaults.colors. Checked pairs (opaque colors only; masked OtpMask.FilledCell cells use the border colors):

Colors of an OtpField, created with OtpFieldDefaults.colors. Use dynamic colors (the defaults are) so dark mode and Increase Contrast keep working. Checked pairs, resolved for the trait collection in use (opaque colors only; masked OtpMask.FilledCell cells use the border colors):

Link copied to clipboard

Default styles for OtpField.

Default styles for OtpField. From Swift, call for example OtpFieldDefaults.shared.style(); Kotlin default arguments are not visible to Swift, so the zero-argument functions return the defaults.

Link copied to clipboard

Visual style of an OtpField.

Visual style of an OtpField.

Link copied to clipboard

A multi-digit input (paste, autofill, keyboard suggestion) that was rejected because it did not contain exactly expectedDigitCount digits. Only the counts are available, never the digits, so they cannot end up in logs. A rejection usually means that the configured OtpLength differs from the code length of the host's backend.

Link copied to clipboard
Link copied to clipboard

Supported one-time code lengths, in characters.

Link copied to clipboard
sealed interface OtpMask

Visual masking of entered characters. Masking also switches the Android keyboard to a password keyboard, marks the field as a password for screen readers, and blocks copy, so visual and assistive-technology privacy stay consistent. Entries may be added in future versions; handle unknown values with an else branch.

Link copied to clipboard

Progress of the entered code, passed to OtpFieldAccessibility.progressDescription so hosts can localize with plural rules. A value object rather than primitive lambda parameters so the callback stays idiomatic when called from Swift.

Link copied to clipboard
class OtpResendAccessibility(val label: String, val countdownDescription: (OtpCountdown) -> String)

Required, localized accessibility text for an OTP resend button.

Link copied to clipboard

"Resend code" button with a countdown. The host owns the timer and sets secondsRemaining; the button is disabled while it is above zero. The countdown text is the visible text and therefore also the accessible name (WCAG 2.5.3 Label in Name). There is no per-second announcement; verify the VoiceOver behavior on a device.

Link copied to clipboard
class OtpState

Immutable state of one OTP field.

Link copied to clipboard
class OtpVerifyAccessibility(val label: String)

Required, localized accessibility text for an OTP verify button; label is also the visible text.

Link copied to clipboard

Button that verifies a complete code. It is enabled only while state is complete and isEnabled is true. The host owns verification: onVerify receives the code and should not also be triggered by OtpField.onComplete for the same code unless it de-duplicates. Use the same alignment as OtpField to keep them aligned. The visible text is also the accessible name. Embed view in SwiftUI with a UIViewRepresentable and keep this object alive.

Properties

Link copied to clipboard

Saves an OtpState for rememberSaveable, so a partly entered code survives configuration changes and process death:

Functions

Link copied to clipboard
fun OtpField(state: OtpState, onStateChange: (OtpState) -> Unit, onComplete: (code: String) -> Unit, accessibility: OtpFieldAccessibility, modifier: Modifier = Modifier, enabled: Boolean = true, style: OtpFieldStyle = OtpFieldDefaults.style(), mask: OtpMask = OtpMask.None, hapticFeedbackOnError: Boolean = true, alignment: OtpAlignment = OtpAlignment.CENTER, onInputRejected: (OtpInputRejection) -> Unit = {})

One-time-code input that exposes a single logical text field to screen readers while drawing the digits as decorative cells (cells, group separators and placeholders are not in the accessibility tree).

Link copied to clipboard
fun OtpResendButton(secondsRemaining: Int, onResend: () -> Unit, accessibility: OtpResendAccessibility, modifier: Modifier = Modifier, alignment: OtpAlignment = OtpAlignment.CENTER, style: OtpButtonStyle = OtpButtonDefaults.style())

"Resend code" button with a countdown. The host owns the timer and passes secondsRemaining; the button is disabled while it is above zero. The remaining time is the button text, which is also its accessible name (WCAG 2.5.3 Label in Name). There is no live region and no per-second announcement; verify the screen-reader behaviour on a device.

Link copied to clipboard
fun OtpVerifyButton(state: OtpState, onVerify: (code: String) -> Unit, accessibility: OtpVerifyAccessibility, modifier: Modifier = Modifier, enabled: Boolean = true, alignment: OtpAlignment = OtpAlignment.CENTER, style: OtpButtonStyle = OtpButtonDefaults.style())

Button that verifies a complete code. It is enabled only while state is complete and enabled is true. The host owns verification: onVerify receives the code and should not also be triggered by onComplete of OtpField for the same code unless it de-duplicates. Pass the same alignment as OtpField to keep them aligned.