From cdf9ed811f0fc3dcb0bc0aa473fb10393c636c85 Mon Sep 17 00:00:00 2001 From: Yuichi Araki Date: Fri, 20 May 2022 13:49:13 +0900 Subject: [PATCH 1/2] MotionCompose: Update dependencies Migrate from accompanist-insets to the official 'androidx.compose.foundation' insets. https://google.github.io/accompanist/insets/#migration Change-Id: I4a1593141c8232d94f2d2c995b03d327daa2669a --- MotionCompose/app/build.gradle | 17 +++++----- .../compose/motion/demo/SimpleScaffold.kt | 16 ++++------ .../demo/fadethrough/FadeThroughDemo.kt | 2 -- .../motion/demo/loading/LoadingDemo.kt | 26 ++++++---------- .../motion/demo/sharedaxis/SharedAxisDemo.kt | 13 ++------ .../sharedtransform/SharedTransformDemo.kt | 4 +-- .../example/android/compose/motion/ui/Main.kt | 31 +++++++++---------- .../android/compose/motion/ui/Theme.kt | 7 +++-- .../android/compose/motion/ui/home/Home.kt | 27 +++++++--------- MotionCompose/build.gradle | 4 +-- 10 files changed, 59 insertions(+), 88 deletions(-) diff --git a/MotionCompose/app/build.gradle b/MotionCompose/app/build.gradle index 27a7c5fa..95c31fb7 100644 --- a/MotionCompose/app/build.gradle +++ b/MotionCompose/app/build.gradle @@ -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' @@ -62,21 +62,20 @@ android { dependencies { implementation 'androidx.core:core-ktx:1.7.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.9-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' diff --git a/MotionCompose/app/src/main/java/com/example/android/compose/motion/demo/SimpleScaffold.kt b/MotionCompose/app/src/main/java/com/example/android/compose/motion/demo/SimpleScaffold.kt index 0f97eb9c..15343fea 100644 --- a/MotionCompose/app/src/main/java/com/example/android/compose/motion/demo/SimpleScaffold.kt +++ b/MotionCompose/app/src/main/java/com/example/android/compose/motion/demo/SimpleScaffold.kt @@ -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 @@ -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() } diff --git a/MotionCompose/app/src/main/java/com/example/android/compose/motion/demo/fadethrough/FadeThroughDemo.kt b/MotionCompose/app/src/main/java/com/example/android/compose/motion/demo/fadethrough/FadeThroughDemo.kt index b053ba05..76d24d79 100644 --- a/MotionCompose/app/src/main/java/com/example/android/compose/motion/demo/fadethrough/FadeThroughDemo.kt +++ b/MotionCompose/app/src/main/java/com/example/android/compose/motion/demo/fadethrough/FadeThroughDemo.kt @@ -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 @@ -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) { diff --git a/MotionCompose/app/src/main/java/com/example/android/compose/motion/demo/loading/LoadingDemo.kt b/MotionCompose/app/src/main/java/com/example/android/compose/motion/demo/loading/LoadingDemo.kt index ce590078..13c6e6bd 100644 --- a/MotionCompose/app/src/main/java/com/example/android/compose/motion/demo/loading/LoadingDemo.kt +++ b/MotionCompose/app/src/main/java/com/example/android/compose/motion/demo/loading/LoadingDemo.kt @@ -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 @@ -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 @@ -91,20 +93,13 @@ private fun LoadingDemoContent( cheeses: LazyPagingItems, 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( @@ -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. diff --git a/MotionCompose/app/src/main/java/com/example/android/compose/motion/demo/sharedaxis/SharedAxisDemo.kt b/MotionCompose/app/src/main/java/com/example/android/compose/motion/demo/sharedaxis/SharedAxisDemo.kt index 9a0f1c47..e41f0122 100644 --- a/MotionCompose/app/src/main/java/com/example/android/compose/motion/demo/sharedaxis/SharedAxisDemo.kt +++ b/MotionCompose/app/src/main/java/com/example/android/compose/motion/demo/sharedaxis/SharedAxisDemo.kt @@ -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 @@ -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() { @@ -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( diff --git a/MotionCompose/app/src/main/java/com/example/android/compose/motion/demo/sharedtransform/SharedTransformDemo.kt b/MotionCompose/app/src/main/java/com/example/android/compose/motion/demo/sharedtransform/SharedTransformDemo.kt index 43ca8f67..ffa78f98 100644 --- a/MotionCompose/app/src/main/java/com/example/android/compose/motion/demo/sharedtransform/SharedTransformDemo.kt +++ b/MotionCompose/app/src/main/java/com/example/android/compose/motion/demo/sharedtransform/SharedTransformDemo.kt @@ -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 @@ -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) diff --git a/MotionCompose/app/src/main/java/com/example/android/compose/motion/ui/Main.kt b/MotionCompose/app/src/main/java/com/example/android/compose/motion/ui/Main.kt index 9fc7b518..1350ddf7 100644 --- a/MotionCompose/app/src/main/java/com/example/android/compose/motion/ui/Main.kt +++ b/MotionCompose/app/src/main/java/com/example/android/compose/motion/ui/Main.kt @@ -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 } } } } diff --git a/MotionCompose/app/src/main/java/com/example/android/compose/motion/ui/Theme.kt b/MotionCompose/app/src/main/java/com/example/android/compose/motion/ui/Theme.kt index 420cef4e..e3f23395 100644 --- a/MotionCompose/app/src/main/java/com/example/android/compose/motion/ui/Theme.kt +++ b/MotionCompose/app/src/main/java/com/example/android/compose/motion/ui/Theme.kt @@ -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) @@ -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 } } diff --git a/MotionCompose/app/src/main/java/com/example/android/compose/motion/ui/home/Home.kt b/MotionCompose/app/src/main/java/com/example/android/compose/motion/ui/home/Home.kt index 1a5a4fb8..93cf6f2c 100644 --- a/MotionCompose/app/src/main/java/com/example/android/compose/motion/ui/home/Home.kt +++ b/MotionCompose/app/src/main/java/com/example/android/compose/motion/ui/home/Home.kt @@ -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 @@ -41,14 +44,13 @@ 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( @@ -56,19 +58,15 @@ fun Home( 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) ) } } @@ -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 -> @@ -98,6 +93,7 @@ private fun DemoList( } } +@OptIn(ExperimentalMaterial3Api::class) @Composable private fun DemoCard( demo: Demo, @@ -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), diff --git a/MotionCompose/build.gradle b/MotionCompose/build.gradle index e11a1109..6c746913 100644 --- a/MotionCompose/build.gradle +++ b/MotionCompose/build.gradle @@ -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) { From 4eab85159c40e425dd501763980671582a7c3247 Mon Sep 17 00:00:00 2001 From: Yuichi Araki Date: Mon, 6 Jun 2022 10:26:39 +0900 Subject: [PATCH 2/2] MotionCompose: Update accompanist Change-Id: I21163057190e1c2fd647c2f312d298701c8fc5a7 --- MotionCompose/app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MotionCompose/app/build.gradle b/MotionCompose/app/build.gradle index 95c31fb7..9ac554ad 100644 --- a/MotionCompose/app/build.gradle +++ b/MotionCompose/app/build.gradle @@ -60,7 +60,7 @@ 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-alpha13' implementation "androidx.compose.ui:ui-tooling-preview:$compose_version" @@ -68,7 +68,7 @@ dependencies { implementation 'androidx.activity:activity-compose:1.4.0' implementation 'androidx.constraintlayout:constraintlayout-compose:1.0.1' - def accompanist_version = '0.24.9-beta' + def accompanist_version = '0.24.10-beta' implementation "com.google.accompanist:accompanist-flowlayout:$accompanist_version" implementation "com.google.accompanist:accompanist-placeholder:$accompanist_version"