Skip to content

Commit a8100a0

Browse files
committed
Rename CompositionLocalProvider to LocalOwnersProvider and make its saveableStateHolder parameter non-optional
Also improved the docs to make clear that the SaveableStateHolder should be hoisted. Change-Id: Ie918a80042ba3192cb04114ed9aa8fed0a0e2beb
1 parent 8c2a3d7 commit a8100a0

6 files changed

Lines changed: 14 additions & 13 deletions

File tree

‎navigation/navigation-compose/api/current.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ package androidx.navigation.compose {
2424
}
2525

2626
public final class NavBackStackEntryProviderKt {
27-
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);
27+
method @androidx.compose.runtime.Composable public static void LocalOwnersProvider(androidx.navigation.NavBackStackEntry, androidx.compose.runtime.saveable.SaveableStateHolder saveableStateHolder, kotlin.jvm.functions.Function0<kotlin.Unit> content);
2828
}
2929

3030
public final class NavGraphBuilderKt {

‎navigation/navigation-compose/api/public_plus_experimental_current.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ package androidx.navigation.compose {
2424
}
2525

2626
public final class NavBackStackEntryProviderKt {
27-
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);
27+
method @androidx.compose.runtime.Composable public static void LocalOwnersProvider(androidx.navigation.NavBackStackEntry, androidx.compose.runtime.saveable.SaveableStateHolder saveableStateHolder, kotlin.jvm.functions.Function0<kotlin.Unit> content);
2828
}
2929

3030
public final class NavGraphBuilderKt {

‎navigation/navigation-compose/api/restricted_current.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ package androidx.navigation.compose {
2424
}
2525

2626
public final class NavBackStackEntryProviderKt {
27-
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);
27+
method @androidx.compose.runtime.Composable public static void LocalOwnersProvider(androidx.navigation.NavBackStackEntry, androidx.compose.runtime.saveable.SaveableStateHolder saveableStateHolder, kotlin.jvm.functions.Function0<kotlin.Unit> content);
2828
}
2929

3030
public final class NavGraphBuilderKt {

‎navigation/navigation-compose/src/androidTest/java/androidx/navigation/compose/NavBackStackEntryProviderTest.kt‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class NavBackStackEntryProviderTest {
5252

5353
composeTestRule.setContent {
5454
val saveableStateHolder = rememberSaveableStateHolder()
55-
backStackEntry.CompositionLocalProvider(saveableStateHolder) {
55+
backStackEntry.LocalOwnersProvider(saveableStateHolder) {
5656
viewModelStoreOwner = LocalViewModelStoreOwner.current
5757
}
5858
}
@@ -68,7 +68,7 @@ class NavBackStackEntryProviderTest {
6868

6969
composeTestRule.setContent {
7070
val saveableStateHolder = rememberSaveableStateHolder()
71-
backStackEntry.CompositionLocalProvider(saveableStateHolder) {
71+
backStackEntry.LocalOwnersProvider(saveableStateHolder) {
7272
lifecycleOwner = LocalLifecycleOwner.current
7373
}
7474
}
@@ -84,7 +84,7 @@ class NavBackStackEntryProviderTest {
8484

8585
composeTestRule.setContent {
8686
val saveableStateHolder = rememberSaveableStateHolder()
87-
backStackEntry.CompositionLocalProvider(saveableStateHolder) {
87+
backStackEntry.LocalOwnersProvider(saveableStateHolder) {
8888
localSavedStateRegistryOwner = LocalSavedStateRegistryOwner.current
8989
}
9090
}
@@ -101,7 +101,7 @@ class NavBackStackEntryProviderTest {
101101

102102
restorationTester.setContent {
103103
val saveableStateHolder = rememberSaveableStateHolder()
104-
backStackEntry.CompositionLocalProvider(saveableStateHolder) {
104+
backStackEntry.LocalOwnersProvider(saveableStateHolder) {
105105
array = rememberSaveable {
106106
intArrayOf(0)
107107
}
@@ -130,7 +130,7 @@ class NavBackStackEntryProviderTest {
130130

131131
restorationTester.setContent {
132132
val saveableStateHolder = rememberSaveableStateHolder()
133-
backStackEntry.CompositionLocalProvider(saveableStateHolder) {
133+
backStackEntry.LocalOwnersProvider(saveableStateHolder) {
134134
nonSaveable = remember { initialValue }
135135
}
136136
}

‎navigation/navigation-compose/src/main/java/androidx/navigation/compose/NavBackStackEntryProvider.kt‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package androidx.navigation.compose
1919
import androidx.compose.runtime.Composable
2020
import androidx.compose.runtime.CompositionLocalProvider
2121
import androidx.compose.runtime.saveable.SaveableStateHolder
22-
import androidx.compose.runtime.saveable.rememberSaveableStateHolder
2322
import androidx.compose.ui.platform.LocalLifecycleOwner
2423
import androidx.compose.ui.platform.LocalSavedStateRegistryOwner
2524
import androidx.lifecycle.SavedStateHandle
@@ -34,12 +33,14 @@ import java.util.UUID
3433
* [LocalSavedStateRegistryOwner] to the [content] and saves the [content]'s saveable states with
3534
* the given [saveableStateHolder].
3635
*
37-
* @param saveableStateHolder The [SaveableStateHolder] that holds the saved states
36+
* @param saveableStateHolder The [SaveableStateHolder] that holds the saved states. The same
37+
* holder should be used for all [NavBackStackEntry]s in the encapsulating [Composable] and the
38+
* holder should be hoisted.
3839
* @param content The content [Composable]
3940
*/
4041
@Composable
41-
public fun NavBackStackEntry.CompositionLocalProvider(
42-
saveableStateHolder: SaveableStateHolder = rememberSaveableStateHolder(),
42+
public fun NavBackStackEntry.LocalOwnersProvider(
43+
saveableStateHolder: SaveableStateHolder,
4344
content: @Composable () -> Unit
4445
) {
4546
CompositionLocalProvider(

‎navigation/navigation-compose/src/main/java/androidx/navigation/compose/NavHost.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public fun NavHost(
129129
// while in the scope of the composable, we provide the navBackStackEntry as the
130130
// ViewModelStoreOwner and LifecycleOwner
131131
Box(modifier, propagateMinConstraints = true) {
132-
backStackEntry.CompositionLocalProvider(saveableStateHolder) {
132+
backStackEntry.LocalOwnersProvider(saveableStateHolder) {
133133
destination.content(backStackEntry)
134134
}
135135
}

0 commit comments

Comments
 (0)