Skip to content

Commit

Permalink
Merge pull request android#407 from android/dev_beta01
Browse files Browse the repository at this point in the history
Compose beta01
  • Loading branch information
florina-muntenescu authored Feb 24, 2021
2 parents f1e930d + 0f195d9 commit 92f2f16
Show file tree
Hide file tree
Showing 100 changed files with 831 additions and 735 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.compose.samples.crane.data.DatesRepository
import androidx.compose.samples.crane.ui.CraneTheme
import androidx.compose.ui.test.SemanticsMatcher
import androidx.compose.ui.test.assertContentDescriptionEquals
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
Expand Down Expand Up @@ -68,16 +69,17 @@ class CalendarTest {
@Ignore("performScrollTo doesn't work with LazyLists: issuetracker.google.com/178483889")
@Test
fun scrollsToTheBottom() {
composeTestRule.onNodeWithContentDescription("January 1").assertExists()
composeTestRule.onNodeWithContentDescription("January 1").assertIsDisplayed()
composeTestRule.onNodeWithContentDescription("December 31").performScrollTo().performClick()
assert(datesRepository.datesSelected.toString() == "Dec 31")
}

@Test
fun onDaySelected() {
composeTestRule.onNodeWithContentDescription("January 1").assertExists()
composeTestRule.onNodeWithContentDescription("January 2").assertExists().performClick()
composeTestRule.onNodeWithContentDescription("January 3").assertExists()
composeTestRule.onNodeWithContentDescription("January 1").assertIsDisplayed()
composeTestRule.onNodeWithContentDescription("January 2")
.assertIsDisplayed().performClick()
composeTestRule.onNodeWithContentDescription("January 3").assertIsDisplayed()

val datesNoSelected = composeTestRule.onDateNodes(NoSelected)
datesNoSelected[0].assertContentDescriptionEquals("January 1")
Expand All @@ -88,13 +90,15 @@ class CalendarTest {

@Test
fun twoDaysSelected() {
composeTestRule.onNodeWithContentDescription("January 2").assertExists().performClick()
composeTestRule.onNodeWithContentDescription("January 2")
.assertIsDisplayed().performClick()

val datesNoSelectedOneClick = composeTestRule.onDateNodes(NoSelected)
datesNoSelectedOneClick[0].assertContentDescriptionEquals("January 1")
datesNoSelectedOneClick[1].assertContentDescriptionEquals("January 3")

composeTestRule.onNodeWithContentDescription("January 4").assertExists().performClick()
composeTestRule.onNodeWithContentDescription("January 4")
.assertIsDisplayed().performClick()

composeTestRule.onDateNode(FirstDay).assertContentDescriptionEquals("January 2")
composeTestRule.onDateNode(Selected).assertContentDescriptionEquals("January 3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

package androidx.compose.samples.crane.home

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.Before
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test

Expand All @@ -41,14 +43,15 @@ class HomeTest {
}
}

@Ignore("Swipeable bug makes the app crash: https://issuetracker.google.com/180488877")
@Test
fun home_navigatesToAllScreens() {
composeTestRule.onNodeWithText("Explore Flights by Destination").assertExists()
composeTestRule.onNodeWithText("Explore Flights by Destination").assertIsDisplayed()
composeTestRule.onNodeWithText("SLEEP").performClick()
composeTestRule.onNodeWithText("Explore Properties by Destination").assertExists()
composeTestRule.onNodeWithText("Explore Properties by Destination").assertIsDisplayed()
composeTestRule.onNodeWithText("EAT").performClick()
composeTestRule.onNodeWithText("Explore Restaurants by Destination").assertExists()
composeTestRule.onNodeWithText("Explore Restaurants by Destination").assertIsDisplayed()
composeTestRule.onNodeWithText("FLY").performClick()
composeTestRule.onNodeWithText("Explore Flights by Destination").assertExists()
composeTestRule.onNodeWithText("Explore Flights by Destination").assertIsDisplayed()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.foundation.layout.preferredWidth
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.material.Icon
import androidx.compose.material.LocalContentColor
Expand All @@ -39,6 +39,7 @@ import androidx.compose.samples.crane.ui.captionTextStyle
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.tooling.preview.Preview
Expand Down Expand Up @@ -104,7 +105,7 @@ fun CraneEditableUserInput(
} else {
MaterialTheme.typography.body1.copy(color = LocalContentColor.current)
},
cursorColor = LocalContentColor.current
cursorBrush = SolidColor(LocalContentColor.current)
)
}
}
Expand All @@ -123,20 +124,20 @@ private fun CraneBaseUserInput(
Row(Modifier.padding(all = 12.dp)) {
if (vectorImageId != null) {
Icon(
modifier = Modifier.preferredSize(24.dp, 24.dp),
modifier = Modifier.size(24.dp, 24.dp),
painter = painterResource(id = vectorImageId),
tint = if (tintIcon()) tint else Color(0x80FFFFFF),
contentDescription = null
)
Spacer(Modifier.preferredWidth(8.dp))
Spacer(Modifier.width(8.dp))
}
if (caption != null && showCaption()) {
Text(
modifier = Modifier.align(Alignment.CenterVertically),
text = caption,
style = (captionTextStyle).copy(color = tint)
)
Spacer(Modifier.preferredWidth(8.dp))
Spacer(Modifier.width(8.dp))
}
Row(Modifier.weight(1f).align(Alignment.CenterVertically)) {
content()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredHeight
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
Expand All @@ -47,7 +47,7 @@ fun CraneDrawer(modifier: Modifier = Modifier) {
contentDescription = stringResource(R.string.cd_drawer)
)
for (screen in screens) {
Spacer(Modifier.preferredHeight(24.dp))
Spacer(Modifier.height(24.dp))
Text(text = screen, style = MaterialTheme.typography.h4)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.ExperimentalLayout
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredWidth
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Tab
Expand Down Expand Up @@ -58,7 +57,7 @@ fun CraneTabBar(
painter = painterResource(id = R.drawable.ic_menu),
contentDescription = stringResource(id = R.string.cd_menu)
)
Spacer(Modifier.preferredWidth(8.dp))
Spacer(Modifier.width(8.dp))
Image(
painter = painterResource(id = R.drawable.ic_crane_logo),
contentDescription = null
Expand All @@ -72,7 +71,6 @@ fun CraneTabBar(
}
}

@OptIn(ExperimentalLayout::class)
@Composable
fun CraneTabs(
modifier: Modifier = Modifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredHeight
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.foundation.layout.preferredWidth
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
Expand Down Expand Up @@ -62,7 +62,7 @@ fun ExploreSection(
text = title,
style = MaterialTheme.typography.caption.copy(color = crane_caption)
)
Spacer(Modifier.preferredHeight(8.dp))
Spacer(Modifier.height(8.dp))
LazyColumn(
modifier = Modifier.weight(1f),
) {
Expand Down Expand Up @@ -101,21 +101,21 @@ private fun ExploreItem(
loading = {
Box(Modifier.fillMaxSize()) {
Image(
modifier = Modifier.preferredSize(36.dp).align(Alignment.Center),
modifier = Modifier.size(36.dp).align(Alignment.Center),
painter = painterResource(id = R.drawable.ic_crane_logo),
contentDescription = null
)
}
}
)
}
Spacer(Modifier.preferredWidth(24.dp))
Spacer(Modifier.width(24.dp))
Column {
Text(
text = item.city.nameToDisplay,
style = MaterialTheme.typography.h6
)
Spacer(Modifier.preferredHeight(8.dp))
Spacer(Modifier.height(8.dp))
Text(
text = item.description,
style = MaterialTheme.typography.caption.copy(color = crane_caption)
Expand All @@ -126,7 +126,7 @@ private fun ExploreItem(

@Composable
private fun ExploreImageContainer(content: @Composable () -> Unit) {
Surface(Modifier.preferredSize(width = 60.dp, height = 60.dp), RoundedCornerShape(4.dp)) {
Surface(Modifier.size(width = 60.dp, height = 60.dp), RoundedCornerShape(4.dp)) {
content()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredHeight
import androidx.compose.foundation.layout.preferredHeightIn
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.lazy.LazyColumn
Expand Down Expand Up @@ -64,11 +64,11 @@ fun Calendar(
modifier: Modifier = Modifier
) {
LazyColumn(modifier) {
item { Spacer(Modifier.preferredHeight(32.dp)) }
item { Spacer(Modifier.height(32.dp)) }
for (month in calendarYear) {
itemsCalendarMonth(month = month, onDayClicked = onDayClicked)
item {
Spacer(Modifier.preferredHeight(32.dp))
Spacer(Modifier.height(32.dp))
}
}
}
Expand Down Expand Up @@ -102,7 +102,7 @@ private fun Week(
Row(modifier = modifier) {
val spaceModifiers = Modifier
.weight(1f)
.preferredHeightIn(max = CELL_SIZE)
.heightIn(max = CELL_SIZE)
Surface(modifier = spaceModifiers, color = leftFillColor) {
Spacer(Modifier.fillMaxHeight())
}
Expand Down Expand Up @@ -175,7 +175,7 @@ private fun DayContainer(
) {
// What if this doesn't fit the screen? - LayoutFlexible(1f) + LayoutAspectRatio(1f)
Surface(
modifier = modifier.preferredSize(width = CELL_SIZE, height = CELL_SIZE),
modifier = modifier.size(width = CELL_SIZE, height = CELL_SIZE),
color = backgroundColor
) {
content()
Expand Down Expand Up @@ -234,7 +234,7 @@ private fun LazyListScope.itemsCalendarMonth(
)
}
item {
Spacer(Modifier.preferredHeight(8.dp))
Spacer(Modifier.height(8.dp))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredHeight
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.MaterialTheme
Expand Down Expand Up @@ -121,7 +121,7 @@ fun DetailsScreen(
@Composable
fun DetailsContent(exploreModel: ExploreModel) {
Column(verticalArrangement = Arrangement.Center) {
Spacer(Modifier.preferredHeight(32.dp))
Spacer(Modifier.height(32.dp))
Text(
modifier = Modifier.align(Alignment.CenterHorizontally),
text = exploreModel.city.nameToDisplay,
Expand All @@ -132,7 +132,7 @@ fun DetailsContent(exploreModel: ExploreModel) {
text = exploreModel.description,
style = MaterialTheme.typography.h6
)
Spacer(Modifier.preferredHeight(16.dp))
Spacer(Modifier.height(16.dp))
CityMapView(exploreModel.city.latitude, exploreModel.city.longitude)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ import androidx.compose.material.BackdropScaffold
import androidx.compose.material.BackdropValue
import androidx.compose.material.DrawerValue
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.ModalDrawerLayout
import androidx.compose.material.ModalDrawer
import androidx.compose.material.rememberBackdropScaffoldState
import androidx.compose.material.rememberDrawerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.samples.crane.base.CraneDrawer
import androidx.compose.samples.crane.base.CraneTabBar
Expand All @@ -37,6 +38,7 @@ import androidx.compose.samples.crane.data.ExploreModel
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.lifecycle.viewmodel.compose.viewModel
import kotlinx.coroutines.launch

typealias OnExploreItemClicked = (ExploreModel) -> Unit

Expand All @@ -51,19 +53,23 @@ fun CraneHome(
modifier: Modifier = Modifier,
) {
val drawerState = rememberDrawerState(DrawerValue.Closed)
ModalDrawerLayout(
ModalDrawer(
drawerState = drawerState,
gesturesEnabled = drawerState.isOpen,
drawerContent = { CraneDrawer() },
bodyContent = {
CraneHomeContent(
modifier = modifier,
onExploreItemClicked = onExploreItemClicked,
onDateSelectionClicked = onDateSelectionClicked,
openDrawer = { drawerState.open() }
)
}
)
) {
val scope = rememberCoroutineScope()
CraneHomeContent(
modifier = modifier,
onExploreItemClicked = onExploreItemClicked,
onDateSelectionClicked = onDateSelectionClicked,
openDrawer = {
scope.launch {
drawerState.open()
}
}
)
}
}

@OptIn(ExperimentalMaterialApi::class)
Expand Down
Loading

0 comments on commit 92f2f16

Please sign in to comment.