CountryListIndex

A lookup from a country (or an initial letter) to its row index in the flat LazyColumn that CountryList emits.

The translation is the whole point. CountryList renders a list of CountrySections, each optionally preceded by a sticky header, into one flat lazy list — so the nth country is not at lazy index n, and anything that wants to scroll to a specific country has to account for every header and every preceding section. Doing that arithmetic at each call site is how off-by-one scroll bugs get written; doing it once, here, from the same sections the list was built from, is how they do not.

Build one with rememberCountryListIndex.

Properties

Link copied to clipboard

The initial letters actually present in the list, in display order. Only letters with at least one country appear — a rail that offers Q and then does nothing when tapped is worse than a rail that omits it.

Functions

Link copied to clipboard
fun lazyIndexOf(country: Country): Int?

Convenience for lazyIndexOf by country.

fun lazyIndexOf(letter: Char): Int?

The lazy-list index of the first country starting with letter, or null if there is none.

fun lazyIndexOf(iso2Code: String): Int?

The lazy-list index of iso2Code's row, or null when that country is not in the list.