From e7fb99fcdcdc62a03a480d710ab7631a67dcace9 Mon Sep 17 00:00:00 2001 From: Rob Orgiu Date: Tue, 9 Dec 2025 20:44:23 +0100 Subject: [PATCH 1/2] Fix Horizontal layout --- .../android/developers/androidify/util/LayoutUtils.kt | 11 +++++++++-- .../developers/androidify/creation/PhotoPrompt.kt | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/core/util/src/main/java/com/android/developers/androidify/util/LayoutUtils.kt b/core/util/src/main/java/com/android/developers/androidify/util/LayoutUtils.kt index f3257813..1bf8194e 100644 --- a/core/util/src/main/java/com/android/developers/androidify/util/LayoutUtils.kt +++ b/core/util/src/main/java/com/android/developers/androidify/util/LayoutUtils.kt @@ -50,10 +50,17 @@ fun areBothWindowDimensionsAtLeastMedium(): Boolean { sizeClass.isWidthAtLeastBreakpoint(WindowSizeClass.WIDTH_DP_MEDIUM_LOWER_BOUND) } +/*** + * This function is useful to understand if the window is too small to show the vertically stacked + * photo empty state. It should align items horizontally only if the window is horizontal and + * if the amount of vertical space is smaller than medium + */ @Composable -fun isHorizontalWindow(): Boolean { +fun shouldShowHorizontalPhotoPrompt(): Boolean { val sizeClass = calculateWindowSizeClass() - return sizeClass.minWidthDp >= sizeClass.minHeightDp + val isHorizontalWindow = sizeClass.minWidthDp >= sizeClass.minHeightDp + val isHeightSmallerThanMedium = !sizeClass.isHeightAtLeastBreakpoint(WindowSizeClass.HEIGHT_DP_MEDIUM_LOWER_BOUND) + return isHorizontalWindow && isHeightSmallerThanMedium } /*** diff --git a/feature/creation/src/main/java/com/android/developers/androidify/creation/PhotoPrompt.kt b/feature/creation/src/main/java/com/android/developers/androidify/creation/PhotoPrompt.kt index aac2c1d4..efe4a44a 100644 --- a/feature/creation/src/main/java/com/android/developers/androidify/creation/PhotoPrompt.kt +++ b/feature/creation/src/main/java/com/android/developers/androidify/creation/PhotoPrompt.kt @@ -98,7 +98,7 @@ import com.android.developers.androidify.theme.components.SecondaryOutlinedButto import com.android.developers.androidify.theme.sharedBoundsRevealWithShapeMorph import com.android.developers.androidify.theme.sharedBoundsWithDefaults import com.android.developers.androidify.util.dashedRoundedRectBorder -import com.android.developers.androidify.util.isHorizontalWindow +import com.android.developers.androidify.util.shouldShowHorizontalPhotoPrompt import com.android.developers.androidify.creation.R as CreationR @Composable @@ -171,7 +171,7 @@ private fun UploadEmptyState( onChooseImagePress: () -> Unit, modifier: Modifier = Modifier, ) { - if (isHorizontalWindow()) { + if (shouldShowHorizontalPhotoPrompt()) { HorizontallyAlignedUploadEmptyState( onCameraPressed = onCameraPressed, onChooseImagePress = onChooseImagePress, From c54d176bc3543df20a52904016e029c778b64c04 Mon Sep 17 00:00:00 2001 From: Rob Orgiu Date: Thu, 11 Dec 2025 11:46:20 +0100 Subject: [PATCH 2/2] Move function to better limit its scope to the Creation flow --- .../developers/androidify/util/LayoutUtils.kt | 13 ------------- .../androidify/creation/PhotoPrompt.kt | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/core/util/src/main/java/com/android/developers/androidify/util/LayoutUtils.kt b/core/util/src/main/java/com/android/developers/androidify/util/LayoutUtils.kt index 1bf8194e..ab8f9aa7 100644 --- a/core/util/src/main/java/com/android/developers/androidify/util/LayoutUtils.kt +++ b/core/util/src/main/java/com/android/developers/androidify/util/LayoutUtils.kt @@ -50,19 +50,6 @@ fun areBothWindowDimensionsAtLeastMedium(): Boolean { sizeClass.isWidthAtLeastBreakpoint(WindowSizeClass.WIDTH_DP_MEDIUM_LOWER_BOUND) } -/*** - * This function is useful to understand if the window is too small to show the vertically stacked - * photo empty state. It should align items horizontally only if the window is horizontal and - * if the amount of vertical space is smaller than medium - */ -@Composable -fun shouldShowHorizontalPhotoPrompt(): Boolean { - val sizeClass = calculateWindowSizeClass() - val isHorizontalWindow = sizeClass.minWidthDp >= sizeClass.minHeightDp - val isHeightSmallerThanMedium = !sizeClass.isHeightAtLeastBreakpoint(WindowSizeClass.HEIGHT_DP_MEDIUM_LOWER_BOUND) - return isHorizontalWindow && isHeightSmallerThanMedium -} - /*** * This function is useful to limit the number of buttons when the window is too small to show * everything that should otherwise appear on the screen. diff --git a/feature/creation/src/main/java/com/android/developers/androidify/creation/PhotoPrompt.kt b/feature/creation/src/main/java/com/android/developers/androidify/creation/PhotoPrompt.kt index efe4a44a..e2bbd18e 100644 --- a/feature/creation/src/main/java/com/android/developers/androidify/creation/PhotoPrompt.kt +++ b/feature/creation/src/main/java/com/android/developers/androidify/creation/PhotoPrompt.kt @@ -84,6 +84,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.graphics.shapes.RoundedPolygon import androidx.graphics.shapes.rectangle +import androidx.window.core.layout.WindowSizeClass import coil3.compose.AsyncImage import coil3.request.ImageRequest import coil3.request.crossfade @@ -97,8 +98,8 @@ import com.android.developers.androidify.theme.components.ScaleIndicationNodeFac import com.android.developers.androidify.theme.components.SecondaryOutlinedButton import com.android.developers.androidify.theme.sharedBoundsRevealWithShapeMorph import com.android.developers.androidify.theme.sharedBoundsWithDefaults +import com.android.developers.androidify.util.calculateWindowSizeClass import com.android.developers.androidify.util.dashedRoundedRectBorder -import com.android.developers.androidify.util.shouldShowHorizontalPhotoPrompt import com.android.developers.androidify.creation.R as CreationR @Composable @@ -186,6 +187,19 @@ private fun UploadEmptyState( } } +/*** + * This function is useful to understand if the window is too small to show the vertically stacked + * photo empty state. It should align items horizontally only if the window is horizontal and + * if the amount of vertical space is smaller than medium + */ +@Composable +fun shouldShowHorizontalPhotoPrompt(): Boolean { + val sizeClass = calculateWindowSizeClass() + val isHorizontalWindow = sizeClass.minWidthDp >= sizeClass.minHeightDp + val isHeightSmallerThanMedium = !sizeClass.isHeightAtLeastBreakpoint(WindowSizeClass.HEIGHT_DP_MEDIUM_LOWER_BOUND) + return isHorizontalWindow && isHeightSmallerThanMedium +} + @Composable private fun VerticallyAlignedUploadEmptyState( onCameraPressed: () -> Unit,