-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[Jetnews] TopAppBar doesn't match design spec #467
Changes from 24 commits
d67c992
af6c735
657c99d
5575a95
0e2721a
a7918ff
906b9fd
57da1df
eca2a25
70c3597
d248739
1dbc9f9
f9a3b56
6641358
f698285
9e3f1d5
5569553
2e59495
9883262
b1e5b2f
2d3a680
aa8e8e5
56fdd05
fc3b94b
779ea9b
1242455
a093c85
fb6f61d
2041fc2
69f5a2c
a051cbe
6e7528a
873bc3c
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 |
---|---|---|
|
@@ -17,15 +17,18 @@ | |
package com.example.jetnews.ui.home | ||
|
||
import android.content.res.Configuration.UI_MODE_NIGHT_YES | ||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.wrapContentSize | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.foundation.lazy.LazyListState | ||
import androidx.compose.foundation.lazy.LazyRow | ||
import androidx.compose.foundation.lazy.items | ||
import androidx.compose.foundation.lazy.rememberLazyListState | ||
import androidx.compose.material.CircularProgressIndicator | ||
import androidx.compose.material.Divider | ||
import androidx.compose.material.ExperimentalMaterialApi | ||
|
@@ -37,6 +40,8 @@ import androidx.compose.material.ScaffoldState | |
import androidx.compose.material.SnackbarResult | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.TextButton | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Search | ||
import androidx.compose.material.rememberScaffoldState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
|
@@ -46,6 +51,7 @@ import androidx.compose.runtime.rememberCoroutineScope | |
import androidx.compose.runtime.rememberUpdatedState | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.ColorFilter | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.style.TextAlign | ||
|
@@ -162,33 +168,58 @@ fun HomeScreen( | |
} | ||
} | ||
} | ||
|
||
val scrollState = rememberLazyListState() | ||
Scaffold( | ||
scaffoldState = scaffoldState, | ||
topBar = { | ||
val title = stringResource(id = R.string.app_name) | ||
InsetAwareTopAppBar( | ||
title = { Text(text = title) }, | ||
title = { | ||
Icon( | ||
painter = painterResource(R.drawable.ic_jetnews_wordmark), | ||
contentDescription = title, | ||
tint = MaterialTheme.colors.onBackground, | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(bottom = 4.dp, top = 10.dp) | ||
) | ||
}, | ||
navigationIcon = { | ||
IconButton(onClick = { coroutineScope.launch { openDrawer() } }) { | ||
Icon( | ||
Image( | ||
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. You can use an Icon here and set the tint 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. Done 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 still see 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. +1, please replace with icon From IconButton:
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 just made the change |
||
painter = painterResource(R.drawable.ic_jetnews_logo), | ||
contentDescription = stringResource(R.string.cd_open_navigation_drawer) | ||
contentDescription = stringResource(R.string.cd_open_navigation_drawer), | ||
colorFilter = ColorFilter.tint(MaterialTheme.colors.primary) | ||
) | ||
} | ||
} | ||
}, | ||
actions = { | ||
IconButton( | ||
onClick = { /* TODO: Open search */ } | ||
) { | ||
Icon( | ||
imageVector = Icons.Filled.Search, | ||
contentDescription = stringResource(R.string.cd_search) | ||
) | ||
} | ||
}, | ||
backgroundColor = MaterialTheme.colors.surface, | ||
elevation = if (scrollState.firstVisibleItemScrollOffset == 0) 0.dp else 4.dp | ||
JoseAlcerreca marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
} | ||
) { innerPadding -> | ||
|
||
val modifier = Modifier.padding(innerPadding) | ||
LoadingContent( | ||
empty = posts.initialLoad, | ||
emptyContent = { FullScreenLoading() }, | ||
loading = posts.loading, | ||
onRefresh = onRefreshPosts, | ||
content = { | ||
|
||
HomeScreenErrorAndContent( | ||
posts = posts, | ||
state = scrollState, | ||
onRefresh = { | ||
onRefreshPosts() | ||
}, | ||
|
@@ -243,14 +274,15 @@ private fun LoadingContent( | |
@Composable | ||
private fun HomeScreenErrorAndContent( | ||
posts: UiState<List<Post>>, | ||
state: LazyListState, | ||
onRefresh: () -> Unit, | ||
navigateToArticle: (String) -> Unit, | ||
favorites: Set<String>, | ||
onToggleFavorite: (String) -> Unit, | ||
modifier: Modifier = Modifier | ||
) { | ||
if (posts.data != null) { | ||
PostList(posts.data, navigateToArticle, favorites, onToggleFavorite, modifier) | ||
PostList(posts.data, state, navigateToArticle, favorites, onToggleFavorite, modifier) | ||
} else if (!posts.hasError) { | ||
// if there are no posts, and no error, let the user refresh manually | ||
TextButton(onClick = onRefresh, modifier.fillMaxSize()) { | ||
|
@@ -275,6 +307,7 @@ private fun HomeScreenErrorAndContent( | |
@Composable | ||
private fun PostList( | ||
posts: List<Post>, | ||
state: LazyListState, | ||
JoseAlcerreca marked this conversation as resolved.
Show resolved
Hide resolved
|
||
navigateToArticle: (postId: String) -> Unit, | ||
favorites: Set<String>, | ||
onToggleFavorite: (String) -> Unit, | ||
|
@@ -287,6 +320,7 @@ private fun PostList( | |
|
||
LazyColumn( | ||
modifier = modifier, | ||
state = state, | ||
contentPadding = rememberInsetsPaddingValues( | ||
insets = LocalWindowInsets.current.systemBars, | ||
applyTop = false | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector android:height="24dp" android:tint="#3DDC84" | ||
JoseAlcerreca marked this conversation as resolved.
Show resolved
Hide resolved
|
||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="#FF000000" android:pathData="M17.6,11.48 L19.44,8.3a0.63,0.63 0,0 0,-1.09 -0.63l-1.88,3.24a11.43,11.43 0,0 0,-8.94 0L5.65,7.67a0.63,0.63 0,0 0,-1.09 0.63L6.4,11.48A10.81,10.81 0,0 0,1 20L23,20A10.81,10.81 0,0 0,17.6 11.48ZM7,17.25A1.25,1.25 0,1 1,8.25 16,1.25 1.25,0 0,1 7,17.25ZM17,17.25A1.25,1.25 0,1 1,18.25 16,1.25 1.25,0 0,1 17,17.25Z"/> | ||
</vector> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
JoseAlcerreca marked this conversation as resolved.
Show resolved
Hide resolved
|
||
android:width="48dp" | ||
android:height="48dp" | ||
android:viewportWidth="24.0" | ||
android:viewportHeight="24.0"> | ||
<group> | ||
<path android:name="square" | ||
android:fillColor="#FF073042" | ||
android:pathData="M0,0 L24,0 L24,24 L0,24 z" /> | ||
<path android:fillColor="#3DDC84" | ||
android:pathData="M17.6,11.48 L19.44,8.3a0.63,0.63 0,0 0,-1.09 -0.63l-1.88,3.24a11.43,11.43 0,0 0,-8.94 0L5.65,7.67a0.63,0.63 0,0 0,-1.09 0.63L6.4,11.48A10.81,10.81 0,0 0,1 20L23,20A10.81,10.81 0,0 0,17.6 11.48ZM7,17.25A1.25,1.25 0,1 1,8.25 16,1.25 1.25,0 0,1 7,17.25ZM17,17.25A1.25,1.25 0,1 1,18.25 16,1.25 1.25,0 0,1 17,17.25Z"/> | ||
|
||
</group> | ||
</vector> |
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 the intention here is to increase the elevation if the list has been scrolled? I don't think this code is sufficcient i.e. if you scroll in a new item but it's at 0 offset the elevation will go back to 0.dp. A neat way to fix this might be an ext fun like:
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.
Done
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.
Please rename the file "LazyListUtils.kt" as it's not holding any 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.
Done