Skip to content

feat(motion): adopt spring tokens and add shared CSS-transition helper - #5112

Merged
Doberjohn merged 19 commits into
callstack:mainfrom
rjmreis:css-transitions
Nov 27, 2026
Merged

Doberjohn merged 19 commits into
callstack:mainfrom
rjmreis:css-transitions

Conversation

@rjmreis

@rjmreis rjmreis commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

MD3 Expressive replaces easing+duration with springs where motion is spring-shaped; CSS transitions are the default otherwise. #5015 handled the library swap + CSS-transition conversion; this PR adds spring adoption + a shared getTransition helper.

  • getTransition() CSS-transition helper in theme/tokens/sys/motion.ts
  • Badge: uses helper; easing now standard (duration and reduce motion unchanged)
  • Checkbox: deduped onto helper, no behavior change
  • TextInput: label float/active-border now CSS transitions; follows <PaperProvider reduceMotion> instead of the OS setting; clear() no longer runs the blur animation directly, the label follows the value; label position changes from layout (accessory, RTL) now animate too
  • SegmentedButtonItem: checkmark spring now fast.spatial token, matching Switch/FAB; more overshoot in the expressive theme, almost none in the standard one
  • code.instructions.md: rule to gate every animation on useReduceMotion()

Follow-up (separate issue): some #5015 files still use imperative withTiming for non-spring motion, out of scope here.

Related issue

Part of the MD3 motion modernization; no tracking issue yet.

Test plan

yarn typecheck/lint/jest pass, incl. new getTransition + TextInput focus/blur and reduce-motion tests. Manual verification + screenshots below.

Screenshots

Badge
Simulator.Screen.Recording.-.iPhone.17.Pro.-.2026-09-08.at.13.08.16.mov
Checkbox / Checkbox Item
Simulator.Screen.Recording.-.iPhone.17.Pro.-.2026-09-08.at.13.10.19.mov
TextInput
Simulator.Screen.Recording.-.iPhone.17.Pro.-.2026-09-08.at.12.56.43.mov
Segmented Buttons
Simulator.Screen.Recording.-.iPhone.17.Pro.-.2026-09-08.at.12.58.39.mov

Copilot AI balanced review requested due to automatic review settings September 8, 2026 11:02

Copilot AI 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.

🔵 Needs a closer look

It changes core animation mechanics (tokenized CSS transitions + spring adoption) across widely used components like TextInput, which is cross-platform sensitive and should get final human verification.

Pull request overview

This PR continues the MD3 Expressive motion modernization by (1) introducing a shared helper for Reanimated CSS-transition styles derived from theme motion tokens, and (2) migrating/deduping several components to use those tokens and the CSS-transition tier consistently (including adopting a spring token for SegmentedButtonItem).

Changes:

  • Added getTransition(...) in src/theme/tokens/sys/motion.ts and unit tests validating token lookup + reduce-motion behavior.
  • Refactored TextInput label/indicator animations from imperative Reanimated timing/shared-values to render-driven CSS transitions, and added regression tests asserting the computed label styles across focus/blur.
  • Updated Badge and Checkbox to use the shared transition helper; updated SegmentedButtonItem to use a theme spring token via toRawSpring(...).
File summaries
File Description
src/theme/tokens/sys/motion.ts Adds getTransition helper to standardize CSS transition duration/easing/property from motion tokens.
src/theme/tests/motion.test.ts Adds unit coverage for getTransition token lookup, reduce-motion, and easing construction.
src/components/TextInput/TextInput.tsx Removes now-unused animation handler types; consumes updated hook-driven animation state.
src/components/TextInput/hooks.ts Replaces imperative label/indicator animation with boolean-state-driven CSS transition styles; wires reduce-motion via context.
src/components/TextInput/constants.ts Removes timing/easing constants tied to imperative withTiming animation.
src/components/SegmentedButtons/SegmentedButtonItem.tsx Replaces hardcoded spring config with theme spring token via toRawSpring.
src/components/Checkbox/Checkbox.tsx Dedupes CSS transition props through getTransition.
src/components/Badge.tsx Switches Badge opacity transition to tokenized getTransition + useReduceMotion.
src/components/tests/TextInput.test.tsx Adds assertions for label wrapper/text styles across focus/blur in filled + outlined variants.
Review details
  • Files reviewed: 9/9 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/components/TextInput/hooks.ts Resolved
Copilot AI review requested due to automatic review settings September 8, 2026 11:13

Copilot AI 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.

🔵 Needs a closer look

It changes animation mechanisms and motion-token wiring in core components (notably TextInput), where subtle platform/runtime differences are hard to fully validate from diff review alone.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

src/components/tests/TextInput.test.tsx:83

  • getLabelWrapper currently returns the first node with aria-hidden === true, but TextInput can render multiple aria-hidden elements (e.g. the error icon wrapper). That makes this helper non-specific and can cause future tests to assert styles on the wrong element if another aria-hidden node appears earlier in the tree.

