Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Navigation] Introduce NavBackStackEntry#provideToCompositionLocals #175

Prev Previous commit
Next Next commit
Rename provideToCompositionLocals to CompositionLocalProvider to adhe…
…re with Compose API guidelines

Change-Id: I2bd33a90236033933168411e70c6fbdb77e0abfe
jossiwolf committed May 6, 2021
commit 8c2a3d7fa0a6e361e53e90c7cf9208aa00046e6f
2 changes: 1 addition & 1 deletion navigation/navigation-compose/api/current.txt
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ package androidx.navigation.compose {
}

public final class NavBackStackEntryProviderKt {
method @androidx.compose.runtime.Composable public static void provideToCompositionLocals(androidx.navigation.NavBackStackEntry, optional androidx.compose.runtime.saveable.SaveableStateHolder saveableStateHolder, kotlin.jvm.functions.Function0<kotlin.Unit> content);
method @androidx.compose.runtime.Composable public static void CompositionLocalProvider(androidx.navigation.NavBackStackEntry, optional androidx.compose.runtime.saveable.SaveableStateHolder saveableStateHolder, kotlin.jvm.functions.Function0<kotlin.Unit> content);
}

public final class NavGraphBuilderKt {
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ package androidx.navigation.compose {
}

public final class NavBackStackEntryProviderKt {
method @androidx.compose.runtime.Composable public static void provideToCompositionLocals(androidx.navigation.NavBackStackEntry, optional androidx.compose.runtime.saveable.SaveableStateHolder saveableStateHolder, kotlin.jvm.functions.Function0<kotlin.Unit> content);
method @androidx.compose.runtime.Composable public static void CompositionLocalProvider(androidx.navigation.NavBackStackEntry, optional androidx.compose.runtime.saveable.SaveableStateHolder saveableStateHolder, kotlin.jvm.functions.Function0<kotlin.Unit> content);
}

public final class NavGraphBuilderKt {
2 changes: 1 addition & 1 deletion navigation/navigation-compose/api/restricted_current.txt
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ package androidx.navigation.compose {
}

public final class NavBackStackEntryProviderKt {
method @androidx.compose.runtime.Composable public static void provideToCompositionLocals(androidx.navigation.NavBackStackEntry, optional androidx.compose.runtime.saveable.SaveableStateHolder saveableStateHolder, kotlin.jvm.functions.Function0<kotlin.Unit> content);
method @androidx.compose.runtime.Composable public static void CompositionLocalProvider(androidx.navigation.NavBackStackEntry, optional androidx.compose.runtime.saveable.SaveableStateHolder saveableStateHolder, kotlin.jvm.functions.Function0<kotlin.Unit> content);
}

public final class NavGraphBuilderKt {
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ class NavBackStackEntryProviderTest {

composeTestRule.setContent {
val saveableStateHolder = rememberSaveableStateHolder()
backStackEntry.provideToCompositionLocals(saveableStateHolder) {
backStackEntry.CompositionLocalProvider(saveableStateHolder) {
viewModelStoreOwner = LocalViewModelStoreOwner.current
}
}
@@ -68,7 +68,7 @@ class NavBackStackEntryProviderTest {

composeTestRule.setContent {
val saveableStateHolder = rememberSaveableStateHolder()
backStackEntry.provideToCompositionLocals(saveableStateHolder) {
backStackEntry.CompositionLocalProvider(saveableStateHolder) {
lifecycleOwner = LocalLifecycleOwner.current
}
}
@@ -84,7 +84,7 @@ class NavBackStackEntryProviderTest {

composeTestRule.setContent {
val saveableStateHolder = rememberSaveableStateHolder()
backStackEntry.provideToCompositionLocals(saveableStateHolder) {
backStackEntry.CompositionLocalProvider(saveableStateHolder) {
localSavedStateRegistryOwner = LocalSavedStateRegistryOwner.current
}
}
@@ -101,7 +101,7 @@ class NavBackStackEntryProviderTest {

restorationTester.setContent {
val saveableStateHolder = rememberSaveableStateHolder()
backStackEntry.provideToCompositionLocals(saveableStateHolder) {
backStackEntry.CompositionLocalProvider(saveableStateHolder) {
array = rememberSaveable {
intArrayOf(0)
}
@@ -130,7 +130,7 @@ class NavBackStackEntryProviderTest {

restorationTester.setContent {
val saveableStateHolder = rememberSaveableStateHolder()
backStackEntry.provideToCompositionLocals(saveableStateHolder) {
backStackEntry.CompositionLocalProvider(saveableStateHolder) {
nonSaveable = remember { initialValue }
}
}
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@

package androidx.navigation.compose

import android.annotation.SuppressLint
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.saveable.SaveableStateHolder
@@ -38,9 +37,8 @@ import java.util.UUID
* @param saveableStateHolder The [SaveableStateHolder] that holds the saved states
* @param content The content [Composable]
*/
@SuppressLint("ComposableNaming")
@Composable
public fun NavBackStackEntry.provideToCompositionLocals(
public fun NavBackStackEntry.CompositionLocalProvider(
saveableStateHolder: SaveableStateHolder = rememberSaveableStateHolder(),
content: @Composable () -> Unit
) {
@@ -49,9 +47,7 @@ public fun NavBackStackEntry.provideToCompositionLocals(
LocalLifecycleOwner provides this,
LocalSavedStateRegistryOwner provides this
) {
saveableStateHolder.SaveableStateProvider {
content()
}
saveableStateHolder.SaveableStateProvider(content)
}
}

Original file line number Diff line number Diff line change
@@ -129,7 +129,7 @@ public fun NavHost(
// while in the scope of the composable, we provide the navBackStackEntry as the
// ViewModelStoreOwner and LifecycleOwner
Box(modifier, propagateMinConstraints = true) {
backStackEntry.provideToCompositionLocals(saveableStateHolder) {
backStackEntry.CompositionLocalProvider(saveableStateHolder) {
destination.content(backStackEntry)
}
}