Skip to content

Commit

Permalink
[0.6.x] Cherry pick ambient and padding fixes (#2483)
Browse files Browse the repository at this point in the history
* Add lifecycle parameter to AmbientAware (#2481)

---------

Co-authored-by: yschimke <[email protected]>
(cherry picked from commit 4cceb8d)

* Cherry pick #2476

Ceil padding to 1px

* Update ScalingLazyColumnDefaults.kt

* 🤖 Updates screenshots

---------

Co-authored-by: yschimke <[email protected]>
  • Loading branch information
yschimke and yschimke authored Dec 10, 2024
1 parent d8a4110 commit 73606b9
Show file tree
Hide file tree
Showing 121 changed files with 163 additions and 152 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion compose-layout/api/current.api
Original file line number Diff line number Diff line change
Expand Up @@ -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<? super com.google.android.horologist.compose.ambient.AmbientState,kotlin.Unit> content);
method @androidx.compose.runtime.Composable public static void AmbientAware(optional androidx.lifecycle.Lifecycle lifecycle, kotlin.jvm.functions.Function1<? super com.google.android.horologist.compose.ambient.AmbientState,kotlin.Unit> content);
method public static androidx.compose.runtime.ProvidableCompositionLocal<com.google.android.horologist.compose.ambient.AmbientState> getLocalAmbientState();
property public static final androidx.compose.runtime.ProvidableCompositionLocal<com.google.android.horologist.compose.ambient.AmbientState> LocalAmbientState;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import androidx.wear.compose.foundation.lazy.ScalingParams
import androidx.wear.compose.material.ChipDefaults
import com.google.android.horologist.annotations.ExperimentalHorologistApi
import com.google.android.horologist.compose.layout.ScalingLazyColumnState.RotaryMode
import kotlin.math.ceil
import kotlin.math.sqrt

/**
Expand Down Expand Up @@ -308,7 +309,7 @@ public object ScalingLazyColumnDefaults {

return {
val height = screenHeightDp.dp
val horizontalPadding = screenWidthDp.dp * horizontalPercent
val horizontalPadding = (screenWidthDp.dp * horizontalPercent).ceilPx()

val topPadding = if (first != ItemType.Unspecified) {
first.topPaddingDp * height + first.paddingCorrection
Expand All @@ -318,7 +319,7 @@ public object ScalingLazyColumnDefaults {
} else {
32.dp
}
}
}.ceilPx()

val bottomPadding = if (last != ItemType.Unspecified) {
last.bottomPaddingDp * height + first.paddingCorrection
Expand All @@ -331,7 +332,7 @@ public object ScalingLazyColumnDefaults {
} else {
0.dp
}
}
}.ceilPx()

PaddingValues(
top = topPadding,
Expand All @@ -345,3 +346,12 @@ public object ScalingLazyColumnDefaults {
@Composable
fun Modifier.listTextPadding() = this.padding(horizontal = 0.052f * LocalConfiguration.current.screenWidthDp.dp)
}

@Composable
internal fun Dp.ceilPx(): Dp {
val density = LocalDensity.current

return with(density) {
ceil(this@ceilPx.toPx()).toDp()
}
}
Binary file modified sample/src/test/audit/Cards_backgroundimage_device204.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/src/test/audit/Cards_backgroundimage_device240.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/src/test/audit/Cards_backgroundimage_pixel_watch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/src/test/audit/Lists_nobottombutton_device204.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/src/test/audit/Lists_nobottombutton_device228.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/src/test/audit/Lists_nobottombutton_device240.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/src/test/audit/Lists_nobottombutton_pixel_watch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/src/test/audit/Lists_onebottombutton_device204.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/src/test/audit/Lists_onebottomchip_device204.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/src/test/audit/Lists_onebottomchip_device228.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/src/test/audit/Lists_onebottomchip_device240.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/src/test/audit/Lists_onebottomchip_pixel_watch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/src/test/audit/Lists_twobottomround_device204.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/src/test/audit/MainMenu_bottom_device228.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/src/test/audit/MainMenu_bottom_device240.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/src/test/audit/MainMenu_bottom_pixel_watch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/src/test/audit/MainMenu_bottom_pixel_watch_large_font.png
Binary file modified sample/src/test/audit/MainMenu_top_device204.png
Binary file modified sample/src/test/audit/MainMenu_top_galaxy_watch_6_small_font.png
Binary file modified sample/src/test/audit/PositionIndicator_bottomlong_device204.png
Binary file modified sample/src/test/audit/PositionIndicator_bottomlong_device228.png
Binary file modified sample/src/test/audit/PositionIndicator_bottomlong_device240.png
Binary file modified sample/src/test/audit/PositionIndicator_bottomlong_pixel_watch.png
Binary file modified sample/src/test/audit/PositionIndicator_bottomshort_device204.png
Binary file modified sample/src/test/audit/PositionIndicator_bottomshort_device228.png
Binary file modified sample/src/test/audit/PositionIndicator_bottomshort_device240.png
Binary file modified sample/src/test/audit/PositionIndicator_middlelong_device204.png
Binary file modified sample/src/test/audit/PositionIndicator_middleshort_device204.png
Binary file modified sample/src/test/audit/PositionIndicator_toplong_device204.png
Binary file modified sample/src/test/audit/PositionIndicator_toplong_device240.png
Binary file modified sample/src/test/audit/PositionIndicator_toplong_pixel_watch.png
Binary file modified sample/src/test/audit/PositionIndicator_topshort_device204.png
Binary file modified sample/src/test/audit/PositionIndicator_topshort_device240.png
Binary file modified sample/src/test/audit/PositionIndicator_topshort_pixel_watch.png
Loading

0 comments on commit 73606b9

Please sign in to comment.