Skip to content

Commit 68bfcfe

Browse files
authoredFeb 17, 2021
Merge branch 'dev_beta01' into jv/rally_a11y
2 parents b3bc011 + d6a4a72 commit 68bfcfe

File tree

13 files changed

+76
-80
lines changed

13 files changed

+76
-80
lines changed
 

‎JetNews/app/build.gradle

+5-9
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,14 @@ dependencies {
9191
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"
9292

9393
implementation 'androidx.appcompat:appcompat:1.3.0-beta01'
94-
implementation 'androidx.activity:activity-ktx:1.1.0'
94+
implementation 'androidx.activity:activity-ktx:1.2.0'
9595
implementation 'androidx.core:core-ktx:1.5.0-beta01'
96-
implementation "androidx.activity:activity-compose:1.3.0-alpha02"
96+
implementation "androidx.activity:activity-compose:1.3.0-SNAPSHOT"
9797

98-
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.0-rc01"
99-
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0-rc01"
100-
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha01"
98+
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.0"
99+
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0"
100+
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-SNAPSHOT"
101101

102-
// FIXME: only needed for Compose alpha12
103-
androidTestImplementation "androidx.activity:activity-compose:1.3.0-alpha02"
104-
105-
androidTestImplementation 'junit:junit:4.13.1'
106102
androidTestImplementation 'androidx.test:rules:1.3.0'
107103
androidTestImplementation 'androidx.test:runner:1.3.0'
108104
androidTestImplementation "androidx.compose.ui:ui-test:$compose_version"

‎JetNews/app/src/androidTest/java/com/example/jetnews/HomeScreenSnackbarTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import androidx.compose.material.ExperimentalMaterialApi
2020
import androidx.compose.material.SnackbarHostState
2121
import androidx.compose.material.rememberScaffoldState
2222
import androidx.compose.runtime.ExperimentalComposeApi
23-
import androidx.compose.runtime.snapshots.snapshotFlow
23+
import androidx.compose.runtime.snapshotFlow
2424
import androidx.compose.ui.test.assertIsDisplayed
2525
import androidx.compose.ui.test.junit4.createComposeRule
2626
import androidx.compose.ui.test.onNodeWithText

‎JetNews/app/src/main/java/com/example/jetnews/ui/AppDrawer.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import androidx.compose.foundation.layout.Row
2323
import androidx.compose.foundation.layout.Spacer
2424
import androidx.compose.foundation.layout.fillMaxSize
2525
import androidx.compose.foundation.layout.fillMaxWidth
26+
import androidx.compose.foundation.layout.height
2627
import androidx.compose.foundation.layout.padding
27-
import androidx.compose.foundation.layout.preferredHeight
28-
import androidx.compose.foundation.layout.preferredWidth
28+
import androidx.compose.foundation.layout.width
2929
import androidx.compose.material.Divider
3030
import androidx.compose.material.MaterialTheme
3131
import androidx.compose.material.Surface
@@ -53,7 +53,7 @@ fun AppDrawer(
5353
closeDrawer: () -> Unit
5454
) {
5555
Column(modifier = Modifier.fillMaxSize()) {
56-
Spacer(Modifier.preferredHeight(24.dp))
56+
Spacer(Modifier.height(24.dp))
5757
JetNewsLogo(Modifier.padding(16.dp))
5858
Divider(color = MaterialTheme.colors.onSurface.copy(alpha = .2f))
5959
DrawerButton(
@@ -86,7 +86,7 @@ private fun JetNewsLogo(modifier: Modifier = Modifier) {
8686
contentDescription = null, // decorative
8787
colorFilter = ColorFilter.tint(MaterialTheme.colors.primary)
8888
)
89-
Spacer(Modifier.preferredWidth(8.dp))
89+
Spacer(Modifier.width(8.dp))
9090
Image(
9191
painter = painterResource(R.drawable.ic_jetnews_wordmark),
9292
contentDescription = stringResource(R.string.app_name),
@@ -143,7 +143,7 @@ private fun DrawerButton(
143143
colorFilter = ColorFilter.tint(textIconColor),
144144
alpha = imageAlpha
145145
)
146-
Spacer(Modifier.preferredWidth(16.dp))
146+
Spacer(Modifier.width(16.dp))
147147
Text(
148148
text = label,
149149
style = MaterialTheme.typography.body2,

‎JetNews/app/src/main/java/com/example/jetnews/ui/SwipeToRefresh.kt

+13-19
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.example.jetnews.ui
1818

19+
import androidx.compose.foundation.gestures.Orientation
1920
import androidx.compose.foundation.layout.Box
2021
import androidx.compose.foundation.layout.offset
2122
import androidx.compose.material.ExperimentalMaterialApi
@@ -24,14 +25,13 @@ import androidx.compose.material.SwipeableState
2425
import androidx.compose.material.rememberSwipeableState
2526
import androidx.compose.material.swipeable
2627
import androidx.compose.runtime.Composable
27-
import androidx.compose.runtime.DisposableEffect
28+
import androidx.compose.runtime.LaunchedEffect
2829
import androidx.compose.ui.Alignment
2930
import androidx.compose.ui.Modifier
3031
import androidx.compose.ui.geometry.Offset
31-
import androidx.compose.ui.gesture.nestedscroll.NestedScrollConnection
32-
import androidx.compose.ui.gesture.nestedscroll.NestedScrollSource
33-
import androidx.compose.ui.gesture.nestedscroll.nestedScroll
34-
import androidx.compose.ui.gesture.scrollorientationlocking.Orientation
32+
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
33+
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
34+
import androidx.compose.ui.input.nestedscroll.nestedScroll
3535
import androidx.compose.ui.platform.LocalDensity
3636
import androidx.compose.ui.unit.IntOffset
3737
import androidx.compose.ui.unit.Velocity
@@ -82,10 +82,7 @@ fun SwipeToRefreshLayout(
8282
// TODO (https://issuetracker.google.com/issues/164113834): This state->event trampoline is a
8383
// workaround for a bug in the SwipableState API. Currently, state.value is a duplicated
8484
// source of truth of refreshingState.
85-
DisposableEffect(refreshingState) {
86-
state.animateTo(refreshingState)
87-
onDispose {}
88-
}
85+
LaunchedEffect(refreshingState) { state.animateTo(refreshingState) }
8986
}
9087
}
9188

@@ -117,26 +114,23 @@ private val <T> SwipeableState<T>.PreUpPostDownNestedScrollConnection: NestedScr
117114
}
118115
}
119116

120-
override fun onPreFling(available: Velocity): Velocity {
117+
override suspend fun onPreFling(available: Velocity): Velocity {
121118
val toFling = Offset(available.x, available.y).toFloat()
122119
return if (toFling < 0) {
123-
performFling(velocity = toFling) {}
120+
performFling(velocity = toFling)
124121
// since we go to the anchor with tween settling, consume all for the best UX
125122
available
126123
} else {
127124
Velocity.Zero
128125
}
129126
}
130127

131-
override fun onPostFling(
128+
override suspend fun onPostFling(
132129
consumed: Velocity,
133-
available: Velocity,
134-
onFinished: (Velocity) -> Unit
135-
) {
136-
performFling(velocity = Offset(available.x, available.y).toFloat()) {
137-
// since we go to the anchor with tween settling, consume all for the best UX
138-
onFinished.invoke(available)
139-
}
130+
available: Velocity
131+
): Velocity {
132+
performFling(velocity = Offset(available.x, available.y).toFloat())
133+
return Velocity.Zero
140134
}
141135

142136
private fun Float.toOffset(): Offset = Offset(0f, this)

‎JetNews/app/src/main/java/com/example/jetnews/ui/article/ArticleScreen.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import android.content.Intent
2121
import androidx.compose.foundation.layout.Row
2222
import androidx.compose.foundation.layout.Spacer
2323
import androidx.compose.foundation.layout.fillMaxWidth
24+
import androidx.compose.foundation.layout.height
2425
import androidx.compose.foundation.layout.padding
25-
import androidx.compose.foundation.layout.preferredHeight
2626
import androidx.compose.material.AlertDialog
2727
import androidx.compose.material.Icon
2828
import androidx.compose.material.IconButton
@@ -144,7 +144,7 @@ fun ArticleScreen(
144144
}
145145
)
146146
},
147-
bodyContent = { innerPadding ->
147+
content = { innerPadding ->
148148
val modifier = Modifier.padding(innerPadding)
149149
PostContent(post, modifier)
150150
},
@@ -178,7 +178,7 @@ private fun BottomBar(
178178
Row(
179179
verticalAlignment = Alignment.CenterVertically,
180180
modifier = Modifier
181-
.preferredHeight(56.dp)
181+
.height(56.dp)
182182
.fillMaxWidth()
183183
) {
184184
IconButton(onClick = onUnimplementedAction) {

‎JetNews/app/src/main/java/com/example/jetnews/ui/article/PostContent.kt

+15-15
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ import androidx.compose.foundation.layout.Column
2323
import androidx.compose.foundation.layout.Row
2424
import androidx.compose.foundation.layout.Spacer
2525
import androidx.compose.foundation.layout.fillMaxWidth
26+
import androidx.compose.foundation.layout.height
2627
import androidx.compose.foundation.layout.heightIn
2728
import androidx.compose.foundation.layout.padding
28-
import androidx.compose.foundation.layout.preferredHeight
29-
import androidx.compose.foundation.layout.preferredSize
30-
import androidx.compose.foundation.layout.preferredWidth
29+
import androidx.compose.foundation.layout.size
30+
import androidx.compose.foundation.layout.width
3131
import androidx.compose.foundation.lazy.LazyColumn
3232
import androidx.compose.foundation.lazy.items
3333
import androidx.compose.foundation.shape.CircleShape
@@ -42,7 +42,7 @@ import androidx.compose.material.Typography
4242
import androidx.compose.material.icons.Icons
4343
import androidx.compose.material.icons.filled.AccountCircle
4444
import androidx.compose.runtime.Composable
45-
import androidx.compose.runtime.Providers
45+
import androidx.compose.runtime.CompositionLocalProvider
4646
import androidx.compose.ui.Modifier
4747
import androidx.compose.ui.draw.clip
4848
import androidx.compose.ui.graphics.Color
@@ -82,34 +82,34 @@ fun PostContent(post: Post, modifier: Modifier = Modifier) {
8282
modifier = modifier.padding(horizontal = defaultSpacerSize)
8383
) {
8484
item {
85-
Spacer(Modifier.preferredHeight(defaultSpacerSize))
85+
Spacer(Modifier.height(defaultSpacerSize))
8686
PostHeaderImage(post)
8787
}
8888
item {
8989
Text(text = post.title, style = MaterialTheme.typography.h4)
90-
Spacer(Modifier.preferredHeight(8.dp))
90+
Spacer(Modifier.height(8.dp))
9191
}
9292
post.subtitle?.let { subtitle ->
9393
item {
94-
Providers(LocalContentAlpha provides ContentAlpha.medium) {
94+
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
9595
Text(
9696
text = subtitle,
9797
style = MaterialTheme.typography.body2,
9898
lineHeight = 20.sp
9999
)
100100
}
101-
Spacer(Modifier.preferredHeight(defaultSpacerSize))
101+
Spacer(Modifier.height(defaultSpacerSize))
102102
}
103103
}
104104
item {
105105
PostMetadata(post.metadata)
106-
Spacer(Modifier.preferredHeight(24.dp))
106+
Spacer(Modifier.height(24.dp))
107107
}
108108
items(post.paragraphs) {
109109
Paragraph(paragraph = it)
110110
}
111111
item {
112-
Spacer(Modifier.preferredHeight(48.dp))
112+
Spacer(Modifier.height(48.dp))
113113
}
114114
}
115115
}
@@ -126,7 +126,7 @@ private fun PostHeaderImage(post: Post) {
126126
modifier = imageModifier,
127127
contentScale = ContentScale.Crop
128128
)
129-
Spacer(Modifier.preferredHeight(defaultSpacerSize))
129+
Spacer(Modifier.height(defaultSpacerSize))
130130
}
131131

132132
@Composable
@@ -139,19 +139,19 @@ private fun PostMetadata(metadata: Metadata) {
139139
Image(
140140
imageVector = Icons.Filled.AccountCircle,
141141
contentDescription = null, // decorative
142-
modifier = Modifier.preferredSize(40.dp),
142+
modifier = Modifier.size(40.dp),
143143
colorFilter = ColorFilter.tint(LocalContentColor.current),
144144
contentScale = ContentScale.Fit
145145
)
146-
Spacer(Modifier.preferredWidth(8.dp))
146+
Spacer(Modifier.width(8.dp))
147147
Column {
148148
Text(
149149
text = metadata.author.name,
150150
style = typography.caption,
151151
modifier = Modifier.padding(top = 4.dp)
152152
)
153153

154-
Providers(LocalContentAlpha provides ContentAlpha.medium) {
154+
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
155155
Text(
156156
text = "${metadata.date}${metadata.readTimeMinutes} min read",
157157
style = typography.caption
@@ -228,7 +228,7 @@ private fun BulletParagraph(
228228
// this box is acting as a character, so it's sized with font scaling (sp)
229229
Box(
230230
modifier = Modifier
231-
.preferredSize(8.sp.toDp(), 8.sp.toDp())
231+
.size(8.sp.toDp(), 8.sp.toDp())
232232
.alignBy {
233233
// Add an alignment "baseline" 1sp below the bottom of the circle
234234
9.sp.roundToPx()

‎JetNews/app/src/main/java/com/example/jetnews/ui/home/HomeScreen.kt

+6-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import androidx.compose.foundation.layout.Box
2121
import androidx.compose.foundation.layout.Column
2222
import androidx.compose.foundation.layout.fillMaxSize
2323
import androidx.compose.foundation.layout.padding
24-
import androidx.compose.foundation.layout.preferredSize
24+
import androidx.compose.foundation.layout.size
2525
import androidx.compose.foundation.layout.wrapContentSize
2626
import androidx.compose.foundation.lazy.LazyColumn
2727
import androidx.compose.foundation.lazy.LazyRow
@@ -157,12 +157,13 @@ fun HomeScreen(
157157
}
158158
}
159159

160+
val coroutineScope = rememberCoroutineScope()
160161
Scaffold(
161162
scaffoldState = scaffoldState,
162163
drawerContent = {
163164
AppDrawer(
164165
currentScreen = Screen.Home,
165-
closeDrawer = { scaffoldState.drawerState.close() },
166+
closeDrawer = { coroutineScope.launch { scaffoldState.drawerState.close() } },
166167
navigateTo = navigateTo
167168
)
168169
},
@@ -171,7 +172,7 @@ fun HomeScreen(
171172
TopAppBar(
172173
title = { Text(text = title) },
173174
navigationIcon = {
174-
IconButton(onClick = { scaffoldState.drawerState.open() }) {
175+
IconButton(onClick = { coroutineScope.launch { scaffoldState.drawerState.open() } }) {
175176
Icon(
176177
painter = painterResource(R.drawable.ic_jetnews_logo),
177178
contentDescription = stringResource(R.string.cd_open_navigation_drawer)
@@ -180,7 +181,7 @@ fun HomeScreen(
180181
}
181182
)
182183
},
183-
bodyContent = { innerPadding ->
184+
content = { innerPadding ->
184185
val modifier = Modifier.padding(innerPadding)
185186
LoadingContent(
186187
empty = posts.initialLoad,
@@ -231,7 +232,7 @@ private fun LoadingContent(
231232
Surface(elevation = 10.dp, shape = CircleShape) {
232233
CircularProgressIndicator(
233234
modifier = Modifier
234-
.preferredSize(36.dp)
235+
.size(36.dp)
235236
.padding(4.dp)
236237
)
237238
}

‎JetNews/app/src/main/java/com/example/jetnews/ui/home/PostCardTop.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ import androidx.compose.foundation.Image
2020
import androidx.compose.foundation.layout.Column
2121
import androidx.compose.foundation.layout.Spacer
2222
import androidx.compose.foundation.layout.fillMaxWidth
23+
import androidx.compose.foundation.layout.height
2324
import androidx.compose.foundation.layout.heightIn
2425
import androidx.compose.foundation.layout.padding
25-
import androidx.compose.foundation.layout.preferredHeight
2626
import androidx.compose.material.ContentAlpha
2727
import androidx.compose.material.LocalContentAlpha
2828
import androidx.compose.material.MaterialTheme
2929
import androidx.compose.material.Text
3030
import androidx.compose.runtime.Composable
31-
import androidx.compose.runtime.Providers
31+
import androidx.compose.runtime.CompositionLocalProvider
3232
import androidx.compose.ui.Modifier
3333
import androidx.compose.ui.draw.clip
3434
import androidx.compose.ui.layout.ContentScale
@@ -55,7 +55,7 @@ fun PostCardTop(post: Post, modifier: Modifier = Modifier) {
5555
modifier = imageModifier,
5656
contentScale = ContentScale.Crop
5757
)
58-
Spacer(Modifier.preferredHeight(16.dp))
58+
Spacer(Modifier.height(16.dp))
5959

6060
Text(
6161
text = post.title,
@@ -66,7 +66,7 @@ fun PostCardTop(post: Post, modifier: Modifier = Modifier) {
6666
style = typography.body2
6767
)
6868

69-
Providers(LocalContentAlpha provides ContentAlpha.medium) {
69+
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
7070
Text(
7171
text = "${post.metadata.date} - ${post.metadata.readTimeMinutes} min read",
7272
style = typography.body2

‎JetNews/app/src/main/java/com/example/jetnews/ui/home/PostCardYourNetwork.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import androidx.compose.foundation.Image
2020
import androidx.compose.foundation.clickable
2121
import androidx.compose.foundation.layout.Column
2222
import androidx.compose.foundation.layout.fillMaxWidth
23+
import androidx.compose.foundation.layout.height
2324
import androidx.compose.foundation.layout.padding
24-
import androidx.compose.foundation.layout.preferredHeight
25-
import androidx.compose.foundation.layout.preferredSize
25+
import androidx.compose.foundation.layout.size
2626
import androidx.compose.material.Card
2727
import androidx.compose.material.MaterialTheme
2828
import androidx.compose.material.Text
@@ -47,7 +47,7 @@ fun PostCardPopular(
4747
) {
4848
Card(
4949
shape = MaterialTheme.shapes.medium,
50-
modifier = modifier.preferredSize(280.dp, 240.dp)
50+
modifier = modifier.size(280.dp, 240.dp)
5151
) {
5252
Column(modifier = Modifier.clickable(onClick = { navigateTo(Screen.Article(post.id)) })) {
5353

@@ -56,7 +56,7 @@ fun PostCardPopular(
5656
contentDescription = null, // decorative
5757
contentScale = ContentScale.Crop,
5858
modifier = Modifier
59-
.preferredHeight(100.dp)
59+
.height(100.dp)
6060
.fillMaxWidth()
6161
)
6262

0 commit comments

Comments
 (0)