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..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,12 +50,6 @@ fun areBothWindowDimensionsAtLeastMedium(): Boolean { sizeClass.isWidthAtLeastBreakpoint(WindowSizeClass.WIDTH_DP_MEDIUM_LOWER_BOUND) } -@Composable -fun isHorizontalWindow(): Boolean { - val sizeClass = calculateWindowSizeClass() - return sizeClass.minWidthDp >= sizeClass.minHeightDp -} - /*** * 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 aac2c1d4..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.isHorizontalWindow import com.android.developers.androidify.creation.R as CreationR @Composable @@ -171,7 +172,7 @@ private fun UploadEmptyState( onChooseImagePress: () -> Unit, modifier: Modifier = Modifier, ) { - if (isHorizontalWindow()) { + if (shouldShowHorizontalPhotoPrompt()) { HorizontallyAlignedUploadEmptyState( onCameraPressed = onCameraPressed, onChooseImagePress = onChooseImagePress, @@ -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,