PhoneState

State holder for com.ezzy.ccp.components.PhoneNumberInput.

The public surface is unchanged from previous versions — activeCountry, phoneNumber, phoneField, formattedPhone, unformattedPhone, isValid, and the same five methods — but the implementation now runs on PhoneNumberValidator and PhoneNumberFormatter instead of its own parse/format helpers.

What that buys existing callers

  • Progressive formatting. The field previously reformatted through libphonenumber's NATIONAL formatter, which only produces grouping once a number is complete. It now uses AsYouTypeFormatter, so 71 → 712 → 712 345 678 groups as the user types.

  • Granular validity. validity distinguishes "still typing" from "wrong"; isValid behaves exactly as before.

  • Correct E.164. unformattedPhone is null-safe as before but is now only populated when the number is actually parseable, instead of echoing raw input back as though it were E.164.

Hoist it as before:

val phoneState = rememberPhoneState()
PhoneNumberInput(state = phoneState)
// Later: phoneState.clearPhone(), phoneState.isValid, phoneState.toPhone()

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

The selected country in the legacy model.

Link copied to clipboard

International display form, e.g. +254 712 345 678.

Link copied to clipboard

Whether the number is valid and dialable for activeCountry.

Link copied to clipboard

The field's text and cursor. Derived from phoneNumber; never set independently.

Link copied to clipboard

Digits the user typed, with formatting stripped.

Link copied to clipboard

E.164 form, e.g. +254712345678.

Link copied to clipboard

The granular reason behind isValid.

Link copied to clipboard

The full evaluated value, including the nullable E.164 form.

Functions

Link copied to clipboard

Clears the number, leaving the country selected.

Link copied to clipboard
fun parseAndSet(value: String)

Parses a full phone string, adopting the country when the input identifies one.

Link copied to clipboard
fun selectCountry(country: Country)

Sets the active country from the canonical model.

fun selectCountry(country: Country)

Sets the active country and reformats the current number for it.

Link copied to clipboard

Sets the active country by ISO code, case-insensitively. Falls back to the default if unknown.

Link copied to clipboard
fun toPhone(): Phone

Builds a Phone snapshot of the current state.

Link copied to clipboard

Updates all derived phone state from a raw field edit.