Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import androidx.compose.ui.tooling.preview.Preview
@Preview(
name = "Tablet Small",
showSystemUi = true,
device = "spec:width=440dp,height=920dp,dpi=420,isRound=false,chinSize=0dp,orientation=landscape",
device = "spec:width=674dp,height=800dp,dpi=420,isRound=false,chinSize=0dp,orientation=landscape",
uiMode = Configuration.UI_MODE_TYPE_NORMAL
)
annotation class WooPosPreview
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.woocommerce.android.ui.woopos.common.composeui

import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.woocommerce.android.ui.woopos.util.ext.getLongestScreenSideDp

@Composable
fun Dp.toAdaptivePadding(): Dp {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice way to ensure padding is adjusted based on screen size.

Copy link
Contributor Author

@kidinov kidinov Jul 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samiuelson wdyt about this approach? That's kinda naive, but it seems to be working

Also, if we go with this, we should not forget to use that on all the paddings

val longestSide = LocalContext.current.getLongestScreenSideDp()
return when {
longestSide < 880.dp -> {
val calculatedMargin = this * 0.5f
calculatedMargin.makeDividableByFour()
}

longestSide < 1200.dp -> {
val calculatedMargin = this * 0.75f
calculatedMargin.makeDividableByFour()
}

else -> this
}
}

@Composable
private fun Dp.makeDividableByFour(): Dp {
val remainder = this.value % 4
return if (remainder == 0f) {
this
} else {
this + (4 - remainder).dp
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.woocommerce.android.ui.woopos.common.composeui.WooPosPreview
import com.woocommerce.android.ui.woopos.common.composeui.WooPosTheme
import com.woocommerce.android.ui.woopos.common.composeui.toAdaptivePadding
import com.woocommerce.android.ui.woopos.home.cart.WooPosCartScreen
import com.woocommerce.android.ui.woopos.home.products.WooPosProductsScreen
import com.woocommerce.android.ui.woopos.home.totals.WooPosTotalsScreen
Expand Down Expand Up @@ -100,9 +101,9 @@ private fun WooPosHomeScreen(
when (state) {
WooPosHomeState.Cart.Empty,
WooPosHomeState.Cart.NotEmpty,
WooPosHomeState.Checkout.NotPaid -> 0.dp
WooPosHomeState.Checkout.NotPaid -> 0.dp.toAdaptivePadding()

WooPosHomeState.Checkout.Paid -> 24.dp
WooPosHomeState.Checkout.Paid -> 24.dp.toAdaptivePadding()
},
label = "totalsStartPaddingAnimatedDp"
)
Expand Down Expand Up @@ -133,43 +134,43 @@ private fun WooPosHomeScreen(
.fillMaxWidth(),
) {
Row(modifier = Modifier.width(productsWidthDp)) {
Spacer(modifier = Modifier.width(40.dp))
Spacer(modifier = Modifier.width(40.dp.toAdaptivePadding()))
WooPosProductsScreen(
modifier = Modifier
.width(productsWidthDp - 56.dp)
.padding(top = 36.dp)
.width(productsWidthDp - 56.dp.toAdaptivePadding())
.padding(top = 36.dp.toAdaptivePadding())
)
Spacer(modifier = Modifier.width(16.dp))
Spacer(modifier = Modifier.width(16.dp.toAdaptivePadding()))
}
Row(modifier = Modifier.width(cartWidthDp)) {
Spacer(modifier = Modifier.width(24.dp))
Spacer(modifier = Modifier.width(24.dp.toAdaptivePadding()))
Box {
WooPosCartScreen(
Modifier
.width(cartWidthDp - 48.dp)
.padding(vertical = 24.dp)
.width(cartWidthDp - 48.dp.toAdaptivePadding())
.padding(vertical = 24.dp.toAdaptivePadding())
)
Box(
modifier = Modifier
.width(cartWidthDp - 48.dp)
.padding(vertical = 24.dp)
.width(cartWidthDp - 48.dp.toAdaptivePadding())
.padding(vertical = 24.dp.toAdaptivePadding())
.fillMaxHeight()
.background(
color = MaterialTheme.colors.background.copy(alpha = cartOverlayIntensity),
shape = RoundedCornerShape(16.dp)
shape = RoundedCornerShape(16.dp.toAdaptivePadding())
)
)
}
Spacer(modifier = Modifier.width(24.dp))
Spacer(modifier = Modifier.width(24.dp.toAdaptivePadding()))
}
Row(modifier = Modifier.width(totalsWidthDp)) {
Spacer(modifier = Modifier.width(totalsStartPaddingDp))
WooPosTotalsScreen(
modifier = Modifier
.width(totalsWidthDp - 24.dp - totalsStartPaddingDp)
.padding(vertical = 24.dp)
.width(totalsWidthDp - 24.dp.toAdaptivePadding() - totalsStartPaddingDp)
.padding(vertical = 24.dp.toAdaptivePadding())
)
Spacer(modifier = Modifier.width(24.dp))
Spacer(modifier = Modifier.width(24.dp.toAdaptivePadding()))
}
}
}
Expand Down
Loading