Skip to content

Animate a text's number (count-up): no way to bind text content to an AnimatedValue #336

Open

Description

@houko

Context

A common motion in a dashboard is a figure that counts up to its new value: "18.7 GB can be freed" rolling from the old number to the new one when a check ends. NSGo has a rich animation graph (AnimatedValue, Timing, Spring, Interpolate, Motion), but nothing animated can reach a text's content:

  • AnimatedStyle (core/animated.go:158) binds opacity, transforms, colors, shadows and StickyInset, but not text.
  • AnimatedValue offers only a one-shot Read(cx, fn) (core/animated.go:71); there is no listener that reports the value as it moves.
  • The remaining route is a RequestAnimationFrame loop that sets a signal every frame and formats the number in Go. That works in the app, but nsgotest steps never wait for it: App.done (nsgotest/nsgotest.go:484) only advances while a.anim.Ending() || a.tree.Pacing(), and frames the app asks for itself are documented not to hold a step. So a test that checks the figure after a step reads whatever frame the loop reached, usually the start value.

Why it matters

Apps either skip the effect or ship code whose final state their headless tests cannot reach without hand-moving the clock in every test that reads the figure.

Proposal

Either of these would do; the first is closer to the existing graph:

  1. A text binding in AnimatedStyle, or a core.AnimatedText{Value: AnimatedNode, Format: NumberFormat} node, where NumberFormat is data the platform can apply each frame: decimals, prefix and suffix, and optionally a unit ladder (for example 1000-based steps with "B", "KB", "MB", "GB") so byte sizes can count up without Go running per frame.
  2. A tween driven by the animator's clock that calls back into Go, for example cx.Tween(from, to float64, TimingConfig, func(v float64)), which counts as an animation that ends for nsgotest (anim.Ending()), lands at to at once under reduced motion, and stops with its scope.

Acceptance

  • A figure can animate from one number to another without the app running its own frame loop.
  • After a step that starts it, nsgotest shows the final value (the step waits for it like any other animation that ends).
  • Reduced motion shows the final value at once.

Activity

  1. self-assigned this
    on Nov 20, 2026
  2. houko commented on Nov 20, 2026

    @houko
    CollaboratorAuthor

    Implemented in PR #1001. Scope.Tween drives a Go callback from the animation clock, keeps finite tweens in nsgotest's settling loop, stops with the animation owner, and resolves to the final value immediately under reduced motion. Focused tests cover final-step settling and reduced motion, and the animation guides document the text-binding use case.

    PR: #1001

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions