Skip to content

Commit d97eee2

Browse files
authored
Replace internal platform-specific helpers with unified HostDefaultProviderImpl (JetBrains#2874)
- Removed `findDefaultNavigationEventDispatcherOwner` and `findComposeDefaultViewModelStoreOwner`. - Deprecated and replaced obsolete CompositionLocals with lifecycle-runtime-compose equivalents. - Updated dependencies to align with `navigationevent-compose` and `lifecycle-viewmodel-compose`. - Simplified host default provider initialization through `HostDefaultProviderImpl`. Describe proposed changes and the issue being fixed Fixes https://youtrack.jetbrains.com/issue/CMP-9752 ## Release Notes N/A
1 parent 4a33f21 commit d97eee2

15 files changed

Lines changed: 85 additions & 108 deletions

File tree

compose/foundation/foundation/build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ androidXMultiplatform {
5454
configureDarwinFlags()
5555

5656
sourceSets {
57+
def navigationEventVersion = project.findProperty('artifactRedirection.version.androidx.navigationevent')
5758
commonMain.dependencies {
5859
api("androidx.collection:collection:1.5.0")
5960
api(project(":compose:animation:animation"))
@@ -67,9 +68,9 @@ androidXMultiplatform {
6768
commonTest.dependencies {
6869
implementation(libs.kotlinTest)
6970
implementation(libs.kotlinCoroutinesTest)
70-
implementation("androidx.navigationevent:navigationevent:1.0.1")
71-
implementation("androidx.navigationevent:navigationevent-testing:1.0.1")
72-
implementation("org.jetbrains.androidx.navigationevent:navigationevent-compose:1.0.1")
71+
implementation("androidx.navigationevent:navigationevent:$navigationEventVersion")
72+
implementation("androidx.navigationevent:navigationevent-testing:$navigationEventVersion")
73+
implementation("androidx.navigationevent:navigationevent-compose:$navigationEventVersion")
7374
}
7475

7576
androidMain.dependencies {

compose/material/material/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ androidXMultiplatform {
6666
implementation(libs.kotlinTest)
6767
implementation(project(":compose:ui:ui-test"))
6868
implementation("androidx.navigationevent:navigationevent-testing:$navigationEventVersion")
69-
implementation("org.jetbrains.androidx.navigationevent:navigationevent-compose:1.0.1")
69+
implementation("androidx.navigationevent:navigationevent-compose:$navigationEventVersion")
7070
}
7171

7272
androidMain.dependencies {

compose/material3/adaptive/adaptive-navigation3/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ androidXMultiplatform {
4747
defaultPlatform(PlatformIdentifier.ANDROID)
4848

4949
sourceSets {
50+
def navigationEventVersion = project.findProperty('artifactRedirection.version.androidx.navigationevent')
5051
commonMain.dependencies {
5152
api(project(":compose:material3:adaptive:adaptive-navigation"))
5253
api(project(":navigation3:navigation3-ui"))
5354
implementation("androidx.collection:collection:1.5.0")
54-
implementation("org.jetbrains.androidx.navigationevent:navigationevent-compose:1.0.1")
55+
implementation("androidx.navigationevent:navigationevent-compose:$navigationEventVersion")
5556
}
5657

5758
androidMain.dependencies {

compose/material3/material3/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ androidXMultiplatform {
124124
implementation(project(":compose:runtime:runtime"))
125125
def navigationEventVersion = project.findProperty('artifactRedirection.version.androidx.navigationevent')
126126
implementation("androidx.navigationevent:navigationevent-testing:$navigationEventVersion")
127-
implementation("org.jetbrains.androidx.navigationevent:navigationevent-compose:1.0.1")
127+
implementation("androidx.navigationevent:navigationevent-compose:$navigationEventVersion")
128128
}
129129
}
130130

compose/ui/ui-backhandler/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,13 @@ androidXMultiplatform {
5858
}
5959
}
6060

61+
def navigationEventVersion = project.findProperty('artifactRedirection.version.androidx.navigationevent')
62+
6163
// TODO: Align naming: nonAndroidMain
6264
jbMain {
6365
dependsOn(commonMain)
6466
dependencies {
65-
implementation("androidx.navigationevent:navigationevent:1.0.1")
67+
implementation("androidx.navigationevent:navigationevent-compose:$navigationEventVersion")
6668
}
6769
}
6870

compose/ui/ui-backhandler/src/jbMain/kotlin/androidx/compose/ui/backhandler/BackHandler.jb.kt

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,11 @@ import androidx.compose.runtime.DisposableEffect
2323
import androidx.compose.runtime.currentCompositeKeyHashCode
2424
import androidx.compose.runtime.remember
2525
import androidx.compose.runtime.rememberCoroutineScope
26-
import androidx.compose.runtime.staticCompositionLocalOf
2726
import androidx.compose.ui.ExperimentalComposeUiApi
2827
import androidx.compose.ui.InternalComposeUiApi
29-
import androidx.navigationevent.NavigationEventDispatcherOwner
28+
import androidx.navigationevent.compose.LocalNavigationEventDispatcherOwner
3029
import kotlinx.coroutines.flow.Flow
3130

32-
@InternalComposeUiApi
33-
val LocalCompatNavigationEventDispatcherOwner =
34-
staticCompositionLocalOf<NavigationEventDispatcherOwner?> { null }
35-
3631
@OptIn(InternalComposeUiApi::class)
3732
@Deprecated("Use NavigationEventHandler instead")
3833
@ExperimentalComposeUiApi
@@ -41,8 +36,8 @@ actual fun PredictiveBackHandler(
4136
enabled: Boolean,
4237
onBack: suspend (progress: Flow<BackEventCompat>) -> Unit
4338
) {
44-
val owner = LocalCompatNavigationEventDispatcherOwner.current ?: error(
45-
"No NavigationEventDispatcher was provided via LocalCompatNavigationEventDispatcherOwner"
39+
val owner = LocalNavigationEventDispatcherOwner.current ?: error(
40+
"No NavigationEventDispatcher was provided via LocalNavigationEventDispatcherOwner"
4641
)
4742
val dispatcher = owner.navigationEventDispatcher
4843
val coroutineScope = rememberCoroutineScope()
@@ -63,8 +58,8 @@ actual fun PredictiveBackHandler(
6358
@ExperimentalComposeUiApi
6459
@Composable
6560
actual fun BackHandler(enabled: Boolean, onBack: () -> Unit) {
66-
val owner = LocalCompatNavigationEventDispatcherOwner.current ?: error(
67-
"No NavigationEventDispatcher was provided via LocalCompatNavigationEventDispatcherOwner"
61+
val owner = LocalNavigationEventDispatcherOwner.current ?: error(
62+
"No NavigationEventDispatcher was provided via LocalNavigationEventDispatcherOwner"
6863
)
6964
val dispatcher = owner.navigationEventDispatcher
7065
val compositeKey = currentCompositeKeyHashCode

compose/ui/ui/api/desktop/ui.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3744,7 +3744,7 @@ public final class androidx/compose/ui/platform/CompositionLocalsKt {
37443744
}
37453745

37463746
public final class androidx/compose/ui/platform/CompositionLocals_skikoKt {
3747-
public static final fun getLocalLifecycleOwner ()Landroidx/compose/runtime/ProvidableCompositionLocal;
3747+
public static final synthetic fun getLocalLifecycleOwner ()Landroidx/compose/runtime/ProvidableCompositionLocal;
37483748
}
37493749

37503750
public final class androidx/compose/ui/platform/DefaultViewConfiguration : androidx/compose/ui/platform/ViewConfiguration {

compose/ui/ui/build.gradle

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ androidXMultiplatform {
9090
api("org.jetbrains.androidx.lifecycle:lifecycle-runtime-compose:2.9.6")
9191
api("androidx.savedstate:savedstate-compose:1.4.0")
9292

93-
implementation("org.jetbrains.androidx.lifecycle:lifecycle-viewmodel:2.9.6")
94-
implementation("org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-savedstate:2.9.6")
93+
implementation("org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-compose:2.11.0-alpha01")
94+
implementation("org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-savedstate:2.11.0-alpha01")
9595
}
9696

9797
commonTest.dependencies {
@@ -198,6 +198,7 @@ androidXMultiplatform {
198198
implementation(project(":compose:test-utils"))
199199
}
200200

201+
def navigationEventVersion = project.findProperty('artifactRedirection.version.androidx.navigationevent')
201202
// TODO: Align naming: nonAndroidMain
202203
skikoMain {
203204
dependsOn(commonMain)
@@ -209,12 +210,7 @@ androidXMultiplatform {
209210

210211
// Keep this dependency for compatibility due to https://youtrack.jetbrains.com/issue/KT-60874
211212
implementation(project(":compose:ui:ui-backhandler"))
212-
213-
// Use direct dependency to AOSP's artifact instead of using project reference
214-
// because this module supports all KMP platforms from the beginning.
215-
// Project dependency (commented out version) is required for `integration` branch setup
216-
// implementation(project(":navigationevent:navigationevent"))
217-
implementation("androidx.navigationevent:navigationevent:1.0.1")
213+
implementation("androidx.navigationevent:navigationevent-compose:$navigationEventVersion")
218214
}
219215
}
220216

@@ -225,7 +221,6 @@ androidXMultiplatform {
225221
implementation(project(":compose:material:material"))
226222
implementation(project(":compose:foundation:foundation"))
227223
implementation(project(":compose:ui:ui-test"))
228-
implementation("org.jetbrains.androidx.navigationevent:navigationevent-compose:1.0.1")
229224
}
230225
}
231226

compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/platform/CompositionLocals.skiko.kt

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,13 @@ package androidx.compose.ui.platform
1919
import androidx.compose.runtime.Composable
2020
import androidx.compose.runtime.CompositionLocalProvider
2121
import androidx.compose.runtime.DisposableEffect
22-
import androidx.compose.runtime.HostDefaultKey
23-
import androidx.compose.runtime.HostDefaultProvider
2422
import androidx.compose.runtime.InternalComposeApi
2523
import androidx.compose.runtime.LocalHostDefaultProvider
2624
import androidx.compose.runtime.ProvidedValue
2725
import androidx.compose.runtime.remember
28-
import androidx.compose.runtime.retain.LocalRetainedValuesStore
2926
import androidx.compose.runtime.saveable.LocalSaveableStateRegistry
3027
import androidx.compose.runtime.staticCompositionLocalOf
31-
import androidx.compose.ui.ExperimentalComposeUiApi
3228
import androidx.compose.ui.InternalComposeUiApi
33-
import androidx.compose.ui.backhandler.LocalCompatNavigationEventDispatcherOwner
34-
import androidx.compose.ui.node.Owner
3529
import androidx.lifecycle.LifecycleOwner
3630
import androidx.savedstate.compose.LocalSavedStateRegistryOwner
3731

@@ -41,6 +35,7 @@ import androidx.savedstate.compose.LocalSavedStateRegistryOwner
4135
@Deprecated(
4236
"Moved to lifecycle-runtime-compose library in androidx.lifecycle.compose package.",
4337
ReplaceWith("androidx.lifecycle.compose.LocalLifecycleOwner"),
38+
level = DeprecationLevel.HIDDEN
4439
)
4540
actual val LocalLifecycleOwner get() = androidx.lifecycle.compose.LocalLifecycleOwner
4641

@@ -63,18 +58,6 @@ val LocalPlatformWindowInsets = staticCompositionLocalOf<PlatformWindowInsets> {
6358
error("CompositionLocal LocalPlatformWindowInsets not present")
6459
}
6560

66-
private val PlatformArchitectureComponentsOwner.values: Array<ProvidedValue<*>>
67-
get() {
68-
val providedValues = mutableListOf(
69-
androidx.lifecycle.compose.LocalLifecycleOwner provides lifecycleOwner,
70-
LocalInternalNavigationEventDispatcherOwner provides navigationEventDispatcherOwner,
71-
LocalCompatNavigationEventDispatcherOwner provides navigationEventDispatcherOwner,
72-
LocalSavedStateRegistryOwner provides savedStateRegistryOwner,
73-
)
74-
viewModelStoreOwner?.let { providedValues.add(LocalInternalViewModelStoreOwner provides it) }
75-
return providedValues.toTypedArray()
76-
}
77-
7861
@OptIn(InternalComposeApi::class)
7962
@Composable
8063
internal fun ProvidePlatformCompositionLocals(
@@ -94,21 +77,16 @@ internal fun ProvidePlatformCompositionLocals(
9477
onDispose { registry.dispose() }
9578
}
9679

97-
// TODO: https://youtrack.jetbrains.com/issue/CMP-9752/Properly-implement-HostDefaultProvider-and-LocalHostDefaultProvider-for-CMP
9880
val hostDefaultProvider = remember(platformContext) {
99-
object : HostDefaultProvider {
100-
@Suppress("UNCHECKED_CAST")
101-
override fun <T> getHostDefault(key: HostDefaultKey<T>): T {
102-
return platformContext.architectureComponentsOwner as T
103-
}
104-
}
81+
HostDefaultProviderImpl(platformContext)
10582
}
10683

10784
CompositionLocalProvider(
10885
*values,
10986
LocalPlatformScreenReader provides platformContext.screenReader,
11087
LocalPlatformWindowInsets provides platformContext.windowInsets,
111-
*platformContext.architectureComponentsOwner.values,
88+
androidx.lifecycle.compose.LocalLifecycleOwner provides platformContext.architectureComponentsOwner.lifecycleOwner,
89+
LocalSavedStateRegistryOwner provides platformContext.architectureComponentsOwner.savedStateRegistryOwner,
11290
LocalSaveableStateRegistry provides saveableStateRegistry,
11391
LocalHostDefaultProvider provides hostDefaultProvider,
11492
content = content,

compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/platform/DefaultNavigationEventDispatcherOwner.skiko.kt

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,15 @@ package androidx.compose.ui.platform
1818

1919
import androidx.compose.runtime.Composable
2020
import androidx.compose.runtime.InternalComposeApi
21-
import androidx.compose.runtime.staticCompositionLocalOf
22-
import androidx.compose.ui.backhandler.LocalCompatNavigationEventDispatcherOwner
2321
import androidx.navigationevent.NavigationEventDispatcherOwner
24-
25-
/**
26-
* Internal helper to provide [NavigationEventDispatcherOwner] from Compose UI module.
27-
* In applications please use [androidx.navigationevent.compose.LocalNavigationEventDispatcherOwner].
28-
*
29-
* @hide
30-
*/
31-
internal val LocalInternalNavigationEventDispatcherOwner =
32-
staticCompositionLocalOf<NavigationEventDispatcherOwner?> { null }
22+
import androidx.navigationevent.compose.LocalNavigationEventDispatcherOwner
3323

3424

25+
@Deprecated(
26+
"Moved to navigation-event-compose library in androidx.navigationevent.compose package.",
27+
level = DeprecationLevel.HIDDEN
28+
)
3529
@InternalComposeApi
3630
@Composable
3731
fun findDefaultNavigationEventDispatcherOwner(): NavigationEventDispatcherOwner? =
38-
LocalInternalNavigationEventDispatcherOwner.current
39-
?: LocalCompatNavigationEventDispatcherOwner.current
32+
LocalNavigationEventDispatcherOwner.current

0 commit comments

Comments
 (0)