Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Modifier.animateBounds() to JetLagged #1473

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion JetLagged/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ dependencies {
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.compose.animation)
implementation(libs.androidx.compose.material.iconsExtended)
implementation(libs.androidx.compose.materialWindow)

implementation(libs.androidx.compose.material3.adaptive)
implementation(libs.androidx.compose.ui.googlefonts)
implementation(libs.androidx.compose.ui.tooling.preview)
debugImplementation(libs.androidx.compose.ui.tooling)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.aspectRatio
Expand Down Expand Up @@ -210,7 +209,7 @@ fun WellnessCard(
borderColor = JetLaggedTheme.extraColors.wellness,
modifier = modifier
.widthIn(max = 400.dp)
.heightIn(min = 200.dp)
.heightIn(min = 100.dp, max = 200.dp)
) {
FadingCircleBackground(36.dp, JetLaggedTheme.extraColors.wellness.copy(0.25f))
Column(
Expand All @@ -219,9 +218,8 @@ fun WellnessCard(
.fillMaxWidth()
) {
HomeScreenCardHeading(text = stringResource(R.string.wellness_heading))
FlowRow(
Row(
horizontalArrangement = Arrangement.Center,
verticalArrangement = Arrangement.Center,
modifier = Modifier.fillMaxHeight()
) {
WellnessBubble(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationDrawerItem
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.windowsizeclass.WindowSizeClass
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -55,6 +53,8 @@ import androidx.compose.ui.input.pointer.util.VelocityTracker
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.lerp
import androidx.window.core.layout.WindowSizeClass
import androidx.window.core.layout.WindowWidthSizeClass
import kotlin.coroutines.cancellation.CancellationException
import kotlinx.coroutines.launch

Expand Down Expand Up @@ -133,7 +133,7 @@ fun HomeScreenDrawer(windowSizeClass: WindowSizeClass) {
})
val decay = rememberSplineBasedDecay<Float>()
ScreenContents(
windowWidthSizeClass = windowSizeClass.widthSizeClass,
windowWidthSizeClass = windowSizeClass.windowWidthSizeClass,
selectedScreen = screenState,
onDrawerClicked = ::toggleDrawerState,
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

package com.example.jetlagged

import androidx.compose.animation.ExperimentalSharedTransitionApi
import androidx.compose.animation.animateBounds
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.VisibilityThreshold
import androidx.compose.animation.core.spring
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand All @@ -34,12 +39,16 @@ import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.runtime.movableContentOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.layout.LookaheadScope
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.window.core.layout.WindowWidthSizeClass
import com.example.jetlagged.backgrounds.movingStripesBackground
import com.example.jetlagged.data.JetLaggedHomeScreenViewModel
import com.example.jetlagged.heartrate.HeartRateCard
Expand All @@ -48,12 +57,12 @@ import com.example.jetlagged.sleep.JetLaggedSleepGraphCard
import com.example.jetlagged.ui.theme.JetLaggedTheme
import com.example.jetlagged.ui.util.MultiDevicePreview

@OptIn(ExperimentalLayoutApi::class)
@OptIn(ExperimentalLayoutApi::class, ExperimentalSharedTransitionApi::class)
@MultiDevicePreview
@Composable
fun JetLaggedScreen(
modifier: Modifier = Modifier,
windowSizeClass: WindowWidthSizeClass = WindowWidthSizeClass.Compact,
windowSizeClass: WindowWidthSizeClass = WindowWidthSizeClass.COMPACT,
viewModel: JetLaggedHomeScreenViewModel = viewModel(),
onDrawerClicked: () -> Unit = {}
) {
Expand All @@ -80,47 +89,67 @@ fun JetLaggedScreen(
val insets = WindowInsets.safeDrawing.only(
WindowInsetsSides.Bottom + WindowInsetsSides.Horizontal
)
FlowRow(
modifier = Modifier
.fillMaxSize()
.windowInsetsPadding(insets),
horizontalArrangement = Arrangement.Center,
verticalArrangement = Arrangement.Center,
maxItemsInEachRow = 3
) {
JetLaggedSleepGraphCard(uiState.value.sleepGraphData, Modifier.widthIn(max = 600.dp))
if (windowSizeClass == WindowWidthSizeClass.Compact) {
AverageTimeInBedCard()
AverageTimeAsleepCard()
} else {
FlowColumn {
AverageTimeInBedCard()
AverageTimeAsleepCard()
val boundsTransform = { _: Rect, _: Rect ->
spring(
dampingRatio = Spring.DampingRatioNoBouncy,
stiffness = Spring.StiffnessMedium,
visibilityThreshold = Rect.VisibilityThreshold
)
}
LookaheadScope {
val animateBoundsModifier = Modifier.animateBounds(
lookaheadScope = this@LookaheadScope,
boundsTransform = boundsTransform
)
val timeSleepSummaryCards = remember {
movableContentOf {
AverageTimeInBedCard(animateBoundsModifier)
AverageTimeAsleepCard(animateBoundsModifier)
}
}
if (windowSizeClass == WindowWidthSizeClass.Compact) {
WellnessCard(
wellnessData = uiState.value.wellnessData,
modifier = Modifier
.widthIn(max = 400.dp)
.heightIn(min = 200.dp)
)
HeartRateCard(
modifier = Modifier.widthIn(max = 400.dp, min = 200.dp),
uiState.value.heartRateData
FlowRow(
modifier = Modifier
.fillMaxSize()
.windowInsetsPadding(insets),
horizontalArrangement = Arrangement.Center,
verticalArrangement = Arrangement.Center,
maxItemsInEachRow = 3
) {
JetLaggedSleepGraphCard(
uiState.value.sleepGraphData,
Modifier.widthIn(max = 600.dp)
)
} else {
FlowColumn {
if (windowSizeClass == WindowWidthSizeClass.COMPACT) {
timeSleepSummaryCards()
} else {
FlowColumn {
timeSleepSummaryCards()
}
}
if (windowSizeClass == WindowWidthSizeClass.COMPACT) {
WellnessCard(
wellnessData = uiState.value.wellnessData,
modifier = Modifier
modifier = animateBoundsModifier
.widthIn(max = 400.dp)
.heightIn(min = 200.dp)
)
HeartRateCard(
modifier = Modifier.widthIn(max = 400.dp, min = 200.dp),
modifier = animateBoundsModifier.widthIn(max = 400.dp, min = 200.dp),
uiState.value.heartRateData
)
} else {
FlowColumn {
WellnessCard(
wellnessData = uiState.value.wellnessData,
modifier = animateBoundsModifier
.widthIn(max = 400.dp)
.heightIn(min = 200.dp)
)
HeartRateCard(
modifier = animateBoundsModifier.widthIn(max = 400.dp, min = 200.dp),
uiState.value.heartRateData
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
import com.example.jetlagged.ui.theme.JetLaggedTheme

class MainActivity : ComponentActivity() {

@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
setContent {
val windowSizeClass = calculateWindowSizeClass(this)
val windowSizeClass = currentWindowAdaptiveInfo().windowSizeClass
JetLaggedTheme {
HomeScreenDrawer(windowSizeClass)
}
Expand Down
6 changes: 3 additions & 3 deletions JetLagged/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ androidxHiltNavigationCompose = "1.2.0"
androix-test-uiautomator = "2.3.0"
coil = "2.6.0"
# @keep
compileSdk = "34"
compileSdk = "35"
coroutines = "1.9.0"
google-maps = "18.2.0"
gradle-versions = "0.51.0"
Expand All @@ -56,7 +56,7 @@ rome = "1.18.0"
room = "2.6.0"
secrets = "2.0.1"
# @keep
targetSdk = "33"
targetSdk = "35"
version-catalog-update = "0.8.4"

[libraries]
Expand All @@ -72,7 +72,7 @@ androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "a
androidx-benchmark-macrobenchmark = { module = "androidx.benchmark:benchmark-macro", version.ref = "androidx-benchmark" }
androidx-benchmark-macrobenchmark-junit4 = { module = "androidx.benchmark:benchmark-macro-junit4", version.ref = "androidx-benchmark-junit4" }
androidx-compose-animation = { module = "androidx.compose.animation:animation" }
androidx-compose-bom = { module = "androidx.compose:compose-bom", version.ref = "androidx-compose-bom" }
androidx-compose-bom = { module = "androidx.compose:compose-bom-alpha", version.ref = "androidx-compose-bom" }
androidx-compose-foundation = { module = "androidx.compose.foundation:foundation" }
androidx-compose-foundation-layout = { module = "androidx.compose.foundation:foundation-layout" }
androidx-compose-material-iconsExtended = { module = "androidx.compose.material:material-icons-extended" }
Expand Down