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
6 changes: 5 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,11 @@ clutter came from ignoring one of them:
(incoming keeps the swept cells, outgoing keeps the rest), because the navigator puts the
outgoing screen on top for a back press; a reveal drawn only on the incoming screen would be
hidden there. NavHost's own fade (0.99 alpha) exists only to keep both screens composed for
`DURATION_MS`. Fairy mode uses a smooth gradient, like every other dither.
`DURATION_MS`. It sweeps diagonally, top-left to bottom-right, in 750 ms: 420 ms read as a flicker.
Fairy mode uses a smooth gradient, like every other dither.
- **Rings are drawn, not photographed** (`RingArtView`): a dithered band turning about a tilted
axis, the same for every model. A dark model tint falls back to the accent, since it would
vanish on the page.
- **In-screen motion uses `theme/Motion.kt`**: `sweepIn` for rings, gauges and bars (fill from empty
on first show, glide between values) and `pressScale` for tappable cards. Collapsible sections
expand with `AnimatedVisibility`. Prefer these over one-off specs, so the app moves one way.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fun DeviceHeroCard(
horizontalArrangement = Arrangement.spacedBy(16.dp),
) {
RingArtView(
tint = PulseColors.info,
tint = PulseColors.accent,
size = 72f,
imageRes = wearableModel?.imageRes ?: fallbackRingImage(deviceType),
)
Expand Down
114 changes: 57 additions & 57 deletions app/src/main/java/com/pulseloop/ui/components/RingArtView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,80 +2,80 @@ package com.pulseloop.ui.components

import androidx.annotation.DrawableRes
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.BlurredEdgeTreatment
import androidx.compose.ui.draw.blur
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.graphics.luminance
import androidx.compose.ui.unit.dp
import com.pulseloop.R
import com.pulseloop.ui.theme.ditherBrush
import kotlin.math.PI
import kotlin.math.cos
import kotlin.math.sin

/**
* Ported from RingArtView.swift (iOS #48).
* Renders a smart ring's product art on a light circular "platter" for the pairing carousel
* and the Settings hero: a soft tinted glow behind a light gradient disc so black / gold /
* rose-gold rings all read on the dark theme.
* A smart ring drawn in the app's own dither instead of a product photo: a band turning slowly
* about a tilted axis, its near side dense and its far side sparse, so the dots alone give it
* depth. Every ring looks the same here on purpose; the model's name says which one it is, and
* [tint] (the model's colour) is the only thing that varies.
*
* [imageRes] is accepted and ignored, so callers that still pass a model's photo keep compiling.
*/
@Composable
fun RingArtView(
tint: Color,
modifier: Modifier = Modifier,
size: Float = 180f,
@DrawableRes imageRes: Int? = null,
@Suppress("UNUSED_PARAMETER") @DrawableRes imageRes: Int? = null,
) {
// Tint follows the selected model with a short cross-fade (iOS animates .easeInOut 0.25).
val animatedTint by animateColorAsState(tint, tween(250), label = "ringArtTint")

Box(
modifier = modifier.size(size.dp),
contentAlignment = Alignment.Center,
) {
// Soft themed glow so the platter sits in the app's color world.
Box(
Modifier
.size(size.dp)
.blur((size * 0.13f).dp, BlurredEdgeTreatment.Unbounded)
.clip(CircleShape)
.background(animatedTint.copy(alpha = 0.22f)),
)

// Light platter: vertical white→light-gray gradient, subtle border, soft drop shadow.
Box(
Modifier
.size(size.dp)
.shadow((size * 0.05f).dp, CircleShape)
.clip(CircleShape)
.background(Brush.verticalGradient(listOf(Color.White, Color(0xFFE0E0E0))))
.border(1.dp, Color.Black.copy(alpha = 0.06f), CircleShape),
contentAlignment = Alignment.Center,
) {
Image(
painter = painterResource(imageRes ?: FALLBACK_IMAGE_RES),
contentDescription = null,
modifier = Modifier
.fillMaxSize()
.padding((size * 0.08f).dp),
contentScale = ContentScale.Fit,
)
// A black or gunmetal ring's colour would vanish on the dark page; those turn in the accent.
val visible = if (tint.luminance() < 0.25f) com.pulseloop.ui.theme.PulseColors.accent else tint
val color by animateColorAsState(visible, tween(250), label = "ringArtTint")
val spin by rememberInfiniteTransition(label = "ringSpin").animateFloat(
initialValue = 0f,
targetValue = (2 * PI).toFloat(),
animationSpec = infiniteRepeatable(tween(6000, easing = LinearEasing), RepeatMode.Restart),
label = "ringAngle",
)
Canvas(modifier.size(size.dp)) {
val radius = this.size.minDimension * 0.34f
val band = this.size.minDimension * 0.075f
val center = Offset(this.size.width / 2, this.size.height / 2)
// The ring's own circle, turned about the vertical axis by [spin] and tipped towards
// the viewer, then flattened onto the screen. Depth (z) sets the dot density.
val tilt = 0.45f
val points = (0 until SEGMENTS).map { i ->
val a = 2 * PI * i / SEGMENTS
val x0 = cos(a).toFloat()
val y0 = sin(a).toFloat()
val x1 = x0 * cos(spin)
val z1 = x0 * sin(spin)
val y2 = y0 * cos(tilt) - z1 * sin(tilt)
val z2 = y0 * sin(tilt) + z1 * cos(tilt)
Triple(Offset(center.x + x1 * radius, center.y + y2 * radius), z2, a)
}
// Far side first, so the near side is drawn over it.
points.sortedBy { it.second }.forEach { (pos, z, _) ->
val near = (z + 1f) / 2f
val brush = ditherBrush(color, 0.25f + 0.75f * near) ?: return@forEach
drawCircle(brush, radius = band * (0.75f + 0.35f * near), center = pos)
}
// A highlight that stays put while the ring turns under it: a dense glint on the near rim.
points.filter { it.second > 0.55f }.forEach { (pos, _, _) ->
val brush = ditherBrush(Color.White, 0.3f) ?: return@forEach
drawCircle(brush, radius = band * 0.35f, center = pos)
}
}
}

/** Generic Colmi-style ring shown when no model-specific image is available. */
private val FALLBACK_IMAGE_RES = R.drawable.ring_colmi_r09
/** Dots around the ring; enough to read as a solid band at the largest size. */
private const val SEGMENTS = 96
53 changes: 31 additions & 22 deletions app/src/main/java/com/pulseloop/ui/theme/DitherTransition.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.CompositingStrategy
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.graphicsLayer
import kotlin.math.abs

/**
* The app's screen transition: the new screen dissolves in through the same 4×4 Bayer dither the
* rest of the UI is drawn with, along a gradient that sweeps from the top down, and the sweep's
* rest of the UI is drawn with, along a gradient that sweeps diagonally from the top-left corner to
* the bottom-right, and the sweep's
* front edge glitters in the accent colour. Fairy mode swaps the dots for a smooth fade, as the
* rest of the dither does.
*
Expand All @@ -39,14 +40,14 @@ import kotlin.math.abs
* the outgoing one on top for a back press), the picture is the same.
*/
object DitherTransition {
/** Long enough to read as a wipe, short enough not to hold anyone up. */
const val DURATION_MS = 420
/** Long enough to watch the sweep cross the screen; 420 ms read as a flicker. */
const val DURATION_MS = 750

/** How much of the screen's height the dithered gradient at the front spans. */
/** How much of the sweep's path (corner to corner) the dithered gradient at the front spans. */
private const val GRADIENT = 0.35f

/** Horizontal bands the gradient is cut into; one per dither step reads as smooth. */
private const val BANDS = 32
/** Diagonal bands the corner-to-corner sweep is cut into. */
private const val BANDS = 48

/**
* NavHost's own transitions only hold both screens on screen for [DURATION_MS]: the alpha
Expand All @@ -55,7 +56,7 @@ object DitherTransition {
val enter: EnterTransition = fadeIn(tween(DURATION_MS, easing = LinearEasing), initialAlpha = 0.99f)
val exit: ExitTransition = fadeOut(tween(DURATION_MS, easing = LinearEasing), targetAlpha = 0.99f)

/** Share of the cells revealed at height [t] (0 top, 1 bottom) when the sweep is at [p]. */
/** Share of the cells revealed at [t] along the diagonal (0 top-left, 1 bottom-right) when the sweep is at [p]. */
internal fun coverage(t: Float, p: Float): Float {
val front = p * (1f + GRADIENT)
return ((front - t) / GRADIENT).coerceIn(0f, 1f)
Expand All @@ -73,35 +74,43 @@ object DitherTransition {
*/
internal fun DrawScope.drawWipe(p: Float, entering: Boolean, accent: Color) {
val keepMode = if (entering) BlendMode.DstIn else BlendMode.DstOut
val w = size.width
val h = size.height
if (FairyMode.on) {
val stops = (0..BANDS).map { i -> val t = i / BANDS.toFloat(); t to Color.Black.copy(alpha = coverage(t, p)) }
drawRect(Brush.verticalGradient(*stops.toTypedArray()), blendMode = keepMode)
drawRect(Brush.linearGradient(*stops.toTypedArray(), start = Offset.Zero, end = Offset(w, h)), blendMode = keepMode)
val glow = (0..BANDS).map { i -> val t = i / BANDS.toFloat(); t to accent.copy(alpha = sparkle(t, p) * 0.6f) }
drawRect(Brush.verticalGradient(*glow.toTypedArray()))
drawRect(Brush.linearGradient(*glow.toTypedArray(), start = Offset.Zero, end = Offset(w, h)))
return
}
val bandH = size.height / BANDS
// A point's place along the sweep is (x / w + y / h) / 2, so each band is the strip
// between two lines parallel to the top-right-to-bottom-left diagonal. Its corners can
// lie past the screen; drawing clips them. The dither cells stay on the screen grid.
fun band(a: Float, b: Float) = Path().apply {
moveTo(2f * a * w, 0f)
lineTo(2f * b * w, 0f)
lineTo(0f, 2f * b * h)
lineTo(0f, 2f * a * h)
close()
}
for (i in 0 until BANDS) {
val t = (i + 0.5f) / BANDS
val a = i / BANDS.toFloat()
val b = (i + 1) / BANDS.toFloat()
val t = (a + b) / 2f
val lit = Dither.steps(coverage(t, p))
val top = i * bandH
val brush: Brush? = when {
// Entering keeps everything here; leaving keeps nothing.
lit >= Dither.STEPS -> if (entering) null else SolidColor(Color.Black)
// Entering keeps nothing here; leaving keeps everything.
lit == 0 -> if (entering) SolidColor(Color.Transparent) else null
else -> with(Dither) { brush(Color.Black, lit, cellPx()) }
}
if (brush != null) {
drawRect(brush, topLeft = Offset(0f, top), size = Size(size.width, bandH + 1f), blendMode = keepMode)
}
val glitter = Dither.steps(sparkle(t, p))
if (glitter > 0) {
drawRect(
with(Dither) { brush(accent, glitter, cellPx()) },
topLeft = Offset(0f, top), size = Size(size.width, bandH + 1f),
)
}
if (brush == null && glitter == 0) continue
// About a pixel of overlap, so anti-aliased strip edges leave no visible seam.
val path = band(a, b + 1f / (w + h))
if (brush != null) drawPath(path, brush, blendMode = keepMode)
if (glitter > 0) drawPath(path, with(Dither) { brush(accent, glitter, cellPx()) })
}
}
}
Expand Down
Loading