Skip to content

Commit

Permalink
use remember to prevent a new flow from being created every time Loca…
Browse files Browse the repository at this point in the history
…lAppLanguage.current is called
  • Loading branch information
frett committed Oct 26, 2023
1 parent 1e544dc commit 92f9cd0
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.cru.godtools.base

import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.remember
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.platform.LocalContext
import java.util.Locale
Expand All @@ -15,7 +16,9 @@ object LocalAppLanguage {
val current: Locale
@Composable
get() = LocalComposition.current
?: LocalContext.current.let { it.getAppLanguageFlow().collectAsState(it.appLanguage).value }
?: LocalContext.current.let {
remember(it) { it.getAppLanguageFlow() }.collectAsState(it.appLanguage).value
}

/**
* Associates a [LocalAppLanguage] key to a value in a call to [CompositionLocalProvider].
Expand Down

0 comments on commit 92f9cd0

Please sign in to comment.