-
Notifications
You must be signed in to change notification settings - Fork 657
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
Make the Adaptive Layout Codelab edge-to-edge #485
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -20,9 +20,15 @@ import androidx.compose.foundation.Image | |||||||
import androidx.compose.foundation.background | ||||||||
import androidx.compose.foundation.layout.Arrangement | ||||||||
import androidx.compose.foundation.layout.Column | ||||||||
import androidx.compose.foundation.layout.PaddingValues | ||||||||
import androidx.compose.foundation.layout.Row | ||||||||
import androidx.compose.foundation.layout.WindowInsets | ||||||||
import androidx.compose.foundation.layout.asPaddingValues | ||||||||
import androidx.compose.foundation.layout.calculateEndPadding | ||||||||
import androidx.compose.foundation.layout.calculateStartPadding | ||||||||
import androidx.compose.foundation.layout.fillMaxWidth | ||||||||
import androidx.compose.foundation.layout.padding | ||||||||
import androidx.compose.foundation.layout.safeDrawing | ||||||||
import androidx.compose.foundation.layout.size | ||||||||
import androidx.compose.foundation.lazy.LazyColumn | ||||||||
import androidx.compose.foundation.lazy.items | ||||||||
|
@@ -42,9 +48,13 @@ import androidx.compose.runtime.Composable | |||||||
import androidx.compose.ui.Alignment | ||||||||
import androidx.compose.ui.Modifier | ||||||||
import androidx.compose.ui.draw.clip | ||||||||
import androidx.compose.ui.layout.Layout | ||||||||
import androidx.compose.ui.platform.LocalLayoutDirection | ||||||||
import androidx.compose.ui.res.painterResource | ||||||||
import androidx.compose.ui.res.stringResource | ||||||||
import androidx.compose.ui.text.style.TextOverflow | ||||||||
import androidx.compose.ui.unit.Dp | ||||||||
import androidx.compose.ui.unit.LayoutDirection | ||||||||
import androidx.compose.ui.unit.dp | ||||||||
import com.example.reply.R | ||||||||
import com.example.reply.data.Email | ||||||||
|
@@ -55,7 +65,13 @@ fun ReplyListPane( | |||||||
onEmailClick: (Email) -> Unit, | ||||||||
modifier: Modifier = Modifier | ||||||||
) { | ||||||||
LazyColumn(modifier = modifier.fillMaxWidth()) { | ||||||||
val layoutDirection = LocalLayoutDirection.current | ||||||||
|
||||||||
LazyColumn( | ||||||||
modifier = modifier.fillMaxWidth(), | ||||||||
contentPadding = WindowInsets.safeDrawing.asPaddingValues() | ||||||||
.copy(layoutDirection, bottom = 0.dp) | ||||||||
Comment on lines
+72
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this can be done with built-in APIs as
Suggested change
|
||||||||
) { | ||||||||
item { | ||||||||
ReplySearchBar(modifier = Modifier.fillMaxWidth()) | ||||||||
} | ||||||||
|
@@ -73,7 +89,15 @@ fun ReplyDetailPane( | |||||||
email: Email, | ||||||||
modifier: Modifier = Modifier | ||||||||
) { | ||||||||
LazyColumn(modifier = modifier.fillMaxWidth()) { | ||||||||
|
||||||||
val layoutDirection = LocalLayoutDirection.current | ||||||||
|
||||||||
LazyColumn( | ||||||||
modifier = modifier.fillMaxWidth(), | ||||||||
contentPadding = WindowInsets.safeDrawing.asPaddingValues() | ||||||||
.copy(layoutDirection = layoutDirection, bottom = 0.dp) | ||||||||
Comment on lines
+97
to
+98
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto here
Suggested change
|
||||||||
|
||||||||
) { | ||||||||
item { | ||||||||
ReplyEmailThreadItem(email) | ||||||||
} | ||||||||
|
@@ -156,13 +180,13 @@ fun ReplyEmailThreadItem( | |||||||
modifier: Modifier = Modifier | ||||||||
) { | ||||||||
Card( | ||||||||
modifier = modifier.padding(horizontal = 16.dp, vertical = 4.dp), | ||||||||
modifier = modifier.padding(horizontal = 16.dp), | ||||||||
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surface) | ||||||||
) { | ||||||||
Column( | ||||||||
modifier = Modifier | ||||||||
.fillMaxWidth() | ||||||||
.padding(20.dp) | ||||||||
.padding(horizontal = 20.dp) | ||||||||
) { | ||||||||
Row(modifier = Modifier.fillMaxWidth()) { | ||||||||
ReplyProfileImage( | ||||||||
|
@@ -264,7 +288,7 @@ fun ReplySearchBar(modifier: Modifier = Modifier) { | |||||||
Row( | ||||||||
modifier = modifier | ||||||||
.fillMaxWidth() | ||||||||
.padding(16.dp) | ||||||||
.padding(horizontal = 16.dp) | ||||||||
.background(MaterialTheme.colorScheme.surface, CircleShape), | ||||||||
verticalAlignment = Alignment.CenterVertically | ||||||||
) { | ||||||||
|
@@ -291,3 +315,17 @@ fun ReplySearchBar(modifier: Modifier = Modifier) { | |||||||
) | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
private fun PaddingValues.copy( | ||||||||
layoutDirection: LayoutDirection, | ||||||||
start: Dp? = null, | ||||||||
top: Dp? = null, | ||||||||
end: Dp? = null, | ||||||||
bottom: Dp? = null, | ||||||||
) = PaddingValues( | ||||||||
start = start ?: calculateStartPadding(layoutDirection), | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this can be removed entirely with the alternate APIs above, but one subtle behavior issue that can arise with this code: This causes A solution to this here would be to setup a fun PaddingValues.copy(
start: Dp? = null,
top: Dp? = null,
end: Dp? = null,
bottom: Dp? = null,
) = object : PaddingValues {
override fun calculateBottomPadding(): Dp =
bottom ?: this@copy.calculateBottomPadding()
override fun calculateLeftPadding(layoutDirection: LayoutDirection): Dp =
when (layoutDirection) {
LayoutDirection.Ltr -> start
LayoutDirection.Rtl -> end
} ?: this@copy.calculateLeftPadding(layoutDirection)
override fun calculateRightPadding(layoutDirection: LayoutDirection): Dp =
when (layoutDirection) {
LayoutDirection.Ltr -> end
LayoutDirection.Rtl -> start
} ?: this@copy.calculateRightPadding(layoutDirection)
override fun calculateTopPadding(): Dp =
top ?: this@copy.calculateTopPadding()
} |
||||||||
top = top ?: calculateTopPadding(), | ||||||||
end = end ?: calculateEndPadding(layoutDirection), | ||||||||
bottom = bottom ?: calculateBottomPadding(), | ||||||||
) | ||||||||
|
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.
Haven't seen this done before, should we add it to the compose docs for edge to edge?