Skip to content

Instantly share code, notes, and snippets.

// A remember() that can survive recompositions and config changes but not process death.
@Composable
inline fun <T: Any> rememberRetained(
key: String = currentCompositeKeyHash.toString(36), // Copied from rememberSaveable()
crossinline init: @DisallowComposableCalls () -> T
): T {
if (retainedStore[key] == null) {
retainedStore[key] = init()
}
val activity = LocalContext.current.findActivity()