Consider narrowing the predicate to only match the label wrapper by additionally requiring a transition style marker (e.g. transitionProperty in the style object/array), which should be unique to the animated label wrapper in these tests.

  • Files reviewed: 9/9 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Comment thread src/components/Badge.tsx Resolved
Copilot AI review requested due to automatic review settings September 15, 2026 14:02

Copilot AI 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.

🔵 Needs a closer look

The helper’s default generic currently permits invalid transition-property names.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

src/theme/tokens/sys/motion.ts:142

  • The Record<string, unknown> default erases transitionProperty validation because its keys accept any string, so typos such as 'opactiy' compile and produce a no-op/invalid transition at runtime. Use Reanimated's own default CSSTransitionProperties style type here so callers are constrained to supported style keys.
  • Files reviewed: 9/9 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@rjmreis
rjmreis requested a review from JKobrynski September 23, 2026 07:06

@JKobrynski JKobrynski left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just one thing from me

Copilot AI balanced review requested due to automatic review settings October 5, 2026 15:02

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

SegmentedButtonItem uses the fast spring token instead of the documented slow token, substantially changing its motion.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Found potential problems with the pull request:

  • The description is too long. Please keep it under 1000 characters.

@satya164 satya164 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review by Claude

See the inline comments. (via Claude, verify if it makes sense)

Comment thread src/theme/tokens/sys/motion.ts Resolved
Comment thread src/theme/tokens/sys/motion.ts Resolved
Copilot AI balanced review requested due to automatic review settings October 28, 2026 08:19

Copilot AI 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.

🟡 Changes recommended

The opacity-only reduced-motion exemption is ineffective because PaperProvider still forces animation.scale to zero, causing transitions to snap; the provider override must be separated from the user-controlled multiplier and covered by a provider-backed regression test.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread src/theme/tokens/sys/motion.ts Resolved
@rjmreis
rjmreis requested a review from satya164 October 28, 2026 08:26
@Doberjohn Doberjohn added this to the 6.0.0 milestone Oct 30, 2026
Copilot AI balanced review requested due to automatic review settings November 4, 2026 12:27

Copilot AI 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.

🟡 Changes recommended

The provider’s reduced-motion override still zeros the shared animation scale, causing explicitly exempt opacity transitions to become instant instead of retaining their duration.

2 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 23, 2026 14:54
@lukewalczak

Copy link
Copy Markdown
Member

/review

Copilot AI 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.

🔵 Needs a closer look

The TextInput transitions and affix animations need visual confirmation on iOS, Android, and web, including interrupted focus/blur, since Jest checks only target styles and no before/after comparisons were available.

2 open issues

Review effort: Balanced

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging 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.

Apex Sentinel: 1 new finding on c5b4cf9. The verdict and the full list are in the summary comment.

Comment thread src/components/TextInput/hooks.ts Resolved
Copilot AI balanced review requested due to automatic review settings November 23, 2026 15:10

Copilot AI 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.

🔵 Needs a closer look

JavaScript-timed TextInput transitions still require human native/web visual checks for interrupted focus/blur and placeholder/affix timing, since platform execution and linked-media inspection were unavailable.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 27, 2026 13:43

Copilot AI 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.

🟡 Changes recommended

Two active issues remain: synchronous clearing can leave an empty input’s label floated after blur, and adding a start accessory can cause an outlined label to jump horizontally before animating back.

2 open issues

Review effort: Balanced

Comment thread src/components/TextInput/hooks.ts Resolved
Comment thread src/components/TextInput/hooks.ts Resolved
@alpharius-ck

Copy link
Copy Markdown
Collaborator

Review: css-transitions

Verdict: LGTM. I found no blocking issues on iOS, web or Android. The suggestions below are non-blocking.

Platform Result How it was checked
Static (tsc, eslint, jest) ✅ tsc clean outside docs/, eslint clean on touched files, jest 1581 passed
iOS ✅ iPhone 17 Pro simulator, dev client
Web ✅ Expo web, computed styles sampled during transitions
Android ✅ Pixel 4 API 34 emulator, dev client

Suggestions (non-blocking)

  1. isLabelFloated timer. It flips on a setTimeout of short3 ms, because CSS transitions report no end. On a busy JS thread the placeholder can show late, and with reduce motion it flips one tick after the label jumps. A short comment next to the timer would help.
  2. Changelog / migration note. These changes are user-visible, but the diff only touches code comments and code.instructions.md:
    • TextInput now follows <PaperProvider reduceMotion> instead of the OS setting.
    • clear() no longer drives the blur animation.
    • Label position changes from layout (accessory, RTL) now animate.
    • Badge easing is now standard.
    • The SegmentedButtons check overshoots differently per theme.
  3. Affix fade-in test. The logic is subtle: state is set during render, and a CSS animation is used because a transition doesn't run on mount. Affixes present on the first render intentionally don't fade. A test for first mount vs. re-float would protect it, if there isn't one already.
  4. "Dense" in the PR description. I couldn't find a dense path in the TextInput label layout (getTextInputAnimationLayout only takes variant, hasAccessory and isRTL). Either the description is out of date or I'm missing a case.
