DefaultRecentCountryStore

Persistent RecentCountryStore with an in-memory MutableStateFlow mirror.

Backed by the platform's own small key-value store — SharedPreferences on Android, NSUserDefaults on iOS. Create it with DefaultRecentCountryStore(context) on Android, DefaultRecentCountryStore() on iOS, or rememberDefaultRecentCountryStore from common code.

Why not DataStore

This is a UI library, and a handful of ISO codes is the smallest possible piece of state. Adding androidx.datastore — plus its Okio and protobuf transitive graph — to every consumer's app to store ten two-letter strings is not a trade worth making. Both platform stores are already there, so the default store costs nothing to depend on.

The interface is what matters for hosts who disagree: an app that already uses DataStore can implement RecentCountryStore over its own store in a dozen lines and pass it in. Nothing in the library depends on this class.

All disk work happens on Dispatchers.IO; reads after construction are served from memory, so the recents section renders on the first frame instead of appearing a moment later.

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open suspend override fun clear()

Forgets everything. Wire this to the host's "clear data" affordance.

Link copied to clipboard
open override fun observeRecentCountryCodes(): Flow<List<String>>

Emits the recent ISO alpha-2 codes, most recent first, whenever they change.

Link copied to clipboard
open suspend override fun recordSelection(countryCode: String)

Records that the user selected countryCode, moving it to the front.