Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import me.lvca.alba.app.testing.SHORT_WAIT
import me.lvca.alba.app.testing.ScreenshotCapture
import me.lvca.alba.app.testing.Screenshots
import me.lvca.alba.app.testing.Smoke
import me.lvca.alba.app.testing.motionMillis
import me.lvca.alba.app.testing.openGalleryMedia
import me.lvca.alba.app.testing.pressBack
import me.lvca.alba.app.testing.scrollToGalleryMedia
import me.lvca.alba.app.testing.waitForVideoPlaying
import me.lvca.alba.app.ui.viewer.ViewerSpec
import org.junit.Assert.*
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -110,7 +110,7 @@ class ViewerTest {
compose.mainClock.autoAdvance = false
try {
compose.onNodeWithTag("video-player").performClick()
compose.mainClock.advanceTimeBy(ViewerSpec.CHROME_FADE_MILLIS + 100L)
compose.mainClock.advanceTimeBy(motionMillis { fastEffectsSpec() } + 100L)
// Like Google Photos, the tap brings back the top bar and actions with the playback controls, without pausing.
compose.onNodeWithTag("viewer-share").assertExists()
compose.onNodeWithTag("floating-viewer-back").assertIsDisplayed()
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/me/lvca/alba/app/ui/AlbaApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.SharedTransitionLayout
import androidx.compose.animation.core.tween
import androidx.compose.animation.core.updateTransition
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
Expand All @@ -21,6 +20,7 @@ import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.SnackbarResult
Expand Down Expand Up @@ -67,7 +67,6 @@ import me.lvca.alba.app.ui.transfers.ProvideMediaLookup
import me.lvca.alba.app.ui.viewer.LocalPhotoTransition
import me.lvca.alba.app.ui.viewer.LocalViewerBurst
import me.lvca.alba.app.ui.viewer.MediaDetailScreen
import me.lvca.alba.app.ui.viewer.PHOTO_TRANSITION_MILLIS
import me.lvca.alba.app.ui.viewer.PhotoTransitionScope
import me.lvca.alba.app.ui.viewer.ViewerBurst
import me.lvca.alba.app.ui.viewer.reduceGalleryMotion
Expand Down Expand Up @@ -204,6 +203,7 @@ fun AlbaApp(
key = { it }, reduceMotion = reduceMotion, onBack = actions::closeAccount)
var galleryBottomSpace by remember { mutableStateOf(100.dp) }
val slide = with(LocalDensity.current) { NavigationMotion.SHARED_AXIS_DP.dp.roundToPx() }
val motion = MaterialTheme.motionScheme

Scaffold(
contentWindowInsets = WindowInsets(0, 0, 0, 0),
Expand All @@ -216,7 +216,7 @@ fun AlbaApp(
) { padding ->
accountTransition.AnimatedContent(
transitionSpec = {
navigationTransform(if (targetState) NavigationDirection.FORWARD else NavigationDirection.BACK, slide,
navigationTransform(if (targetState) NavigationDirection.FORWARD else NavigationDirection.BACK, slide, motion,
gesture = accountBack.phase != BackPhase.IDLE, reduceMotion = reduceMotion)
},
modifier = Modifier
Expand Down Expand Up @@ -251,10 +251,10 @@ fun AlbaApp(
// Keep the gallery opaque underneath the viewer. Fading both screens exposes
// the scaffold between them and produces a pale flash.
if (targetState is Destination.Media) {
fadeIn(tween(PHOTO_TRANSITION_MILLIS)).togetherWith(ExitTransition.None)
fadeIn(motion.fastEffectsSpec()).togetherWith(ExitTransition.None)
.apply { targetContentZIndex = 1f }
} else {
EnterTransition.None.togetherWith(fadeOut(tween(PHOTO_TRANSITION_MILLIS)))
EnterTransition.None.togetherWith(fadeOut(motion.fastEffectsSpec()))
.apply { targetContentZIndex = 0f }
}
},
Expand Down
24 changes: 10 additions & 14 deletions app/src/main/java/me/lvca/alba/app/ui/AlbaSnackbar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import android.content.Context
import android.view.accessibility.AccessibilityManager
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.SizeTransform
import androidx.compose.animation.core.LinearOutSlowInEasing
import androidx.compose.animation.core.snap
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Snackbar
import androidx.compose.material3.SnackbarData
import androidx.compose.material3.SnackbarDefaults
Expand All @@ -38,14 +37,11 @@ import androidx.compose.ui.unit.dp
import kotlinx.coroutines.delay
import me.lvca.alba.app.ui.viewer.reduceGalleryMotion

/** Google Photos' actionable toast, read from GP 7.95 (`bt_animation_duration_toast_translation_ms`, `D/low`). */
/**
* Google Photos' actionable toast, read from GP 7.95 (`D/low`). It slides in on the theme's default spatial spring and
* a leaving message fades out on the fast effects spring.
*/
internal object SnackbarSpec {
/** The toast slides in over 300 ms. */
const val SLIDE_IN_MILLIS = 300

/** Alba fades a leaving message out quickly, like GP's generic short fade (`photos_animations_fade_out_short`). */
const val FADE_OUT_MILLIS = 75

/** Material's own durations for Alba's plain status messages. */
const val SHORT_MILLIS = 4_000L
const val LONG_MILLIS = 10_000L
Expand Down Expand Up @@ -88,7 +84,7 @@ private fun Context.screenReaderOn(): Boolean =
(getSystemService(Context.ACCESSIBILITY_SERVICE) as? AccessibilityManager)?.isTouchExplorationEnabled == true

/**
* Alba's snackbar host. Messages slide up into place over 300 ms like Google Photos' toast and leave with a short
* Alba's snackbar host. Messages slide up into place like Google Photos' toast and leave with a short
* fade; the host times them out itself so an undo message gets GP's 5 s (10 s or more with a screen reader).
*/
@Composable
Expand All @@ -105,14 +101,14 @@ internal fun AlbaSnackbarHost(state: SnackbarHostState, modifier: Modifier = Mod
data.dismiss()
}
val reduceMotion = reduceGalleryMotion()
val motion = MaterialTheme.motionScheme
AnimatedContent(
targetState = current,
modifier = modifier,
transitionSpec = {
val enter = if (reduceMotion) fadeIn(tween(SnackbarSpec.FADE_OUT_MILLIS))
else slideInVertically(tween(SnackbarSpec.SLIDE_IN_MILLIS, easing = LinearOutSlowInEasing)) { it } +
fadeIn(tween(SnackbarSpec.SLIDE_IN_MILLIS))
(enter togetherWith fadeOut(tween(SnackbarSpec.FADE_OUT_MILLIS))).using(SizeTransform(clip = true) { _, _ -> snap() })
val enter = if (reduceMotion) fadeIn(motion.fastEffectsSpec())
else slideInVertically(motion.defaultSpatialSpec()) { it } + fadeIn(motion.defaultEffectsSpec())
(enter togetherWith fadeOut(motion.fastEffectsSpec())).using(SizeTransform(clip = true) { _, _ -> snap() })
},
contentAlignment = Alignment.BottomCenter,
label = "snackbar",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,15 @@ fun ICloudAccountScreen(
PredictiveBackNavigation(pageState, pageBack, previous = page.parent.takeIf { page != ProfilePage.OVERVIEW },
key = { it }, reduceMotion = reduceMotion) { back() }
val slide = with(LocalDensity.current) { NavigationMotion.SHARED_AXIS_DP.dp.roundToPx() }
val motion = MaterialTheme.motionScheme
pageTransition.AnimatedContent(
transitionSpec = {
val direction = when {
targetState == ProfilePage.OVERVIEW || targetState == initialState.parent -> NavigationDirection.BACK
initialState == ProfilePage.OVERVIEW || initialState == targetState.parent -> NavigationDirection.FORWARD
else -> NavigationDirection.LATERAL
}
navigationTransform(direction, slide, gesture = pageBack.phase != BackPhase.IDLE, reduceMotion = reduceMotion)
navigationTransform(direction, slide, motion, gesture = pageBack.phase != BackPhase.IDLE, reduceMotion = reduceMotion)
},
modifier = Modifier.fillMaxSize(),
) { shown ->
Expand Down
15 changes: 7 additions & 8 deletions app/src/main/java/me/lvca/alba/app/ui/account/SignInPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package me.lvca.alba.app.ui.account
import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.ContentTransform
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInHorizontally
Expand Down Expand Up @@ -49,6 +47,7 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.MotionScheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.material3.Text
Expand Down Expand Up @@ -152,25 +151,25 @@ internal fun SignInFlow(state: SignInFlowState, actions: SignInFlowActions) {
val glowHeight = with(LocalDensity.current) { (WindowInsets.statusBars.getTop(this) + GlowHeight.roundToPx()).toFloat() }
val reduceMotion = reduceGalleryMotion()
val slide = with(LocalDensity.current) { NavigationMotion.SHARED_AXIS_DP.dp.roundToPx() }
val motion = MaterialTheme.motionScheme
Box(Modifier.fillMaxSize().background(surface).drawBehind { drawDawnGlow(dawn, surface, glowHeight) }
.testTag("sign-in-page")) {
AnimatedContent(
targetState = state.challenge,
contentKey = { it != null },
transitionSpec = { stepTransform(forward = targetState != null, slide, reduceMotion) },
transitionSpec = { stepTransform(forward = targetState != null, slide, motion, reduceMotion) },
label = "sign-in-step",
) { challenge ->
if (challenge == null) CredentialsStep(state, actions) else CodeStep(challenge, state, actions)
}
}
}

/** Shared axis between the steps on critically damped springs, so nothing overshoots; a cross-fade with reduced motion. */
private fun stepTransform(forward: Boolean, slidePx: Int, reduceMotion: Boolean): ContentTransform {
val fade = spring<Float>(dampingRatio = Spring.DampingRatioNoBouncy, stiffness = Spring.StiffnessMedium)
/** Shared axis between the steps on the theme's default springs; a cross-fade with reduced motion. */
private fun stepTransform(forward: Boolean, slidePx: Int, motion: MotionScheme, reduceMotion: Boolean): ContentTransform {
val fade = motion.defaultEffectsSpec<Float>()
if (reduceMotion) return fadeIn(fade) togetherWith fadeOut(fade)
val move = spring(dampingRatio = Spring.DampingRatioNoBouncy, stiffness = Spring.StiffnessMediumLow,
visibilityThreshold = IntOffset(1, 1))
val move = motion.defaultSpatialSpec<IntOffset>()
val sign = if (forward) 1 else -1
return (slideInHorizontally(move) { sign * slidePx } + fadeIn(fade))
.togetherWith(slideOutHorizontally(move) { -sign * slidePx } + fadeOut(fade))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.graphics.BitmapFactory
import android.util.LruCache
import androidx.compose.animation.Crossfade
import androidx.compose.animation.core.snap
import androidx.compose.animation.core.tween
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
Expand Down Expand Up @@ -160,7 +159,7 @@ internal fun AccountAvatar(
if (photo == null || key == null) { value = null; return@produceState }
value = decodedAvatars.get(key) ?: withContext(Dispatchers.Default) { decodeAvatar(photo) }?.also { decodedAvatars.put(key, it) }
}
val fade = if (reduceGalleryMotion()) snap<Float>() else tween(AVATAR_FADE_MILLIS)
val fade = if (reduceGalleryMotion()) snap<Float>() else MaterialTheme.motionScheme.defaultEffectsSpec()
Crossfade(bitmap, modifier.size(avatarSize), animationSpec = fade, label = "account-avatar") { image ->
if (image != null) AlbaAvatar(avatarSize, Color.Transparent, Color.White, shadowElevation = shadowElevation, border = border) {
Image(image, null, Modifier.size(avatarSize).testTag("account-photo"), contentScale = ContentScale.Crop)
Expand All @@ -187,7 +186,6 @@ private fun decodeAvatar(photo: ByteArray): ImageBitmap? {

private const val SILHOUETTE_SCALE = .62f
private const val DECODED_AVATARS = 4
private const val AVATAR_FADE_MILLIS = 220
private const val MAX_SOURCE_SIDE = 16384
private const val MAX_DECODED_SIDE = 256

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import androidx.compose.ui.window.PopupProperties
import me.lvca.alba.app.ui.designsystem.theme.AlbaIconSize
import me.lvca.alba.app.ui.designsystem.theme.AlbaTheme
import me.lvca.alba.app.ui.designsystem.theme.floating
import me.lvca.alba.app.ui.navigation.NavigationMotion
import me.lvca.alba.app.ui.viewer.reduceGalleryMotion

/**
Expand All @@ -83,12 +82,14 @@ internal object AlbaFloatingDefaults {
/** The anchor's gap to the window edge the menu keeps. */
val MenuWindowMargin = 8.dp

/** Floating bars rise in on Material's fast spatial spring and fade on the effects spring; reduced motion snaps. */
/** Floating bars rise in on the theme's fast spatial spring and fade on its fast effects spring; reduced motion snaps. */
@Composable
fun enter(reducedMotion: Boolean): EnterTransition = if (reducedMotion) EnterTransition.None else
slideInVertically(NavigationMotion.fastSpatial()) { it } + fadeIn(NavigationMotion.fastEffects())
MaterialTheme.motionScheme.let { slideInVertically(it.fastSpatialSpec()) { height -> height } + fadeIn(it.fastEffectsSpec()) }

@Composable
fun exit(reducedMotion: Boolean): ExitTransition = if (reducedMotion) ExitTransition.None else
slideOutVertically(NavigationMotion.fastSpatial()) { it } + fadeOut(NavigationMotion.fastEffects())
MaterialTheme.motionScheme.let { slideOutVertically(it.fastSpatialSpec()) { height -> height } + fadeOut(it.fastEffectsSpec()) }
}

/**
Expand Down Expand Up @@ -131,10 +132,11 @@ internal fun AlbaMenu(
Popup(popupPositionProvider = position, onDismissRequest = onDismissRequest, properties = PopupProperties(focusable = true)) {
val reduce = reduceGalleryMotion()
val transition = rememberTransition(visibility, label = "alba-menu")
val scale by transition.animateFloat({ if (reduce) snap() else NavigationMotion.fastSpatial() }, label = "menu-scale") {
val motion = MaterialTheme.motionScheme
val scale by transition.animateFloat({ if (reduce) snap() else motion.fastSpatialSpec() }, label = "menu-scale") {
if (it) 1f else MENU_CLOSED_SCALE
}
val alpha by transition.animateFloat({ if (reduce) snap() else NavigationMotion.fastEffects() }, label = "menu-alpha") {
val alpha by transition.animateFloat({ if (reduce) snap() else motion.fastEffectsSpec() }, label = "menu-alpha") {
if (it) 1f else 0f
}
Surface(Modifier.padding(AlbaFloatingDefaults.MenuShadow).graphicsLayer {
Expand Down
19 changes: 9 additions & 10 deletions app/src/main/java/me/lvca/alba/app/ui/designsystem/AlbaStatus.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package me.lvca.alba.app.ui.designsystem

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.VisibilityThreshold
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.snap
import androidx.compose.animation.core.spring
import androidx.compose.animation.expandVertically
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
Expand Down Expand Up @@ -125,7 +122,7 @@ internal fun AlbaStatusDot(tone: AlbaTone, modifier: Modifier = Modifier, size:

/**
* A determinate ring in the tone's colour with [content] in its middle, such as "412 / 980". The ring eases to a new
* value on a critically damped spring, and jumps there under reduced motion.
* value on the theme's slow spatial spring, and jumps there under reduced motion.
*/
@Composable
internal fun AlbaProgressRing(
Expand All @@ -138,7 +135,7 @@ internal fun AlbaProgressRing(
) {
val reduce = reduceGalleryMotion()
val shown by animateFloatAsState(progress.coerceIn(0f, 1f),
if (reduce) snap() else spring(Spring.DampingRatioNoBouncy, Spring.StiffnessLow), label = "progress-ring")
if (reduce) snap() else MaterialTheme.motionScheme.slowSpatialSpec(), label = "progress-ring")
Box(modifier.size(size), contentAlignment = Alignment.Center) {
CircularProgressIndicator(
progress = { shown },
Expand Down Expand Up @@ -262,16 +259,18 @@ internal fun AlbaInfoToggle(expanded: Boolean, onToggle: (Boolean) -> Unit, labe
}

/**
* Detail that unfolds under its row or info icon on a critically damped spring, and only fades under reduced motion,
* as the invite form in Manage shared album does.
* Detail that unfolds under its row or info icon on the theme's default spatial spring, and only fades under reduced
* motion, as the invite form in Manage shared album does.
*/
@Composable
internal fun AlbaReveal(visible: Boolean, modifier: Modifier = Modifier, content: @Composable ColumnScope.() -> Unit) {
val reduce = reduceGalleryMotion()
val unfold = spring(Spring.DampingRatioNoBouncy, Spring.StiffnessMediumLow, IntSize.VisibilityThreshold)
val motion = MaterialTheme.motionScheme
val unfold = motion.defaultSpatialSpec<IntSize>()
val fade = motion.defaultEffectsSpec<Float>()
AnimatedVisibility(visible, modifier,
enter = if (reduce) fadeIn() else fadeIn() + expandVertically(unfold, expandFrom = Alignment.Top),
exit = if (reduce) fadeOut() else fadeOut() + shrinkVertically(unfold, shrinkTowards = Alignment.Top)) {
enter = if (reduce) fadeIn(fade) else fadeIn(fade) + expandVertically(unfold, expandFrom = Alignment.Top),
exit = if (reduce) fadeOut(fade) else fadeOut(fade) + shrinkVertically(unfold, shrinkTowards = Alignment.Top)) {
Column(content = content)
}
}
Loading