Static checks
  • tsc is clean outside docs/.
  • eslint is clean on the touched files.
  • jest: 1581 passed. 4 snapshot tests failed only because I ran from a different directory (ListImage and Appbar embed asset paths), so I don't think they're related to this PR.
iOS (iPhone 17 Pro simulator)
  • TextInput:
    • Focus floats the label and fills the underline, and the placeholder shows.
    • Typing with a prefix keeps the label floated.
    • clear() while focused keeps the label floated.
    • Blur on an empty field drops the label and removes the prefix.
    • RTL with a start accessory positions both the floated and resting label correctly.
  • Badge: fades out and back in.
  • Checkbox: toggles work, and the parent follows its children.
  • SegmentedButtons: the check moves to the newly selected segment.
  • reduceMotion="on": TextInput ends in the correct states with no errors.
Web (Expo web)

I checked computed styles and sampled them during the transitions.

  • TextInput:
    • The label wrapper animates top 20→8px, and the label font-size goes 16→12px.
    • Both use 0.15s cubic-bezier(0.2, 0, 0, 1), i.e. short3 with the standard easing.
    • The filled-variant underline animates its transform (scaleX).
    • Clearing a blurred, non-empty field sends the label back to rest.
  • Badge: opacity goes 1→0 over about 150 ms with the standard curve (the intended easing change).
  • Checkbox:
    • Fill, outline and state layer fade over 0.1s.
    • The check mask animates width, opacity over 0.15s.
    • The curves are unchanged by the dedup.
  • SegmentedButtons: the check scale goes 0 → 1.067 → 0.995 → 1.0, the expected fast.spatial overshoot in the expressive theme.
  • reduceMotion="on": Badge, TextInput label and wrapper show transition-duration: 0s, and states jump to their end values.
  • The console is clean.
Android (Pixel 4 API 34 emulator)
  • TextInput: focus, type, blur with text, and clearing a blurred field all behave correctly. The prefix and clear action work.
  • RTL: the label floats next to the leading icon and rests beside it.
  • Badge, Checkbox (including parent/children) and SegmentedButtons: all behave correctly.
  • OS "remove animations" set to 0: TextInput still ends in the correct states, with no crashes and no PR-related errors.

Not covered

  • Web in LTR (the example opened in RTL), and browsers other than the one I used.
  • Frame-by-frame motion on iOS and Android. My screenshots only showed end states, so please check the spring overshoot and transition feel on a device.
  • reduceMotion="auto" actually picking up the OS setting on Android.

Unrelated noise I saw (not from this PR)

  • Reanimated "Dependencies should only be used on the web" warnings in Metro. I found no Reanimated hooks with dependency arrays in src.
  • On iOS, "999+" in the Badge example clips to "99…" because of the badge's existing maxWidth.
  • An ExpoKeepAwake.deactivate error toast on Android relaunch, which comes from the dev client.

- Always update `hasValue` in `onChangeText`, so a nested clear from the
  parent's handler drops the label on blur.
- Transition the outlined label inset with its translateX, so adding a
  start accessory to a floated label no longer makes it jump. On web the
  inset uses `left`/`right`, which a CSS transition can target.
- Document the `isLabelFloated` timer caveats.
- Test the affix fade-in on re-float vs. first render.
- Drop the stale note that TextInput ignores the `reduceMotion` prop.
Copilot AI balanced review requested due to automatic review settings November 27, 2026 14:33
@lukewalczak

Copy link
Copy Markdown
Member

Thanks for the thorough review! Addressed in 3c243d6:

  1. isLabelFloated timer: the comment now covers the busy JS thread and the one-tick delay with reduce motion.
  2. Changelog / migration: the theming guide said the TextInput label ignores the reduceMotion prop, which is no longer true, so I removed that sentence. I didn't add the smaller visual changes (Badge easing, SegmentedButtons overshoot, clear()) to the migration guide. Happy to if we want them there.
  3. Affix fade-in: added a test that the prefix doesn't fade in on first render but does when the label floats again.
  4. "Dense": the description was out of date, now fixed.

Copilot AI 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.

🔵 Needs a closer look

Human assessment is needed because the published review omits moderate findings affecting web reduced-motion behavior and outlined-label positioning during direction changes.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@lukewalczak

Copy link
Copy Markdown
Member

/review

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 3c243d6

Since the review of c5b4cf9: 0 new · 0 still open · 1 no longer raised

No open findings.

1 finding below minor hidden (user_settings.min_severity).

Reviewed with this repository's own Sentinel configuration (63a3d5acf854).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@Doberjohn
Doberjohn merged commit 5a13338 into callstack:main Nov 27, 2026
12 checks passed
Doberjohn added a commit to jacekAtCK/react-native-paper that referenced this pull request Nov 29, 2026
The chevron's CSS transition keeps its duration, easing and reduce
motion handling, now built with the getTransition helper that Badge,
Checkbox and TextInput use since callstack#5112.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants