Skip to content

fix(chart): keep candle long-press timer across micro-moves - #6895

Merged
crossle merged 4 commits into
masterfrom
fix/candle-chart-long-press
Nov 26, 2026
Merged

crossle merged 4 commits into
masterfrom
fix/candle-chart-long-press

Conversation

@SeniorZhai

Copy link
Copy Markdown
Member

No description provided.

@gaotic

gaotic Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

AI review done for 3aac54e in 13m 44s · 3 comments

Quality: Needs fixes. The change adds the requested long-press behavior, but the new range animator has a cancellation state bug and the edge-scroll path still has two user-visible regressions. The relevant code and both PR deltas were inspected, with whitespace checks passing.

Role Model Status
Reviewer GPT codex/gpt-6.2-sol · effort high ok
Summary codex/gpt-6.2-sol · effort medium ok

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review · GPT + Grok · da721b4

No defects found. git diff --check passed, and all five chart tests passed in the Kotlin harness with Compose stubs on the PR head, while both new tests failed on the base as expected. The Android Gradle test run was blocked by wrapper cache permissions and an unavailable plugin on the offline retry.

Read viewport state only in the draw phase and snapshotFlow so drags and flings skip recomposition, and apply the touch-slop distance when a drag starts so candles stay under the finger.

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review · GPT + Grok · d596d21

No findings. git diff --check passed for both the prior-review delta and the full PR delta. The targeted Gradle test could not start because the sandbox cannot create the Gradle wrapper lock under /Users/binyang/.gradle, so verification was limited to source inspection and diff checks.

Trigger long press sooner, throttle selection haptics, and auto-scroll when the held selection rests near a plot edge.

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review · GPT + Grok · 2105adf

Needs fixes. Edge auto-scroll leaves the price-range animator in released mode, which can clip newly exposed candle extremes, and it bypasses selection haptics as the selected candle advances. git diff --check passes for both requested deltas, while the narrow Gradle test was blocked before execution by the sandbox filesystem restriction.

val frameNanos = withFrameNanos { it }
val frameSeconds = (frameNanos - lastFrameNanos) / 1_000_000_000f
lastFrameNanos = frameNanos
if (state.scrollAtEdge(selectX, edgePx, frameSeconds)) state.select(selectX)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When edge auto-scroll moves end, isScrolling remains false because this path calls stopFling() and never marks the state as scrolling. snapshotFlow therefore calls PriceRangeAnimator.animateTo with hold = false for every newly visible candle, restarting the 220 ms range animation from its current interpolation. If the incoming candle has a new high or low, its wick/body is temporarily mapped outside the stale range and clipped by the clipRect. Keep the price range in held/growing mode for the lifetime of edge auto-scroll, or otherwise update the range without restarting a released-mode animation.

val frameNanos = withFrameNanos { it }
val frameSeconds = (frameNanos - lastFrameNanos) / 1_000_000_000f
lastFrameNanos = frameNanos
if (state.scrollAtEdge(selectX, edgePx, frameSeconds)) state.select(selectX)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The frame loop changes selectedIndex as edge auto-scroll advances candles, but it discards the boolean returned by select and never invokes onSelectionMove. As a result, holding a finger at an edge silently moves the selection and produces no click haptic, while ordinary scrubbing does. Route changed selections through the same throttled haptic callback used in the pointer-event branch.

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review · GPT · 3aac54e

Needs fixes for the three issues described in the inline comments. git diff --check passed for both the PR base and the post-review delta. The focused CandleChartStateTest could not execute because the Gradle wrapper could not download Gradle 9.9.2 due to unavailable network access to services.gradle.org.

val current = value
val next = if (hold) PriceRange(min(current.min, target.min), max(current.max, target.max)) else target
if (next == to || (hold && next == current)) return@LaunchedEffect
if (next == to || (hold && next == current)) return

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collectLatest cancels the in-flight progress.animateTo when either the target range or isScrolling changes. Cancellation leaves progress at its current fraction, and this early return skips restoring it when the next request has the same to range. After a scroll-state transition or a short fling, the axis can therefore remain permanently at an intermediate range. On cancellation or an unchanged target, complete or snap the animator state so progress reaches 1f before returning.

val frameNanos = withFrameNanos { it }
val frameSeconds = (frameNanos - lastFrameNanos) / 1_000_000_000f
lastFrameNanos = frameNanos
if (state.scrollAtEdge(selectX, edgePx, frameSeconds)) state.select(selectX)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The selection path calls stopFling(), which sets isScrolling to false, and this edge-scroll loop advances end without setting it back. The range collector consequently animates each newly exposed candle with hold = false, so a new high or low can be outside the interpolated range and be clipped by the candle clipRect. Keep the price range in held or growing mode for the duration of edge auto-scroll, or update it without releasing the range animation during these moves.

val frameNanos = withFrameNanos { it }
val frameSeconds = (frameNanos - lastFrameNanos) / 1_000_000_000f
lastFrameNanos = frameNanos
if (state.scrollAtEdge(selectX, edgePx, frameSeconds)) state.select(selectX)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When edge auto-scroll advances end, this call can change selectedIndex but discards the result and never invokes the throttled onSelectionMove callback. Holding a finger at the edge therefore moves the selection without the click haptic used by ordinary scrubbing. Route changed selections through the same callback and interval handling as the pointer-event branch.

@crossle
crossle merged commit c2e57bd into master Nov 26, 2026
1 check passed
@crossle
crossle deleted the fix/candle-chart-long-press branch November 26, 2026 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants