Skip to content

Commit

Permalink
Promoting Navigator Lifecycle APIs Experimental APIs to Stable
Browse files Browse the repository at this point in the history
  • Loading branch information
DevSrSouza committed Nov 28, 2023
1 parent 1449d98 commit a90186b
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public fun rememberScreenLifecycleOwner(
}

@Composable
@ExperimentalVoyagerApi
@InternalVoyagerApi
public fun getNavigatorScreenLifecycleProvider(screen: Screen): List<ScreenLifecycleContentProvider> {
val navigatorScreenLifecycleProvider = LocalNavigatorScreenLifecycleProvider.current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.compose.runtime.remember
import cafe.adriel.voyager.core.annotation.ExperimentalVoyagerApi
import cafe.adriel.voyager.core.annotation.InternalVoyagerApi

@ExperimentalVoyagerApi
@InternalVoyagerApi
@Composable
public fun MultipleProvideBeforeScreenContent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public inline fun <reified T : ScreenModel, reified F : ScreenModelFactory> Scre
*
* @return A new instance of [ScreenModel] or the same instance remembered by the composition
*/
@ExperimentalVoyagerApi
@Composable
public inline fun <reified T : ScreenModel> Navigator.getNavigatorScreenModel(
tag: String? = null
Expand All @@ -93,7 +92,6 @@ public inline fun <reified T : ScreenModel> Navigator.getNavigatorScreenModel(
* @param factory A function that receives a [ScreenModelFactory] and returns a [ScreenModel] created by the custom factory
* @return A new instance of [ScreenModel] or the same instance remembered by the composition
*/
@ExperimentalVoyagerApi
@Composable
public inline fun <reified T : ScreenModel, reified F : ScreenModelFactory> Navigator.getNavigatorScreenModel(
tag: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ public inline fun <reified A : Any, reified T : ScreenModel> Screen.rememberScre
rememberScreenModel(tag = tag?.toString()) { direct.provider<A, T>(tag, arg)() }
}

@ExperimentalVoyagerApi
@Composable
public inline fun <reified T : ScreenModel> Navigator.rememberNavigatorScreenModel(
tag: Any? = null
): T = with(localDI()) {
rememberNavigatorScreenModel(tag = tag?.toString()) { direct.provider<T>(tag)() }
}

@ExperimentalVoyagerApi
@Composable
public inline fun <reified A : Any, reified T : ScreenModel> Navigator.rememberNavigatorScreenModel(
tag: Any? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public inline fun <reified T : ScreenModel> Screen.getScreenModel(
return rememberScreenModel(tag = qualifier?.value) { koin.get(qualifier, parameters) }
}

@ExperimentalVoyagerApi
@Composable
public inline fun <reified T : ScreenModel> Navigator.getNavigatorScreenModel(
qualifier: Qualifier? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cafe.adriel.voyager.navigator.lifecycle
import cafe.adriel.voyager.core.annotation.ExperimentalVoyagerApi
import cafe.adriel.voyager.navigator.Navigator

@ExperimentalVoyagerApi
public interface NavigatorDisposable {
public fun onDispose(navigator: Navigator)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import kotlin.reflect.typeOf

public typealias NavigatorKey = String

@ExperimentalVoyagerApi
public object NavigatorLifecycleStore {

private val owners = ThreadSafeMap<NavigatorKey, ThreadSafeMap<KType, NavigatorDisposable>>()
Expand All @@ -17,16 +16,15 @@ public object NavigatorLifecycleStore {
* Register a NavigatorDisposable that will be called `onDispose` on the
* [navigator] leaves the Composition.
*/
@ExperimentalVoyagerApi
public inline fun <reified T : NavigatorDisposable> register(
public inline fun <reified T : NavigatorDisposable> get(
navigator: Navigator,
noinline factory: (NavigatorKey) -> T
): T {
return register(navigator, typeOf<T>(), factory) as T
return get(navigator, typeOf<T>(), factory) as T
}

@PublishedApi
internal fun <T : NavigatorDisposable> register(
internal fun <T : NavigatorDisposable> get(
navigator: Navigator,
screenDisposeListenerType: KType,
factory: (NavigatorKey) -> T
Expand All @@ -40,7 +38,6 @@ public object NavigatorLifecycleStore {
}
}

@ExperimentalVoyagerApi
public fun remove(navigator: Navigator) {
owners.remove(navigator.key)?.forEach { it.value.onDispose(navigator) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ import cafe.adriel.voyager.navigator.Navigator
import cafe.adriel.voyager.navigator.lifecycle.NavigatorDisposable
import cafe.adriel.voyager.navigator.lifecycle.NavigatorLifecycleStore

@ExperimentalVoyagerApi
@Composable
public inline fun <reified T : ScreenModel> Navigator.rememberNavigatorScreenModel(
tag: String? = null,
crossinline factory: @DisallowComposableCalls () -> T
): T {
// register the navigator lifecycle listener if is not already registered
remember(this) {
NavigatorLifecycleStore.register(this) { NavigatorScreenModelDisposer }
NavigatorLifecycleStore.get(this) { NavigatorScreenModelDisposer }
}

return remember(ScreenModelStore.getKey<T>(this.key, tag)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public fun TabNavigator(
}
}

@ExperimentalVoyagerApi
@Composable
public fun TabDisposable(navigator: TabNavigator, tabs: List<Tab>) {
DisposableEffectIgnoringConfiguration(Unit) {
Expand Down

0 comments on commit a90186b

Please sign in to comment.