-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(MVP): Add landscape support for the PIN layout. #74
base: master
Are you sure you want to change the base?
Conversation
manpreeeeeet
commented
Dec 23, 2024
.fillMaxHeight() | ||
.padding(it) | ||
.padding(40.dp) | ||
.padding(bottom = 16.dp), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to merge these paddings into one modifier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just so I am understanding this correctly, I do not see a visual difference when I remove padding(it)
here, which is expected since we already do padding(40.dp)
. So we can safely remove this for the row layout, is that right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.padding(it)
applies additional paddings provided by Scaffold to ensure the top and bottom bars don't overlap with the content. Removing it will also result in a compiler warning/error
val orientation = LocalConfiguration.current.orientation | ||
if (orientation == Configuration.ORIENTATION_LANDSCAPE) { | ||
|
||
FlowColumn( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reasons why this is a FlowColumn and not a FlowRow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose FlowColumn
since in landscape fitting all the buttons requires reducing the height as low as possible rather than the width. And using FlowColumn
+ weight(1f) made it easier.
But now taking a second look at it, a fixed width for the Box
that contains these buttons should be able to achieve this without having to do it using FlowColumns
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I asked was because FlowRow would allow extracting the content into a separate composable
} | ||
} | ||
Spacer(modifier = Modifier.weight(1f)) | ||
Box(modifier = Modifier.weight(0.4f)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternative to FlowColumn
requires this code, where we need to manually calculate all the padding + minimumButton size. This does remove the duplicated content inside of FlowColumn
and FlowRow
but it does make it complex to read IMO, since it is not obvious what/how it is calculated without taking a closer look.
I am leaning towards the FlowColumn
approach. Thoughts?
val pinBoardHorizontalPadding = 32.dp
val horizontalSpacedBy = 16.dp
val totalPadding = (pinBoardHorizontalPadding * 2) + (horizontalSpacedBy * 2)
val minimumBoxWidth = remember(PinButtonDefaults.PinButtonMinSize) {
val buttonsInRow = 3
(PinButtonDefaults.PinButtonMinSize * buttonsInRow) + totalPadding
}
Box(
modifier = Modifier.width(minimumBoxWidth),
contentAlignment = Alignment.Center
) {
PinBoard(
modifier = Modifier
.padding(horizontal = pinBoardHorizontalPadding)
.padding(bottom = 16.dp),
horizontalSpace = horizontalSpacedBy,
state = state
)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd rather have this than duplicated code
fit 3 pin buttons. In landscape mode, height is the limiting constraint. So, this calculation tries to fit exactly 3 buttons in a row using their `PinButtonDefaults.PinButtonMinSize`.
I boot up the official emulator images for stuff like pin input. For more common layouts I use https://m3.material.io |
TopAppBar in landscape looks wonderful, let's do that to fit the buttons. Otherwise, this looks great. I'll make some final adjustments for larger screens on landscape after this |