Skip to content

Commit

Permalink
Merge pull request #6 from sergejsha/release0.5
Browse files Browse the repository at this point in the history
Release 0.5
  • Loading branch information
sergejsha authored Aug 30, 2024
2 parents f7604e8 + df8739b commit 502230c
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 33 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -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`
Expand Down
6 changes: 3 additions & 3 deletions componental-compose/src/commonMain/kotlin/DialogSlot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import androidx.compose.runtime.Composable
import de.halfbit.componental.router.slot.Slot

@Composable
public fun <I : Any, C : Any> DialogSlot(
public inline fun <I : Any, C : Any> DialogSlot(
slot: Slot<I, C>,
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)
}
}
19 changes: 11 additions & 8 deletions componental-compose/src/commonMain/kotlin/ToastSlot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import androidx.compose.ui.unit.dp
import de.halfbit.componental.router.slot.Slot

@Composable
public fun <I : Any, C : Any> BoxScope.ToastSlot(
public inline fun <I : Any, C : Any> BoxScope.ToastSlot(
slot: Slot<I, C>,
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)
}
}
}
Expand All @@ -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,
)
}
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -29,6 +29,6 @@ public interface BackNavigationOwner {
}
}

public inline fun BackNavigationOwner.onNavigateBack(onNavigateBack: OnNavigateBack) {
public fun BackNavigationOwner.onNavigateBack(onNavigateBack: OnNavigateBack) {
backNavigation.register(onNavigateBack)
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public fun <R : Any> SlotRouter<R>.set(active: R?) {
route { _ -> active }
}

public fun <R : Any> SlotRouter<R>.clear() {
route { _ -> null }
}

@OptIn(ExperimentalSerializationApi::class)
public fun <Route : Any, Child : Any> ComponentContext.childSlot(
router: SlotRouter<Route>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ plugins {

allprojects {
group = "de.halfbit"
version = "0.4"
version = "0.5"
}
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 502230c

Please sign in to comment.