Skip to content

Commit

Permalink
Merge pull request #485 from android/e2e_for_main
Browse files Browse the repository at this point in the history
Make the Adaptive Layout Codelab edge-to-edge
  • Loading branch information
ashnohe authored Nov 7, 2024
2 parents 7673bc7 + 69bfac9 commit c33b618
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

package com.example.reply.ui

import android.os.Build
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand All @@ -34,6 +36,11 @@ class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

enableEdgeToEdge()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
window.isNavigationBarContrastEnforced = false
}

setContent {
ReplyTheme {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ 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.WindowInsetsSides
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.only
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
Expand All @@ -42,9 +50,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
Expand All @@ -55,7 +67,12 @@ fun ReplyListPane(
onEmailClick: (Email) -> Unit,
modifier: Modifier = Modifier
) {
LazyColumn(modifier = modifier.fillMaxWidth()) {

LazyColumn(
modifier = modifier.fillMaxWidth(),
contentPadding = WindowInsets.safeDrawing.only(
WindowInsetsSides.Horizontal + WindowInsetsSides.Top).asPaddingValues()
) {
item {
ReplySearchBar(modifier = Modifier.fillMaxWidth())
}
Expand All @@ -73,7 +90,14 @@ fun ReplyDetailPane(
email: Email,
modifier: Modifier = Modifier
) {
LazyColumn(modifier = modifier.fillMaxWidth()) {

val layoutDirection = LocalLayoutDirection.current

LazyColumn(
modifier = modifier.fillMaxWidth(),
contentPadding = WindowInsets.safeDrawing.only(
WindowInsetsSides.Horizontal + WindowInsetsSides.Top).asPaddingValues()
) {
item {
ReplyEmailThreadItem(email)
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.example.reply.ui.theme

import android.app.Activity
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
Expand All @@ -25,11 +24,7 @@ import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.core.view.ViewCompat

// Material 3 color schemes
private val replyDarkColorScheme = darkColorScheme(
Expand Down Expand Up @@ -104,13 +99,6 @@ fun ReplyTheme(
darkTheme -> replyDarkColorScheme
else -> replyLightColorScheme
}
val view = LocalView.current
if (!view.isInEditMode) {
SideEffect {
(view.context as Activity).window.statusBarColor = replyColorScheme.primary.toArgb()
ViewCompat.getWindowInsetsController(view)?.isAppearanceLightStatusBars = darkTheme
}
}

MaterialTheme(
colorScheme = replyColorScheme,
Expand Down

0 comments on commit c33b618

Please sign in to comment.