Skip to content

Commit fd91e3a

Browse files
authored
Merge pull request #490 from android/dev_beta06
[All] Update to Compose beta06
2 parents 67c3a9c + 188b4fb commit fd91e3a

File tree

38 files changed

+169
-128
lines changed

38 files changed

+169
-128
lines changed

Crane/README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Studies built with [Jetpack Compose](https://developer.android.com/jetpack/compo
55
The goal of the sample is to showcase Material components, draggable UI elements, Android Views
66
inside Compose, and UI state handling.
77

8-
To try out this sample app, you need to use the latest Canary version of Android Studio 4.2.
8+
To try out this sample app, you need to use the latest Canary version of Android Studio Arctic Fox.
99
You can clone this repository or import the
1010
project from Android Studio following the steps
1111
[here](https://developer.android.com/jetpack/compose/setup#sample).
@@ -22,8 +22,6 @@ the bottom of the screen.
2222
- __Home__ [screen][home] where you can explore flights, hotels, and restaurants specifying
2323
the number of people.
2424
- Clicking on the number of people refreshes the destinations.
25-
- The [backdrop](https://material.io/components/backdrop) is draggable and can pin to the top of
26-
the screen, just under the search criteria, and to the bottom. Implemented [here][backdrop].
2725
- Destination's images are retrieved using the [coil-accompanist][coil-accompanist] library.
2826
- __Calendar__ [screen][calendar]. Tapping on __Select Dates__ takes you to a calendar built
2927
completely from scratch. It makes a heavy usage of Compose's state APIs.
@@ -32,6 +30,9 @@ implemented using a different Activity will be displayed. In there, you can see
3230
embedded in Compose and Compose buttons updating the Android View. Notice how you can also
3331
interact with the `MapView` seamlessly.
3432

33+
Crane is a multi-activity app that showcases how navigating between activities can be done in
34+
Jetpack Compose.
35+
3536
## Hilt
3637

3738
Crane uses [Hilt][hilt] to manage its dependencies. Hilt's ViewModel (with the
@@ -48,8 +49,9 @@ class MainViewModel @Inject constructor(
4849
) : ViewModel() { ... }
4950
5051
@Composable
51-
fun CraneHomeContent(...) {
52-
val viewModel: MainViewModel = viewModel()
52+
fun CraneHomeContent(
53+
viewModel: MainViewModel = viewModel()
54+
) {
5355
...
5456
}
5557
```
@@ -75,11 +77,9 @@ and include it in the `local.properties` file as follows:
7577
google.maps.key={insert_your_api_key_here}
7678
```
7779

78-
## Data
80+
## Images
7981

80-
The data is hardcoded in the _CraneData_ [file][data] and exposed to the UI using the
81-
[MainViewModel][mainViewModel]. Image resources are retrieved from
82-
[Unsplash](https://unsplash.com/).
82+
Image resources are retrieved from [Unsplash](https://unsplash.com/).
8383

8484
## Testing
8585

@@ -107,10 +107,8 @@ limitations under the License.
107107

108108
[landing]: app/src/main/java/androidx/compose/samples/crane/home/LandingScreen.kt
109109
[home]: app/src/main/java/androidx/compose/samples/crane/home/CraneHome.kt
110-
[backdrop]: app/src/main/java/androidx/compose/samples/crane/ui/BackdropFrontLayer.kt
111110
[calendar]: app/src/main/java/androidx/compose/samples/crane/calendar/Calendar.kt
112111
[details]: app/src/main/java/androidx/compose/samples/crane/details/DetailsActivity.kt
113-
[data]: app/src/main/java/androidx/compose/samples/crane/data/CraneData.kt
114112
[mainViewModel]: app/src/main/java/androidx/compose/samples/crane/home/MainViewModel.kt
115113
[detailsViewModel]: app/src/main/java/androidx/compose/samples/crane/details/DetailsViewModel.kt
116114
[homeTest]: app/src/androidTest/java/androidx/compose/samples/crane/home/HomeTest.kt

Crane/app/src/androidTest/java/androidx/compose/samples/crane/calendar/CalendarTest.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,19 @@ import androidx.compose.samples.crane.calendar.model.DaySelectedStatus.NoSelecte
2525
import androidx.compose.samples.crane.calendar.model.DaySelectedStatus.Selected
2626
import androidx.compose.samples.crane.data.DatesRepository
2727
import androidx.compose.samples.crane.ui.CraneTheme
28+
import androidx.compose.ui.test.ExperimentalTestApi
2829
import androidx.compose.ui.test.SemanticsMatcher
2930
import androidx.compose.ui.test.assertContentDescriptionEquals
3031
import androidx.compose.ui.test.assertIsDisplayed
32+
import androidx.compose.ui.test.hasScrollToKeyAction
3133
import androidx.compose.ui.test.junit4.ComposeTestRule
3234
import androidx.compose.ui.test.junit4.createAndroidComposeRule
3335
import androidx.compose.ui.test.onNodeWithContentDescription
3436
import androidx.compose.ui.test.performClick
35-
import androidx.compose.ui.test.performScrollTo
37+
import androidx.compose.ui.test.performScrollToKey
3638
import dagger.hilt.android.testing.HiltAndroidRule
3739
import dagger.hilt.android.testing.HiltAndroidTest
3840
import org.junit.Before
39-
import org.junit.Ignore
4041
import org.junit.Rule
4142
import org.junit.Test
4243
import javax.inject.Inject
@@ -66,11 +67,12 @@ class CalendarTest {
6667
}
6768
}
6869

69-
@Ignore("performScrollTo doesn't work with LazyLists: issuetracker.google.com/178483889")
70+
@ExperimentalTestApi
7071
@Test
7172
fun scrollsToTheBottom() {
7273
composeTestRule.onNodeWithContentDescription("January 1").assertIsDisplayed()
73-
composeTestRule.onNodeWithContentDescription("December 31").performScrollTo().performClick()
74+
composeTestRule.onNode(hasScrollToKeyAction()).performScrollToKey("2020/12/4")
75+
composeTestRule.onNodeWithContentDescription("December 31").performClick()
7476
assert(datesRepository.datesSelected.toString() == "Dec 31")
7577
}
7678

Crane/app/src/main/java/androidx/compose/samples/crane/base/ExploreSection.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private fun ExploreItem(
107107
modifier = Modifier.fillMaxSize(),
108108
)
109109

110-
if (painter.loadState == ImageLoadState.Loading) {
110+
if (painter.loadState is ImageLoadState.Loading) {
111111
Image(
112112
painter = painterResource(id = R.drawable.ic_crane_logo),
113113
contentDescription = null,

Crane/app/src/main/java/androidx/compose/samples/crane/calendar/Calendar.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,12 @@ private fun LazyListScope.itemsCalendarMonth(
224224
item {
225225
DaysOfWeek(modifier = contentModifier)
226226
}
227-
for (week in month.weeks.value) {
228-
item {
227+
228+
month.weeks.value.forEachIndexed { index, week ->
229+
// A custom key needs to be given to these items so that they can be found in tests that
230+
// need scrolling. The format of the key is ${year/month/weekNumber}. Thus,
231+
// the key for the fourth week of December 2020 is "2020/12/4"
232+
item(key = "${month.year}/${month.monthNumber}/${index + 1}") {
229233
Week(
230234
modifier = contentModifier,
231235
week = week,

Crane/app/src/main/java/androidx/compose/samples/crane/util/Shapes.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import androidx.compose.ui.Modifier
2323
import androidx.compose.ui.geometry.Offset
2424
import androidx.compose.ui.geometry.Size
2525
import androidx.compose.ui.graphics.Color
26+
import androidx.compose.ui.platform.LocalLayoutDirection
27+
import androidx.compose.ui.unit.LayoutDirection
2628

2729
@Composable
2830
fun Circle(color: Color) {
@@ -33,8 +35,11 @@ fun Circle(color: Color) {
3335

3436
@Composable
3537
fun SemiRect(color: Color, lookingLeft: Boolean = true) {
38+
val layoutDirection = LocalLayoutDirection.current
3639
Canvas(Modifier.fillMaxSize()) {
37-
val offset = if (lookingLeft) {
40+
// The SemiRect should face left EITHER the lookingLeft param is true
41+
// OR the layoutDirection is Rtl
42+
val offset = if (lookingLeft xor (layoutDirection == LayoutDirection.Rtl)) {
3843
Offset(0f, 0f)
3944
} else {
4045
Offset(size.width / 2, 0f)

Crane/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ buildscript {
3131
}
3232

3333
plugins {
34-
id 'com.diffplug.spotless' version '5.11.1'
34+
id 'com.diffplug.spotless' version '5.12.4'
3535
}
3636

3737
subprojects {

Crane/buildSrc/src/main/java/com/example/crane/buildsrc/Dependencies.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
package com.example.crane.buildsrc
1818

1919
object Versions {
20-
const val ktLint = "0.40.0"
20+
const val ktLint = "0.41.0"
2121
}
2222

2323
object Libs {
24-
const val androidGradlePlugin = "com.android.tools.build:gradle:7.0.0-alpha14"
24+
const val androidGradlePlugin = "com.android.tools.build:gradle:7.0.0-alpha15"
2525
const val ktLint = "com.pinterest:ktlint:${Versions.ktLint}"
2626

2727
object GoogleMaps {
@@ -30,7 +30,7 @@ object Libs {
3030
}
3131

3232
object Accompanist {
33-
const val version = "0.8.0"
33+
const val version = "0.9.0"
3434
const val coil = "com.google.accompanist:accompanist-coil:$version"
3535
const val insets = "com.google.accompanist:accompanist-insets:$version"
3636
}
@@ -57,7 +57,7 @@ object Libs {
5757

5858
object Compose {
5959
const val snapshot = ""
60-
const val version = "1.0.0-beta05"
60+
const val version = "1.0.0-beta06"
6161

6262
const val runtime = "androidx.compose.runtime:runtime:$version"
6363
const val runtimeLivedata = "androidx.compose.runtime:runtime-livedata:$version"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-rc-2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

JetNews/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
buildscript {
1818
ext.kotlin_version = '1.4.32'
19-
ext.compose_version = '1.0.0-beta05'
19+
ext.compose_version = '1.0.0-beta06'
2020
ext.coroutines_version = '1.4.2'
2121

2222
repositories {
@@ -25,7 +25,7 @@ buildscript {
2525
}
2626

2727
dependencies {
28-
classpath 'com.android.tools.build:gradle:7.0.0-alpha14'
28+
classpath 'com.android.tools.build:gradle:7.0.0-alpha15'
2929
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
3030
}
3131
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-rc-2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)