diff --git a/compose-layout/api/current.api b/compose-layout/api/current.api index 73bf9d4aad..4d2546eafe 100644 --- a/compose-layout/api/current.api +++ b/compose-layout/api/current.api @@ -2,7 +2,7 @@ package com.google.android.horologist.compose.ambient { public final class AmbientAwareKt { - method @androidx.compose.runtime.Composable public static void AmbientAware(kotlin.jvm.functions.Function1 content); + method @androidx.compose.runtime.Composable public static void AmbientAware(optional androidx.lifecycle.Lifecycle lifecycle, kotlin.jvm.functions.Function1 content); method public static androidx.compose.runtime.ProvidableCompositionLocal getLocalAmbientState(); property public static final androidx.compose.runtime.ProvidableCompositionLocal LocalAmbientState; } diff --git a/compose-layout/src/main/java/com/google/android/horologist/compose/ambient/AmbientAware.kt b/compose-layout/src/main/java/com/google/android/horologist/compose/ambient/AmbientAware.kt index 05ce84bfcd..d5bacc0997 100644 --- a/compose-layout/src/main/java/com/google/android/horologist/compose/ambient/AmbientAware.kt +++ b/compose-layout/src/main/java/com/google/android/horologist/compose/ambient/AmbientAware.kt @@ -42,17 +42,18 @@ import androidx.wear.ambient.AmbientLifecycleObserver * * It should be used within each individual screen inside nav routes. * + * @param lifecycle The [Lifecycle] of the activity or current owner such as NavBackStackEntry. * @param content Lambda that will be used for building the UI, which is passed the current ambient * state. */ @Composable fun AmbientAware( + lifecycle: Lifecycle = LocalLifecycleOwner.current.lifecycle, content: @Composable (AmbientState) -> Unit, ) { // Using AmbientAware correctly relies on there being an Activity context. If there isn't, then // gracefully allow the composition of [block], but no ambient-mode functionality is enabled. val activity = LocalContext.current.findActivityOrNull() - val lifecycle = LocalLifecycleOwner.current.lifecycle val ambientState = rememberAmbientState(activity, lifecycle)