diff --git a/README.md b/README.md index 9df44fd..107b313 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,8 @@ In `gradle/libs.versions.toml` ```toml [versions] -kotlin = "2.0.0" -componental = "0.4" +kotlin = "2.0.20" +componental = "0.5" [libraries] componental = { module = "de.halfbit:componental", version.ref = "componental" } @@ -74,6 +74,7 @@ dependencies { # Release Notes +* 0.5 Improve Toast API and UI, bump to Kotlin 2.0.20 * 0.4 Refine Stack and Slot API and their implementations * 0.3 Add BackNavigation * 0.2 Module `componental` is exposed as API from `componental.compose` diff --git a/componental-compose/src/commonMain/kotlin/DialogSlot.kt b/componental-compose/src/commonMain/kotlin/DialogSlot.kt index bea8a8f..b80dc42 100644 --- a/componental-compose/src/commonMain/kotlin/DialogSlot.kt +++ b/componental-compose/src/commonMain/kotlin/DialogSlot.kt @@ -4,12 +4,12 @@ import androidx.compose.runtime.Composable import de.halfbit.componental.router.slot.Slot @Composable -public fun DialogSlot( +public inline fun DialogSlot( slot: Slot, - content: @Composable (route: I, child: C) -> Unit, + content: @Composable (child: C) -> Unit, ) { val active = slot.active if (active != null) { - content(active.route, active.child) + content(active.child) } } diff --git a/componental-compose/src/commonMain/kotlin/ToastSlot.kt b/componental-compose/src/commonMain/kotlin/ToastSlot.kt index 258fb7d..f750170 100644 --- a/componental-compose/src/commonMain/kotlin/ToastSlot.kt +++ b/componental-compose/src/commonMain/kotlin/ToastSlot.kt @@ -13,14 +13,15 @@ import androidx.compose.ui.unit.dp import de.halfbit.componental.router.slot.Slot @Composable -public fun BoxScope.ToastSlot( +public inline fun BoxScope.ToastSlot( slot: Slot, - content: @Composable (id: I, child: C) -> Unit, + modifier: Modifier = Modifier, + crossinline content: @Composable (child: C) -> Unit, ) { val active = slot.active if (active != null) { - ToastSurface { - content(active.route, active.child) + ToastSurface(modifier = modifier) { + content(active.child) } } } @@ -32,10 +33,11 @@ public fun BoxScope.ToastSurface( ) { Surface( modifier = modifier - .padding(8.dp) + .padding(horizontal = 32.dp) + .padding(bottom = 24.dp) .align(Alignment.BottomCenter), shape = RoundedCornerShape(8.dp), - shadowElevation = 2.dp, + shadowElevation = 6.dp, content = content, ) } @@ -85,12 +87,13 @@ private fun Toast( modifier = Modifier .background(backgroundColor) .fillMaxWidth() - .padding(vertical = 8.dp) .padding(start = 16.dp, end = 8.dp), verticalAlignment = Alignment.CenterVertically, ) { Text( - modifier = Modifier.weight(1f), + modifier = Modifier + .weight(1f) + .padding(vertical = 12.dp), text = text, style = MaterialTheme.typography.bodyMedium, color = color, diff --git a/componental/src/commonMain/kotlin/de/halfbit/componental/back/BackNavigationOwner.kt b/componental/src/commonMain/kotlin/de/halfbit/componental/back/BackNavigationOwner.kt index 7f676b7..1043958 100644 --- a/componental/src/commonMain/kotlin/de/halfbit/componental/back/BackNavigationOwner.kt +++ b/componental/src/commonMain/kotlin/de/halfbit/componental/back/BackNavigationOwner.kt @@ -4,7 +4,7 @@ package de.halfbit.componental.back import de.halfbit.componental.lifecycle.Lifecycle public interface BackNavigationOwner { - public val backNavigation : BackNavigation + public val backNavigation: BackNavigation public companion object { public fun create(lifecycle: Lifecycle): BackNavigationOwner = @@ -29,6 +29,6 @@ public interface BackNavigationOwner { } } -public inline fun BackNavigationOwner.onNavigateBack(onNavigateBack: OnNavigateBack) { +public fun BackNavigationOwner.onNavigateBack(onNavigateBack: OnNavigateBack) { backNavigation.register(onNavigateBack) } \ No newline at end of file diff --git a/componental/src/commonMain/kotlin/de/halfbit/componental/restorator/Restorator.kt b/componental/src/commonMain/kotlin/de/halfbit/componental/restorator/Restorator.kt index 097380e..5596d6a 100644 --- a/componental/src/commonMain/kotlin/de/halfbit/componental/restorator/Restorator.kt +++ b/componental/src/commonMain/kotlin/de/halfbit/componental/restorator/Restorator.kt @@ -1,5 +1,6 @@ package de.halfbit.componental.restorator +import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.builtins.ByteArraySerializer import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.protobuf.ProtoBuf @@ -13,23 +14,19 @@ public interface Restorator { public fun storeAll(): ByteArray } +@OptIn(ExperimentalSerializationApi::class) private class DefaultRestorator( bytes: ByteArray?, ) : Restorator { - private val consumable: ConsumableList private val storableRouters = mutableListOf<() -> ByteArray?>() - - init { - consumable = - ConsumableList( - bytes?.let { - ProtoBuf - .decodeFromByteArray(routersSerializer, bytes) - .map { if (it.isEmpty()) null else it } - .toMutableList() - } - ) - } + private val consumable: ConsumableList = ConsumableList( + bytes?.let { + ProtoBuf + .decodeFromByteArray(routersSerializer, bytes) + .map { if (it.isEmpty()) null else it } + .toMutableList() + } + ) override fun restoreRoute(): ByteArray? = consumable.consume() @@ -59,8 +56,8 @@ private class ConsumableList( if (position >= bytes.size) { throw IllegalStateException( "Restore for a not stored child requested." + - " Stored children count: ${bytes.size}," + - " requested position: $position" + " Stored children count: ${bytes.size}," + + " requested position: $position" ) } return bytes[position].also { diff --git a/componental/src/commonMain/kotlin/de/halfbit/componental/router/slot/SlotRouter.kt b/componental/src/commonMain/kotlin/de/halfbit/componental/router/slot/SlotRouter.kt index 4b47ab0..4c11460 100644 --- a/componental/src/commonMain/kotlin/de/halfbit/componental/router/slot/SlotRouter.kt +++ b/componental/src/commonMain/kotlin/de/halfbit/componental/router/slot/SlotRouter.kt @@ -28,6 +28,10 @@ public fun SlotRouter.set(active: R?) { route { _ -> active } } +public fun SlotRouter.clear() { + route { _ -> null } +} + @OptIn(ExperimentalSerializationApi::class) public fun ComponentContext.childSlot( router: SlotRouter, diff --git a/convention-plugins/src/main/kotlin/root.publication.gradle.kts b/convention-plugins/src/main/kotlin/root.publication.gradle.kts index d1398d7..1406b18 100644 --- a/convention-plugins/src/main/kotlin/root.publication.gradle.kts +++ b/convention-plugins/src/main/kotlin/root.publication.gradle.kts @@ -4,5 +4,5 @@ plugins { allprojects { group = "de.halfbit" - version = "0.4" + version = "0.5" } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4f84116..991e8b8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,12 +1,12 @@ [versions] agp = "8.2.2" -kotlin = "2.0.0" +kotlin = "2.0.20" android-sdk-min = "24" android-sdk-compile = "34" compose-plugin = "1.6.11" kotlinx-coroutines = "1.8.1" kotlinx-atomicfu = "0.25.0" -kotlinx-serialization = "1.7.1" +kotlinx-serialization = "1.7.2" androidx-lifecycle = "2.8.4" androidx-savedstate = "1.2.1" androidx-activity = "1.9.1"