From 2a8c82f2c66ea959e5b3ac294bad6154a3b9f081 Mon Sep 17 00:00:00 2001 From: DevSrSouza Date: Tue, 28 Nov 2023 18:33:48 -0300 Subject: [PATCH] Renaming the new register function as function to be more acurate --- voyager-core/api/android/voyager-core.api | 3 ++- voyager-core/api/desktop/voyager-core.api | 2 +- .../core/lifecycle/ScreenLifecycleStore.kt | 26 ++++++++++++++++--- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/voyager-core/api/android/voyager-core.api b/voyager-core/api/android/voyager-core.api index 1ee00524..7558ab7f 100644 --- a/voyager-core/api/android/voyager-core.api +++ b/voyager-core/api/android/voyager-core.api @@ -1,6 +1,7 @@ public final class cafe/adriel/voyager/androidx/AndroidScreenLifecycleOwner : androidx/lifecycle/HasDefaultViewModelProviderFactory, androidx/lifecycle/LifecycleOwner, androidx/lifecycle/ViewModelStoreOwner, androidx/savedstate/SavedStateRegistryOwner, cafe/adriel/voyager/core/lifecycle/ScreenLifecycleOwner { public static final field $stable I public static final field Companion Lcafe/adriel/voyager/androidx/AndroidScreenLifecycleOwner$Companion; + public synthetic fun ProvideBeforeScreenContent (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function0;Landroidx/compose/runtime/Composer;I)V public fun ProvideBeforeScreenContent (Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;I)V public fun getDefaultViewModelCreationExtras ()Landroidx/lifecycle/viewmodel/CreationExtras; public fun getDefaultViewModelProviderFactory ()Landroidx/lifecycle/ViewModelProvider$Factory; @@ -151,7 +152,7 @@ public abstract interface class cafe/adriel/voyager/core/lifecycle/ScreenLifecyc public final class cafe/adriel/voyager/core/lifecycle/ScreenLifecycleStore { public static final field $stable I public static final field INSTANCE Lcafe/adriel/voyager/core/lifecycle/ScreenLifecycleStore; - public final fun register (Lcafe/adriel/voyager/core/screen/Screen;Lkotlin/reflect/KType;Lkotlin/jvm/functions/Function1;)Lcafe/adriel/voyager/core/lifecycle/ScreenDisposable; + public final fun get (Lcafe/adriel/voyager/core/screen/Screen;Lkotlin/reflect/KType;Lkotlin/jvm/functions/Function1;)Lcafe/adriel/voyager/core/lifecycle/ScreenDisposable; public final fun remove (Lcafe/adriel/voyager/core/screen/Screen;)V } diff --git a/voyager-core/api/desktop/voyager-core.api b/voyager-core/api/desktop/voyager-core.api index 2a63cc87..88d4c8ef 100644 --- a/voyager-core/api/desktop/voyager-core.api +++ b/voyager-core/api/desktop/voyager-core.api @@ -134,7 +134,7 @@ public abstract interface class cafe/adriel/voyager/core/lifecycle/ScreenLifecyc public final class cafe/adriel/voyager/core/lifecycle/ScreenLifecycleStore { public static final field $stable I public static final field INSTANCE Lcafe/adriel/voyager/core/lifecycle/ScreenLifecycleStore; - public final fun register (Lcafe/adriel/voyager/core/screen/Screen;Lkotlin/reflect/KType;Lkotlin/jvm/functions/Function1;)Lcafe/adriel/voyager/core/lifecycle/ScreenDisposable; + public final fun get (Lcafe/adriel/voyager/core/screen/Screen;Lkotlin/reflect/KType;Lkotlin/jvm/functions/Function1;)Lcafe/adriel/voyager/core/lifecycle/ScreenDisposable; public final fun remove (Lcafe/adriel/voyager/core/screen/Screen;)V } diff --git a/voyager-core/src/commonMain/kotlin/cafe/adriel/voyager/core/lifecycle/ScreenLifecycleStore.kt b/voyager-core/src/commonMain/kotlin/cafe/adriel/voyager/core/lifecycle/ScreenLifecycleStore.kt index 22c253eb..f43e5dee 100644 --- a/voyager-core/src/commonMain/kotlin/cafe/adriel/voyager/core/lifecycle/ScreenLifecycleStore.kt +++ b/voyager-core/src/commonMain/kotlin/cafe/adriel/voyager/core/lifecycle/ScreenLifecycleStore.kt @@ -12,18 +12,36 @@ public object ScreenLifecycleStore { private val newOwners = ThreadSafeMap>() /** - * Register a ScreenDisposable that will be called `onDispose` on the - * [screen] leaves the Navigation stack. + * Get current for screen or register a ScreenDisposable resulted by + * [factory] that will be called `onDispose` on the [screen] leaves + * the Navigation stack. */ + public inline fun get( + screen: Screen, + noinline factory: (ScreenKey) -> T + ): T { + return get(screen, typeOf(), factory) as T + } + + /** + * Get current for screen or register a ScreenDisposable resulted by + * [factory] that will be called `onDispose` on the [screen] leaves + * the Navigation stack. + */ + @Deprecated( + message = "Use `get` instead. Will be removed in 1.1.0.", + replaceWith = ReplaceWith("ScreenLifecycleStore.get(screen, factory)"), + level = DeprecationLevel.HIDDEN, + ) public inline fun register( screen: Screen, noinline factory: (ScreenKey) -> T ): T { - return register(screen, typeOf(), factory) as T + return get(screen, factory) } @PublishedApi - internal fun register( + internal fun get( screen: Screen, screenDisposeListenerType: KType, factory: (ScreenKey) -> T