Skip to content

Commit

Permalink
Merge pull request #90 from android/yaraki/MotionCompose-update
Browse files Browse the repository at this point in the history
MotionCompose: Update dependencies
  • Loading branch information
yaraki authored Jun 6, 2022
2 parents d7d507d + 4eab851 commit 95cd0cc
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 89 deletions.
19 changes: 9 additions & 10 deletions MotionCompose/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ plugins {
}

android {
compileSdk 31
compileSdk 32

defaultConfig {
applicationId 'com.example.android.compose.motion'
minSdk 21
targetSdk 31
targetSdk 32
versionCode 1
versionName '1.0'
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
Expand Down Expand Up @@ -60,23 +60,22 @@ android {
}

dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.core:core-ktx:1.8.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation 'androidx.compose.material3:material3:1.0.0-alpha02'
implementation 'androidx.compose.material3:material3:1.0.0-alpha13'
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
implementation 'androidx.activity:activity-compose:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout-compose:1.0.0-rc02'
implementation 'androidx.constraintlayout:constraintlayout-compose:1.0.1'

def accompanist_version = '0.22.0-rc'
def accompanist_version = '0.24.10-beta'
implementation "com.google.accompanist:accompanist-flowlayout:$accompanist_version"
implementation "com.google.accompanist:accompanist-insets-ui:$accompanist_version"
implementation "com.google.accompanist:accompanist-placeholder:$accompanist_version"

def lifecycle_version = '2.4.0'
def lifecycle_version = '2.4.1'
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version"

implementation "androidx.paging:paging-compose:1.0.0-alpha14"
implementation "androidx.paging:paging-compose:1.0.0-alpha15"

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'com.google.truth:truth:1.1.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SmallTopAppBar
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.google.accompanist.insets.LocalWindowInsets
import com.google.accompanist.insets.rememberInsetsPaddingValues

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand All @@ -43,18 +42,15 @@ fun SimpleScaffold(
Text(text = title)
},
modifier = Modifier
.padding(
rememberInsetsPaddingValues(
insets = LocalWindowInsets.current.systemBars,
applyBottom = false
)
)
.statusBarsPadding()
)
},
modifier = modifier
) {
) { padding ->
Box(
modifier = Modifier.fillMaxSize()
modifier = Modifier
.fillMaxSize()
.padding(padding)
) {
content()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material.icons.filled.Share
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
Expand All @@ -68,7 +67,6 @@ import com.example.android.compose.motion.demo.Demo
import com.example.android.compose.motion.demo.SimpleScaffold
import com.example.android.compose.motion.ui.MotionComposeTheme

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun FadeThroughDemo() {
SimpleScaffold(title = Demo.FadeThrough.title) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ import androidx.compose.animation.core.keyframes
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
Expand Down Expand Up @@ -63,8 +67,6 @@ import androidx.paging.compose.collectAsLazyPagingItems
import androidx.paging.compose.itemsIndexed
import com.example.android.compose.motion.demo.Cheese
import com.example.android.compose.motion.demo.Demo
import com.google.accompanist.insets.LocalWindowInsets
import com.google.accompanist.insets.rememberInsetsPaddingValues
import com.google.accompanist.placeholder.PlaceholderHighlight
import com.google.accompanist.placeholder.fade
import com.google.accompanist.placeholder.placeholder
Expand All @@ -91,20 +93,13 @@ private fun LoadingDemoContent(
cheeses: LazyPagingItems<Cheese>,
onRefresh: () -> Unit
) {
val systemBars = LocalWindowInsets.current.systemBars
Scaffold(
topBar = {
SmallTopAppBar(
title = {
Text(text = Demo.Loading.title)
},
modifier = Modifier
.padding(
rememberInsetsPaddingValues(
insets = systemBars,
applyBottom = false
)
),
modifier = Modifier.statusBarsPadding(),
actions = {
IconButton(onClick = onRefresh) {
Icon(
Expand All @@ -115,14 +110,13 @@ private fun LoadingDemoContent(
}
)
}
) {
) { padding ->
val startTimeMillis = remember(cheeses) { SystemClock.uptimeMillis() }
LazyColumn(
modifier = Modifier.fillMaxSize(),
contentPadding = rememberInsetsPaddingValues(
insets = systemBars,
applyTop = false
)
modifier = Modifier
.fillMaxSize()
.padding(padding),
contentPadding = WindowInsets.navigationBars.asPaddingValues()
) {
itemsIndexed(items = cheeses) { index, cheese ->
// Calculate the offset used to animate the placeholder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
Expand Down Expand Up @@ -71,8 +72,6 @@ import com.example.android.compose.motion.demo.CheeseNames
import com.example.android.compose.motion.demo.Demo
import com.example.android.compose.motion.demo.SimpleScaffold
import com.example.android.compose.motion.ui.MotionComposeTheme
import com.google.accompanist.insets.LocalWindowInsets
import com.google.accompanist.insets.rememberInsetsPaddingValues

@Composable
fun SharedAxisDemo() {
Expand Down Expand Up @@ -249,18 +248,10 @@ private fun PageContent(
page: Page,
modifier: Modifier = Modifier
) {
val systemBars = LocalWindowInsets.current.systemBars
Column(
modifier = modifier
.verticalScroll(rememberScrollState())
.padding(
rememberInsetsPaddingValues(
insets = systemBars,
applyStart = false,
applyTop = false,
additionalBottom = 16.dp
)
),
.navigationBarsPadding(),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Image(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Divider
import androidx.compose.material3.Divider
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
Expand Down Expand Up @@ -131,7 +131,7 @@ private fun DemoCard(
Color.Transparent
}
}
Divider( // TODO: Replace with Material3 Divider when it's available.
Divider(
modifier = Modifier.constrainAs(divider) {
top.linkTo(content.bottom)
start.linkTo(parent.start)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,23 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import com.example.android.compose.motion.demo.Demo
import com.example.android.compose.motion.ui.home.Home
import com.google.accompanist.insets.ProvideWindowInsets

@Composable
fun Main() {
ProvideWindowInsets {
MotionComposeTheme {
var currentDemo: Demo? by rememberSaveable {
mutableStateOf(null)
}
Crossfade(targetState = currentDemo) { targetDemo ->
if (targetDemo == null) {
Home(
onDemoSelected = { demo ->
currentDemo = demo
}
)
} else {
targetDemo.content()
BackHandler { currentDemo = null }
}
MotionComposeTheme {
var currentDemo: Demo? by rememberSaveable {
mutableStateOf(null)
}
Crossfade(targetState = currentDemo) { targetDemo ->
if (targetDemo == null) {
Home(
onDemoSelected = { demo ->
currentDemo = demo
}
)
} else {
targetDemo.content()
BackHandler { currentDemo = null }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat

val Purple80 = Color(0xFFD0BCFF)
val PurpleGrey80 = Color(0xFFCCC2DC)
Expand Down Expand Up @@ -69,8 +69,9 @@ fun MotionComposeTheme(
val view = LocalView.current
if (!view.isInEditMode) {
SideEffect {
(view.context as Activity).window.statusBarColor = colorScheme.primary.toArgb()
ViewCompat.getWindowInsetsController(view)?.isAppearanceLightStatusBars = darkTheme
val window = (view.context as Activity).window
window.statusBarColor = colorScheme.primary.toArgb()
WindowCompat.getInsetsController(window, view)?.isAppearanceLightStatusBars = darkTheme
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ package com.example.android.compose.motion.ui.home
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
Expand All @@ -41,34 +44,29 @@ import com.example.android.compose.motion.R
import com.example.android.compose.motion.demo.Demo
import com.example.android.compose.motion.ui.MotionComposeTheme
import com.google.accompanist.flowlayout.FlowRow
import com.google.accompanist.insets.LocalWindowInsets
import com.google.accompanist.insets.rememberInsetsPaddingValues

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun Home(
onDemoSelected: (demo: Demo) -> Unit
) {
WindowInsets
Scaffold(
topBar = {
SmallTopAppBar(
title = {
Text(text = stringResource(R.string.app_name))
},
modifier = Modifier
.padding(
rememberInsetsPaddingValues(
insets = LocalWindowInsets.current.systemBars,
applyBottom = false
)
)
.statusBarsPadding()
)
}
) {
) { innerPadding ->
DemoList(
onDemoSelected = onDemoSelected,
modifier = Modifier
.fillMaxSize()
.padding(innerPadding)
)
}
}
Expand All @@ -80,10 +78,7 @@ private fun DemoList(
) {
LazyColumn(
modifier = modifier,
contentPadding = rememberInsetsPaddingValues(
insets = LocalWindowInsets.current.systemBars,
applyTop = false
),
contentPadding = WindowInsets.navigationBars.asPaddingValues(),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
items(items = Demo.values()) { demo ->
Expand All @@ -98,6 +93,7 @@ private fun DemoList(
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun DemoCard(
demo: Demo,
Expand All @@ -108,8 +104,7 @@ private fun DemoCard(
modifier = modifier,
tonalElevation = 2.dp,
shape = RoundedCornerShape(16.dp),
onClick = onClick,
indication = rememberRipple()
onClick = onClick
) {
Column(
modifier = Modifier.padding(16.dp),
Expand Down
4 changes: 2 additions & 2 deletions MotionCompose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

buildscript {
ext {
compose_version = '1.1.0-rc01'
compose_version = '1.2.0-beta03'
}
}

plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.0' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}

task clean(type: Delete) {
Expand Down

0 comments on commit 95cd0cc

Please sign in to comment.