File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed
composed/src/main/kotlin/com/w2sv/composed Expand file tree Collapse file tree 3 files changed +26
-1
lines changed File renamed without changes.
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ package com.w2sv.composed
33import android.annotation.SuppressLint
44import androidx.compose.runtime.Composable
55import androidx.compose.runtime.LaunchedEffect
6+ import androidx.compose.runtime.getValue
7+ import androidx.compose.runtime.rememberUpdatedState
68import kotlinx.coroutines.flow.Flow
79import kotlinx.coroutines.flow.FlowCollector
810import kotlinx.coroutines.flow.collectLatest
@@ -37,4 +39,18 @@ fun <T> CollectLatestFromFlow(
3739 LaunchedEffect (flow, key1, key2) {
3840 flow.collectLatest(action)
3941 }
42+ }
43+
44+ @Composable
45+ fun <T > OnChange (
46+ value : T ,
47+ key1 : Any? = null,
48+ key2 : Any? = null,
49+ callback : suspend (T ) -> Unit
50+ ) {
51+ val updatedCallback by rememberUpdatedState(newValue = callback)
52+
53+ LaunchedEffect (value, key1, key2) {
54+ updatedCallback(value)
55+ }
4056}
Original file line number Diff line number Diff line change @@ -25,4 +25,13 @@ inline fun Modifier.thenIf(
2525 condition : Boolean ,
2626 onTrue : Modifier .() -> Modifier ,
2727): Modifier =
28- thenIf(condition = condition, onFalse = { this }, onTrue = onTrue)
28+ thenIf(condition = condition, onFalse = { this }, onTrue = onTrue)
29+
30+ /* *
31+ * A convenience function that invokes the Modifier receiver function [onNotNull] which depends on an optional [instance], if that [instance] is not null.
32+ */
33+ inline fun <T > Modifier.thenIfNotNull (
34+ instance : T ? ,
35+ onNotNull : Modifier .(T ) -> Modifier ,
36+ ): Modifier =
37+ instance?.let { onNotNull(it) } ? : this
You can’t perform that action at this time.
0 commit comments