From bae0a48351b4417d80eee41e965d99c5b2de6fb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Mon, 5 Oct 2026 12:11:04 -0400 Subject: [PATCH] Snapshots: hide view until ReduceMotion applies; Spinner repaints when motion setting flips --- snapshot_test.go | 8 +++++++- spinner.go | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/snapshot_test.go b/snapshot_test.go index cffb84c..73425b0 100644 --- a/snapshot_test.go +++ b/snapshot_test.go @@ -20,11 +20,17 @@ var update = flag.Bool("update", false, "rewrite snapshots") func snapshot(t *testing.T, name string, w, h int, view func(c *ui.Context)) { t.Helper() for _, m := range []Mode{Light, Dark} { + ready := false tt := ui.NewTester(func(c *ui.Context) { Use(c, Settings{Mode: m}) - view(c) + if ready { + view(c) + } }, w, h) + // Animations must not paint before ReduceMotion applies. tt.SetPreferences(ui.Preferences{ReduceMotion: true, TextScale: 1}) + ready = true + tt.Frame() got := encode(t, tt.Image()) path := filepath.Join("testdata", "snapshots", runtime.GOOS, name+"-"+strings.ToLower(m.String())+".png") if *update { diff --git a/spinner.go b/spinner.go index b93ca02..75ee900 100644 --- a/spinner.go +++ b/spinner.go @@ -36,7 +36,7 @@ func Spinner(c *ui.Context, opts SpinnerOptions) *ui.Element { still := c.Preferences().ReduceMotion row := ui.Row(c).Gap(Density(c).Unit() * 2).AlignItems(ui.Center).Role(ui.RoleProgress).Label(label) row.Children(func() { - ui.Box(c).Size(size, size).Shrink(0).Draw(func(p *ui.Painter, r ui.Rect) { + ui.Box(c).Key(still).Size(size, size).Shrink(0).Draw(func(p *ui.Painter, r ui.Rect) { turn := 0.0 if !still { turn = float64(p.Now().UnixMilli()%1200) / 1200