FIx AppPreferences must be singleton
This commit is contained in:
parent
62fb6496e7
commit
ca1737acb8
1 changed files with 5 additions and 1 deletions
|
|
@ -1,5 +1,6 @@
|
|||
package org.fnives.android.qrcodetransfer.storage
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
|
|
@ -55,8 +56,11 @@ val LocalAppPreferences = compositionLocalOf<AppPreferences> {
|
|||
error("CompositionLocal LocalIntentText not present")
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private var appPreferences: AppPreferences? = null
|
||||
|
||||
@Composable
|
||||
fun LocalAppPreferencesProvider(context: Context, content: @Composable () -> Unit) {
|
||||
val preferences = remember(context) { AppPreferences(context) }
|
||||
val preferences = appPreferences ?: AppPreferences(context.applicationContext).also { appPreferences = it }
|
||||
CompositionLocalProvider(LocalAppPreferences provides preferences, content = content)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue