Skip to content

Commit d0ec2e0

Browse files
committed
Allow router to consume custom serializers
1 parent 69d8bb7 commit d0ec2e0

5 files changed

Lines changed: 14 additions & 9 deletions

File tree

decompose-router/api/android/decompose-router.api

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public final class io/github/xxfast/decompose/router/pages/Router : com/arkivano
5151
public final class io/github/xxfast/decompose/router/pages/RouterKt {
5252
public static final fun pagesOf ([Ljava/lang/Object;I)Lcom/arkivanov/decompose/router/pages/Pages;
5353
public static synthetic fun pagesOf$default ([Ljava/lang/Object;IILjava/lang/Object;)Lcom/arkivanov/decompose/router/pages/Pages;
54-
public static final fun rememberRouter (Lkotlin/reflect/KClass;Ljava/lang/Object;ZLkotlin/jvm/functions/Function0;Landroidx/compose/runtime/Composer;II)Lio/github/xxfast/decompose/router/pages/Router;
54+
public static final fun rememberRouter (Lkotlin/reflect/KClass;Ljava/lang/Object;ZLkotlinx/serialization/KSerializer;Lkotlin/jvm/functions/Function0;Landroidx/compose/runtime/Composer;II)Lio/github/xxfast/decompose/router/pages/Router;
5555
}
5656

5757
public final class io/github/xxfast/decompose/router/slot/RoutedContentKt {
@@ -68,7 +68,7 @@ public final class io/github/xxfast/decompose/router/slot/Router : com/arkivanov
6868
}
6969

7070
public final class io/github/xxfast/decompose/router/slot/RouterKt {
71-
public static final fun rememberRouter (Lkotlin/reflect/KClass;Ljava/lang/Object;ZLkotlin/jvm/functions/Function0;Landroidx/compose/runtime/Composer;II)Lio/github/xxfast/decompose/router/slot/Router;
71+
public static final fun rememberRouter (Lkotlin/reflect/KClass;Ljava/lang/Object;ZLkotlinx/serialization/KSerializer;Lkotlin/jvm/functions/Function0;Landroidx/compose/runtime/Composer;II)Lio/github/xxfast/decompose/router/slot/Router;
7272
}
7373

7474
public final class io/github/xxfast/decompose/router/stack/RoutedContentKt {
@@ -84,6 +84,6 @@ public final class io/github/xxfast/decompose/router/stack/Router : com/arkivano
8484
}
8585

8686
public final class io/github/xxfast/decompose/router/stack/RouterKt {
87-
public static final fun rememberRouter (Lkotlin/reflect/KClass;Ljava/lang/Object;ZLkotlin/jvm/functions/Function0;Landroidx/compose/runtime/Composer;II)Lio/github/xxfast/decompose/router/stack/Router;
87+
public static final fun rememberRouter (Lkotlin/reflect/KClass;Ljava/lang/Object;ZLkotlinx/serialization/KSerializer;Lkotlin/jvm/functions/Function0;Landroidx/compose/runtime/Composer;II)Lio/github/xxfast/decompose/router/stack/Router;
8888
}
8989

decompose-router/api/desktop/decompose-router.api

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public final class io/github/xxfast/decompose/router/pages/Router : com/arkivano
5050
public final class io/github/xxfast/decompose/router/pages/RouterKt {
5151
public static final fun pagesOf ([Ljava/lang/Object;I)Lcom/arkivanov/decompose/router/pages/Pages;
5252
public static synthetic fun pagesOf$default ([Ljava/lang/Object;IILjava/lang/Object;)Lcom/arkivanov/decompose/router/pages/Pages;
53-
public static final fun rememberRouter (Lkotlin/reflect/KClass;Ljava/lang/Object;ZLkotlin/jvm/functions/Function0;Landroidx/compose/runtime/Composer;II)Lio/github/xxfast/decompose/router/pages/Router;
53+
public static final fun rememberRouter (Lkotlin/reflect/KClass;Ljava/lang/Object;ZLkotlinx/serialization/KSerializer;Lkotlin/jvm/functions/Function0;Landroidx/compose/runtime/Composer;II)Lio/github/xxfast/decompose/router/pages/Router;
5454
}
5555

5656
public final class io/github/xxfast/decompose/router/slot/RoutedContentKt {
@@ -67,7 +67,7 @@ public final class io/github/xxfast/decompose/router/slot/Router : com/arkivanov
6767
}
6868

6969
public final class io/github/xxfast/decompose/router/slot/RouterKt {
70-
public static final fun rememberRouter (Lkotlin/reflect/KClass;Ljava/lang/Object;ZLkotlin/jvm/functions/Function0;Landroidx/compose/runtime/Composer;II)Lio/github/xxfast/decompose/router/slot/Router;
70+
public static final fun rememberRouter (Lkotlin/reflect/KClass;Ljava/lang/Object;ZLkotlinx/serialization/KSerializer;Lkotlin/jvm/functions/Function0;Landroidx/compose/runtime/Composer;II)Lio/github/xxfast/decompose/router/slot/Router;
7171
}
7272

7373
public final class io/github/xxfast/decompose/router/stack/RoutedContentKt {
@@ -83,6 +83,6 @@ public final class io/github/xxfast/decompose/router/stack/Router : com/arkivano
8383
}
8484

8585
public final class io/github/xxfast/decompose/router/stack/RouterKt {
86-
public static final fun rememberRouter (Lkotlin/reflect/KClass;Ljava/lang/Object;ZLkotlin/jvm/functions/Function0;Landroidx/compose/runtime/Composer;II)Lio/github/xxfast/decompose/router/stack/Router;
86+
public static final fun rememberRouter (Lkotlin/reflect/KClass;Ljava/lang/Object;ZLkotlinx/serialization/KSerializer;Lkotlin/jvm/functions/Function0;Landroidx/compose/runtime/Composer;II)Lio/github/xxfast/decompose/router/stack/Router;
8787
}
8888

decompose-router/src/commonMain/kotlin/io/github/xxfast/decompose/router/pages/Router.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import io.github.xxfast.decompose.asState
1414
import io.github.xxfast.decompose.router.getOrCreate
1515
import io.github.xxfast.decompose.key
1616
import kotlinx.serialization.InternalSerializationApi
17+
import kotlinx.serialization.KSerializer
1718
import kotlinx.serialization.Serializable
1819
import kotlinx.serialization.serializerOrNull
1920
import kotlin.reflect.KClass
@@ -30,6 +31,7 @@ fun <C: @Serializable Any> rememberRouter(
3031
type: KClass<C>,
3132
key: Any = type.key,
3233
handleBackButton: Boolean = true,
34+
serializer: KSerializer<C>? = type.serializerOrNull(),
3335
initialPages: () -> Pages<C>,
3436
): Router<C> {
3537
val routerContext: RouterContext = LocalRouterContext.current
@@ -41,7 +43,7 @@ fun <C: @Serializable Any> rememberRouter(
4143
val stack: State<ChildPages<C, RouterContext>> = routerContext
4244
.childPages(
4345
source = navigation,
44-
serializer = type.serializerOrNull(),
46+
serializer = serializer,
4547
initialPages = initialPages,
4648
key = routerKey,
4749
handleBackButton = handleBackButton,

decompose-router/src/commonMain/kotlin/io/github/xxfast/decompose/router/slot/Router.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import io.github.xxfast.decompose.router.LocalRouterContext
1212
import io.github.xxfast.decompose.router.RouterContext
1313
import io.github.xxfast.decompose.router.getOrCreate
1414
import kotlinx.serialization.InternalSerializationApi
15+
import kotlinx.serialization.KSerializer
1516
import kotlinx.serialization.Serializable
1617
import kotlinx.serialization.serializerOrNull
1718
import kotlin.reflect.KClass
@@ -27,6 +28,7 @@ fun <C : @Serializable Any> rememberRouter(
2728
type: KClass<C>,
2829
key: Any = type.key,
2930
handleBackButton: Boolean = true,
31+
serializer: KSerializer<C>? = type.serializerOrNull(),
3032
initialConfiguration: () -> C?,
3133
): Router<C> {
3234
val routerContext: RouterContext = LocalRouterContext.current
@@ -38,7 +40,7 @@ fun <C : @Serializable Any> rememberRouter(
3840
val slot: State<ChildSlot<C, RouterContext>> = routerContext
3941
.childSlot(
4042
source = navigation,
41-
serializer = type.serializerOrNull(),
43+
serializer = serializer,
4244
initialConfiguration = initialConfiguration,
4345
key = routerKey,
4446
handleBackButton = handleBackButton,

decompose-router/src/commonMain/kotlin/io/github/xxfast/decompose/router/stack/Router.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ fun <C: @Serializable Any> rememberRouter(
4848
type: KClass<C>,
4949
key: Any = type.key,
5050
handleBackButton: Boolean = true,
51+
serializer: KSerializer<C>? = type.serializerOrNull(),
5152
initialStack: () -> List<C>,
5253
): Router<C> {
5354
val routerContext: RouterContext = LocalRouterContext.current
@@ -59,7 +60,7 @@ fun <C: @Serializable Any> rememberRouter(
5960
val stack: State<ChildStack<C, RouterContext>> = routerContext
6061
.childStack(
6162
source = navigation,
62-
serializer = type.serializerOrNull(),
63+
serializer = serializer,
6364
initialStack = initialStack,
6465
key = routerKey,
6566
handleBackButton = handleBackButton,

0 commit comments

Comments
 (0)