Phone State
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
NATIONALformatter, which only produces grouping once a number is complete. It now usesAsYouTypeFormatter, so71→712→712 345 678groups 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()Properties
The selected country in the legacy model.
International display form, e.g. +254 712 345 678.
Whether the number is valid and dialable for activeCountry.
The field's text and cursor. Derived from phoneNumber; never set independently.
Digits the user typed, with formatting stripped.
E.164 form, e.g. +254712345678.
The granular reason behind isValid.
The full evaluated value, including the nullable E.164 form.
Functions
Clears the number, leaving the country selected.
Parses a full phone string, adopting the country when the input identifies one.
Sets the active country from the canonical model.
Sets the active country and reformats the current number for it.
Sets the active country by ISO code, case-insensitively. Falls back to the default if unknown.
Updates all derived phone state from a raw field edit.