Skip to content

Commit c924e9f

Browse files
committed
Add KDoc to core utils
1 parent 1cccdcc commit c924e9f

File tree

7 files changed

+41
-4
lines changed

7 files changed

+41
-4
lines changed

composed-core/src/main/kotlin/com/w2sv/composed/core/DisposableEffect.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import androidx.lifecycle.LifecycleOwner
1010
import androidx.lifecycle.compose.LocalLifecycleOwner
1111

1212
/**
13-
* Run the given [callback] inside of a [LifecycleEventObserver] launched as a [DisposableEffect], when the [lifecycleOwner] reaches the given [lifecycleEvent] and clean up the observer when [lifecycleOwner], [key1] or [key2] changes or if [OnLifecycleEvent] leaves the composition.
13+
* Run the given [callback] inside of a [LifecycleEventObserver] launched as a [DisposableEffect], when the [lifecycleOwner] reaches the
14+
* given [lifecycleEvent] and clean up the observer when [lifecycleOwner], [key1] or [key2] changes or if [OnLifecycleEvent] leaves the
15+
* composition.
16+
*
1417
* @see DisposableEffect
1518
*/
1619
@Composable
@@ -38,6 +41,12 @@ fun OnLifecycleEvent(
3841
}
3942
}
4043

44+
/**
45+
* Executes [callback] when the current composition leaves the composition.
46+
*
47+
* This is a convenience wrapper around `DisposableEffect(Unit)` that ensures
48+
* the latest provided [callback] is invoked during disposal.
49+
*/
4150
@Composable
4251
fun OnDispose(callback: () -> Unit) {
4352
val currentCallback by rememberUpdatedState(newValue = callback)

composed-core/src/main/kotlin/com/w2sv/composed/core/LaunchedEffect.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ fun <T> CollectLatestFromFlow(
4141
}
4242
}
4343

44+
/**
45+
* Runs [callback] whenever [value] or one of the optional keys changes.
46+
*
47+
* This behaves like a [LaunchedEffect] tied to [value], ensuring the latest
48+
* [callback] is invoked with the updated value.
49+
*/
4450
@Composable
4551
fun <T> OnChange(
4652
value: T,

composed-core/src/main/kotlin/com/w2sv/composed/core/Orientation.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ import androidx.compose.runtime.Composable
55
import androidx.compose.runtime.ReadOnlyComposable
66
import androidx.compose.ui.platform.LocalConfiguration
77

8+
/**
9+
* @return `true` when the current configuration is in landscape orientation.
10+
*/
811
val isLandscapeModeActive: Boolean
912
@Composable
1013
@ReadOnlyComposable
1114
get() = LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE
1215

16+
/**
17+
* @return `true` when the current configuration is in portrait orientation.
18+
*/
1319
val isPortraitModeActive: Boolean
1420
@Composable
1521
@ReadOnlyComposable

composed-core/src/main/kotlin/com/w2sv/composed/core/Saver.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ fun nullableColorSaver() =
2929
/**
3030
* [listSaver] for an optional object of type [Original], that enables you to omit the handling of the case in which the state value == null. Only the saving and restoring of the non-null instance needs to be handled.
3131
*/
32-
fun <Original, Saveable> nullableListSaver(
33-
saveNonNull: SaverScope.(value: Original) -> List<Saveable>,
34-
restoreNonNull: (list: List<Saveable>) -> Original?
32+
fun <Original, Savable> nullableListSaver(
33+
saveNonNull: SaverScope.(value: Original) -> List<Savable>,
34+
restoreNonNull: (list: List<Savable>) -> Original?
3535
): Saver<Original?, Any> =
3636
listSaver(
3737
save = { original ->

composed-core/src/main/kotlin/com/w2sv/composed/core/extensions/DimensionConversion.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,25 @@ import androidx.compose.runtime.ReadOnlyComposable
55
import androidx.compose.ui.platform.LocalDensity
66
import androidx.compose.ui.unit.Dp
77

8+
/**
9+
* Converts this [Dp] value to raw pixels using the current [LocalDensity].
10+
*/
811
@Composable
912
@ReadOnlyComposable
1013
fun Dp.toPx() =
1114
with(LocalDensity.current) { this@toPx.toPx() }
1215

16+
/**
17+
* Converts this pixel value to [Dp] using the current [LocalDensity].
18+
*/
1319
@Composable
1420
@ReadOnlyComposable
1521
fun Int.toDp() =
1622
with(LocalDensity.current) { this@toDp.toDp() }
1723

24+
/**
25+
* Converts this pixel value to [Dp] using the current [LocalDensity].
26+
*/
1827
@Composable
1928
@ReadOnlyComposable
2029
fun Float.toDp() =

composed-core/src/main/kotlin/com/w2sv/composed/core/extensions/Map.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package com.w2sv.composed.core.extensions
33
import androidx.compose.runtime.mutableStateMapOf
44
import androidx.compose.runtime.snapshots.SnapshotStateMap
55

6+
/**
7+
* Converts this [Map] to a [SnapshotStateMap].
8+
*/
69
fun <K, V> Map<K, V>.toMutableStateMap(): SnapshotStateMap<K, V> =
710
mutableStateMapOf<K, V>()
811
.apply { putAll(this@toMutableStateMap) }

composed-core/src/main/kotlin/com/w2sv/composed/core/extensions/TimeInterpolator.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@ package com.w2sv.composed.core.extensions
33
import android.animation.TimeInterpolator
44
import androidx.compose.animation.core.Easing
55

6+
/**
7+
* Converts a [TimeInterpolator] from the View animation system into a Compose [Easing].
8+
* This allows existing interpolators to be reused in Compose animation specs.
9+
*/
610
fun TimeInterpolator.toEasing() =
711
Easing { getInterpolation(it) }

0 commit comments

Comments
 (0)