Merge pull request #312 from FunkyMuse/master

refactor: remove unnecessary code
This commit is contained in:
Tibor Kaputa 2023-07-31 10:02:20 +02:00 committed by GitHub
commit 50af3bd75f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 38 deletions

View File

@ -7,6 +7,7 @@ import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LifecycleEventEffect
import com.google.accompanist.systemuicontroller.rememberSystemUiController import com.google.accompanist.systemuicontroller.rememberSystemUiController
fun Context.getActivity(): Activity { fun Context.getActivity(): Activity {
@ -30,10 +31,8 @@ fun TransparentSystemBars() {
fun <T : Any> onEventValue(event: Lifecycle.Event = Lifecycle.Event.ON_START, value: () -> T): T { fun <T : Any> onEventValue(event: Lifecycle.Event = Lifecycle.Event.ON_START, value: () -> T): T {
val rememberLatestUpdateState by rememberUpdatedState(newValue = value) val rememberLatestUpdateState by rememberUpdatedState(newValue = value)
var rememberedValue by remember { mutableStateOf(value()) } var rememberedValue by remember { mutableStateOf(value()) }
OnLifecycleEvent { lifecycleEvent -> LifecycleEventEffect(event = event) {
if (lifecycleEvent == event) { rememberedValue = rememberLatestUpdateState()
rememberedValue = rememberLatestUpdateState()
}
} }
return rememberedValue return rememberedValue
} }

View File

@ -1,27 +0,0 @@
package com.simplemobiletools.calculator.compose.extensions
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
@Composable
fun OnLifecycleEvent(
lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
onEvent: (event: Lifecycle.Event) -> Unit
) {
val currentOnEvent by rememberUpdatedState(onEvent)
DisposableEffect(lifecycleOwner) {
val observer = LifecycleEventObserver { _, event ->
currentOnEvent(event)
}
lifecycleOwner.lifecycle.addObserver(observer)
onDispose {
lifecycleOwner.lifecycle.removeObserver(observer)
}
}
}

View File

@ -7,7 +7,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView import androidx.compose.ui.platform.LocalView
import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle
import com.simplemobiletools.calculator.compose.extensions.OnLifecycleEvent import androidx.lifecycle.compose.LifecycleEventEffect
import com.simplemobiletools.calculator.compose.theme.model.Theme.Companion.systemDefaultMaterialYou import com.simplemobiletools.calculator.compose.theme.model.Theme.Companion.systemDefaultMaterialYou
@Composable @Composable
@ -27,8 +27,8 @@ fun AppThemeSurface(
) )
) )
} }
OnLifecycleEvent { event -> LifecycleEventEffect(event = Lifecycle.Event.ON_START) {
if (event == Lifecycle.Event.ON_START && !view.isInEditMode) { if (!view.isInEditMode) {
currentTheme = getTheme(context = context, materialYouTheme = materialYouTheme) currentTheme = getTheme(context = context, materialYouTheme = materialYouTheme)
} }
} }

View File

@ -6,12 +6,12 @@ ksp = "1.9.0-1.0.12"
#Androidx #Androidx
androidx-customView = "1.2.0-alpha02" androidx-customView = "1.2.0-alpha02"
androidx-customViewPooling = "1.0.0" androidx-customViewPooling = "1.0.0"
androidx-lifecycle = "2.6.1" androidx-lifecycle = "2.7.0-alpha01"
#Compose #Compose
composeActivity = "1.8.0-alpha06" composeActivity = "1.8.0-alpha06"
compose = "1.6.0-alpha01" compose = "1.6.0-alpha02"
composeCompiler = "1.5.0" composeCompiler = "1.5.1"
composeMaterial3 = "1.2.0-alpha03" composeMaterial3 = "1.2.0-alpha04"
accompanist = "0.31.5-beta" accompanist = "0.31.5-beta"
#AutoFitTextView #AutoFitTextView
autofittextview = "0.2.1" autofittextview = "0.2.1"