Skip to content

Commit

Permalink
Renaming the new register function as function to be more acurate
Browse files Browse the repository at this point in the history
  • Loading branch information
DevSrSouza committed Dec 9, 2023
1 parent 18f02b1 commit 2a8c82f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
3 changes: 2 additions & 1 deletion voyager-core/api/android/voyager-core.api
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion voyager-core/api/desktop/voyager-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,36 @@ public object ScreenLifecycleStore {
private val newOwners = ThreadSafeMap<ScreenKey, ThreadSafeMap<KType, ScreenDisposable>>()

/**
* 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 <reified T : ScreenDisposable> get(
screen: Screen,
noinline factory: (ScreenKey) -> T
): T {
return get(screen, typeOf<T>(), 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<T>(screen, factory)"),
level = DeprecationLevel.HIDDEN,
)
public inline fun <reified T : ScreenDisposable> register(
screen: Screen,
noinline factory: (ScreenKey) -> T
): T {
return register(screen, typeOf<T>(), factory) as T
return get(screen, factory)
}

@PublishedApi
internal fun <T : ScreenDisposable> register(
internal fun <T : ScreenDisposable> get(
screen: Screen,
screenDisposeListenerType: KType,
factory: (ScreenKey) -> T
Expand Down

0 comments on commit 2a8c82f

Please sign in to comment.