Skip to content

Commit

Permalink
Merge "[Crane] Updates to snapshot 6759487" into material
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Vivo authored and Gerrit Code Review committed Aug 14, 2020
2 parents 6065e31 + 3c057dd commit 30e2cc8
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.state
import androidx.compose.samples.crane.R
import androidx.compose.samples.crane.ui.captionTextStyle
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -83,7 +84,7 @@ fun CraneEditableUserInput(
@DrawableRes vectorImageId: Int? = null,
onInputChanged: (String) -> Unit
) {
var textFieldState by state { TextFieldValue(text = hint) }
var textFieldState by remember { mutableStateOf(TextFieldValue(text = hint)) }
val isHint = { textFieldState.text == hint }

CraneBaseUserInput(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@

package androidx.compose.samples.crane.base

import androidx.compose.foundation.Border
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.Text
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.drawBorder
import androidx.compose.foundation.layout.ExperimentalLayout
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
Expand Down Expand Up @@ -60,46 +61,42 @@ fun CraneTabBar(
}
}

@OptIn(ExperimentalLayout::class)
@Composable
fun CraneTabs(
modifier: Modifier = Modifier,
titles: List<String>,
tabSelected: CraneScreen,
onTabSelected: (CraneScreen) -> Unit
) {
val indicatorContainer = @Composable { tabPositions: List<TabRow.TabPosition> ->
TabRow.IndicatorContainer(tabPositions, tabSelected.ordinal) {}
}

TabRow(
selectedTabIndex = tabSelected.ordinal,
modifier = modifier,
items = titles,
selectedIndex = tabSelected.ordinal,
contentColor = MaterialTheme.colors.onSurface,
indicatorContainer = indicatorContainer,
divider = {}
) { index, title ->
val selected = index == tabSelected.ordinal
val textModifier = if (!selected) {
Modifier
} else {
Modifier.drawBorder(
border = Border(2.dp, Color.White),
shape = RoundedCornerShape(16.dp)
).padding(top = 8.dp, start = 16.dp, bottom = 8.dp, end = 16.dp)
}
indicator = { },
divider = { }
) {
titles.forEachIndexed { index, title ->
val selected = index == tabSelected.ordinal

Tab(
text = {
var textModifier = Modifier.padding(vertical = 8.dp, horizontal = 16.dp)
if (selected) {
textModifier =
Modifier.border(BorderStroke(2.dp, Color.White), RoundedCornerShape(16.dp))
.then(textModifier)
}

Tab(
selected = selected,
onClick = { onTabSelected(CraneScreen.values()[index]) }
) {
Text(
modifier = textModifier,
text = title.toUpperCase(
ConfigurationCompat.getLocales(ConfigurationAmbient.current)[0]
)
)
},
selected = selected,
onSelected = { onTabSelected(CraneScreen.values()[index]) }
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private fun Month(
) {
Column(modifier = modifier) {
MonthHeader(
modifier = Modifier.padding(start = 30.dp, end = 30.dp),
modifier = Modifier.padding(horizontal = 30.dp),
month = month.name,
year = month.year
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ 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.setValue
import androidx.compose.runtime.state
import androidx.compose.samples.crane.base.CraneDrawer
import androidx.compose.samples.crane.base.CraneTabBar
import androidx.compose.samples.crane.base.CraneTabs
Expand Down Expand Up @@ -73,7 +74,7 @@ fun CraneHomeContent(
val suggestedDestinations by viewModel.suggestedDestinations.observeAsState()

val onPeopleChanged: (Int) -> Unit = { viewModel.updatePeople(it) }
var tabSelected by state { CraneScreen.Fly }
var tabSelected by remember { mutableStateOf(CraneScreen.Fly) }

BackdropFrontLayer(
modifier = modifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import androidx.compose.foundation.layout.Stack
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.state
import androidx.compose.samples.crane.base.CraneScaffold
import androidx.compose.samples.crane.calendar.launchCalendarActivity
import androidx.compose.samples.crane.details.launchDetailsActivity
Expand All @@ -57,7 +57,7 @@ class MainActivity : AppCompatActivity() {
{ launchCalendarActivity(this) }
}

var splashShown by state { SplashState.Shown }
var splashShown by remember { mutableStateOf(SplashState.Shown) }
val transition = transition(splashTransitionDefinition, splashShown)
Stack {
LandingScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

package androidx.compose.samples.crane.ui

import androidx.compose.animation.asDisposableClock
import androidx.compose.animation.core.AnimationClockObservable
import androidx.compose.animation.core.SpringSpec
import androidx.compose.foundation.Box
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.DpConstraints
Expand All @@ -27,26 +24,31 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.preferredSizeIn
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.FractionalThreshold
import androidx.compose.material.MaterialTheme
import androidx.compose.material.SwipeableState
import androidx.compose.material.fractionalThresholds
import androidx.compose.material.rememberSwipeableState
import androidx.compose.material.swipeable
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.state
import androidx.compose.runtime.structuralEqualityPolicy
import androidx.compose.ui.Modifier
import androidx.compose.ui.WithConstraints
import androidx.compose.ui.gesture.scrollorientationlocking.Orientation
import androidx.compose.ui.onPositioned
import androidx.compose.ui.platform.AnimationClockAmbient
import androidx.compose.ui.platform.DensityAmbient
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp

enum class FullScreenState {
Minimised,
Collapsed,
Expanded,
}

// BackdropFrontLayer is missing a proper nested scrolling behavior as right now,
// instead of scrolling only the parts that are visible on the screen, it scrolls
// all its content. Waiting for a NestedScrollController that makes this easier:
Expand All @@ -55,11 +57,12 @@ import androidx.compose.ui.unit.dp
@Composable
fun BackdropFrontLayer(
modifier: Modifier = Modifier,
backdropState: SwipeableBackdropState = rememberSwipeableBackdropState(),
backdropState: SwipeableState<FullScreenState> =
rememberSwipeableState(FullScreenState.Minimised),
staticChildren: @Composable (Modifier) -> Unit,
backdropChildren: @Composable (Modifier) -> Unit
) {
var backgroundChildrenSize by state(structuralEqualityPolicy()) { IntSize(0, 0) }
var backgroundChildrenSize by remember { mutableStateOf(IntSize(0, 0)) }

Box(modifier.fillMaxSize()) {
// Use ConstraintLayout in the future when
Expand All @@ -72,10 +75,8 @@ fun BackdropFrontLayer(
Modifier.swipeable(
state = backdropState,
anchors = anchors,
thresholds = fractionalThresholds(0.5f),
thresholds = { _, _ -> FractionalThreshold(0.5f) },
orientation = Orientation.Vertical,
minValue = VerticalExplorePadding,
maxValue = fullHeight,
enabled = true
)
) {
Expand Down Expand Up @@ -109,30 +110,6 @@ fun BackdropFrontLayer(
}
}

enum class FullScreenState {
Minimised,
Collapsed,
Expanded,
}

@OptIn(ExperimentalMaterialApi::class)
class SwipeableBackdropState(
initialValue: FullScreenState = FullScreenState.Minimised,
clock: AnimationClockObservable,
confirmStateChange: (FullScreenState) -> Boolean = { true }
) : SwipeableState<FullScreenState>(initialValue, clock, confirmStateChange, AnimationSpec)

@Composable
fun rememberSwipeableBackdropState(
initialValue: FullScreenState = FullScreenState.Minimised,
confirmStateChange: (FullScreenState) -> Boolean = { true }
): SwipeableBackdropState {
val clock = AnimationClockAmbient.current.asDisposableClock()
return remember(clock, confirmStateChange) {
SwipeableBackdropState(initialValue, clock, confirmStateChange)
}
}

@Composable
private fun currentConstraints(pxConstraints: Constraints): DpConstraints {
return with(DensityAmbient.current) {
Expand All @@ -156,4 +133,3 @@ private fun getAnchors(
private const val AnchorBottomOffset = 130f
private const val VerticalExplorePadding = 0f
private const val ExploreStiffness = 1000f
private val AnimationSpec = SpringSpec<Float>(stiffness = ExploreStiffness)
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ object Libs {
const val appcompat = "androidx.appcompat:appcompat:1.3.0-alpha01"

object Compose {
const val snapshot = "6721902"
const val snapshot = "6759487"
const val version = "0.1.0-SNAPSHOT"

const val runtime = "androidx.compose.runtime:runtime:$version"
Expand Down

0 comments on commit 30e2cc8

Please sign in to comment.