Skip to content

Commit 29509ab

Browse files
authored
Merge pull request #185 from android/fix_medium_layout
Fix Horizontal breaking on large devices
2 parents cbb7794 + c54d176 commit 29509ab

File tree

2 files changed

+16
-8
lines changed
  • core/util/src/main/java/com/android/developers/androidify/util
  • feature/creation/src/main/java/com/android/developers/androidify/creation

2 files changed

+16
-8
lines changed

core/util/src/main/java/com/android/developers/androidify/util/LayoutUtils.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ fun areBothWindowDimensionsAtLeastMedium(): Boolean {
5050
sizeClass.isWidthAtLeastBreakpoint(WindowSizeClass.WIDTH_DP_MEDIUM_LOWER_BOUND)
5151
}
5252

53-
@Composable
54-
fun isHorizontalWindow(): Boolean {
55-
val sizeClass = calculateWindowSizeClass()
56-
return sizeClass.minWidthDp >= sizeClass.minHeightDp
57-
}
58-
5953
/***
6054
* This function is useful to limit the number of buttons when the window is too small to show
6155
* everything that should otherwise appear on the screen.

feature/creation/src/main/java/com/android/developers/androidify/creation/PhotoPrompt.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ import androidx.compose.ui.unit.dp
8484
import androidx.compose.ui.unit.sp
8585
import androidx.graphics.shapes.RoundedPolygon
8686
import androidx.graphics.shapes.rectangle
87+
import androidx.window.core.layout.WindowSizeClass
8788
import coil3.compose.AsyncImage
8889
import coil3.request.ImageRequest
8990
import coil3.request.crossfade
@@ -97,8 +98,8 @@ import com.android.developers.androidify.theme.components.ScaleIndicationNodeFac
9798
import com.android.developers.androidify.theme.components.SecondaryOutlinedButton
9899
import com.android.developers.androidify.theme.sharedBoundsRevealWithShapeMorph
99100
import com.android.developers.androidify.theme.sharedBoundsWithDefaults
101+
import com.android.developers.androidify.util.calculateWindowSizeClass
100102
import com.android.developers.androidify.util.dashedRoundedRectBorder
101-
import com.android.developers.androidify.util.isHorizontalWindow
102103
import com.android.developers.androidify.creation.R as CreationR
103104

104105
@Composable
@@ -171,7 +172,7 @@ private fun UploadEmptyState(
171172
onChooseImagePress: () -> Unit,
172173
modifier: Modifier = Modifier,
173174
) {
174-
if (isHorizontalWindow()) {
175+
if (shouldShowHorizontalPhotoPrompt()) {
175176
HorizontallyAlignedUploadEmptyState(
176177
onCameraPressed = onCameraPressed,
177178
onChooseImagePress = onChooseImagePress,
@@ -186,6 +187,19 @@ private fun UploadEmptyState(
186187
}
187188
}
188189

190+
/***
191+
* This function is useful to understand if the window is too small to show the vertically stacked
192+
* photo empty state. It should align items horizontally only if the window is horizontal and
193+
* if the amount of vertical space is smaller than medium
194+
*/
195+
@Composable
196+
fun shouldShowHorizontalPhotoPrompt(): Boolean {
197+
val sizeClass = calculateWindowSizeClass()
198+
val isHorizontalWindow = sizeClass.minWidthDp >= sizeClass.minHeightDp
199+
val isHeightSmallerThanMedium = !sizeClass.isHeightAtLeastBreakpoint(WindowSizeClass.HEIGHT_DP_MEDIUM_LOWER_BOUND)
200+
return isHorizontalWindow && isHeightSmallerThanMedium
201+
}
202+
189203
@Composable
190204
private fun VerticallyAlignedUploadEmptyState(
191205
onCameraPressed: () -> Unit,

0 commit comments

Comments
 (0)