Skip to content

fix(ui): skip per-frame re-renders on the swatch tray - #133

Merged
cameronapak merged 2 commits into
highlightsfrom
fix/verse-action-swatch-scroll-state
Aug 13, 2026
Merged

fix(ui): skip per-frame re-renders on the swatch tray#133
cameronapak merged 2 commits into
highlightsfrom
fix/verse-action-swatch-scroll-state

Conversation

@cameronapak

@cameronapak cameronapak commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

Swatch-tray fades still appear and retire at the same remaining-distance gates, but a drag no longer re-renders the verse action sheet every frame.

Changes

  1. Fade overlays mount from overflow booleans, not the live scroll offset — layout and offset live in refs, React only stores the two gates.
  2. A layout pass mid-scroll still sees the current offset, so both fades stay put while the tray remeasures.

Test plan

  • pnpm --filter @youversion/platform-react-native-expo-ui test -- src/native/__tests__/bible-reader-verse-actions.test.tsx (27 passed)
  • npx react-doctor@latest --scope changedrn-no-scroll-state is gone
  • Needs manual check: swipe an overflowing swatch tray on device; leading and trailing fades still appear and retire at the ends

Made with Cursor

Greptile Summary

The PR extracts swatch-tray fade arithmetic into a tested helper and stores live measurements in refs so scrolling updates React only when an edge-visibility gate changes.

  • Adds focused tests for the fade thresholds and remaining-distance calculations.
  • Preserves the current scroll offset when layout measurements arrive mid-scroll.
  • Avoids updating component state with the raw offset on every scroll event.

Confidence Score: 5/5  ·  View in Greptile

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
packages/ui/src/lib/verse-action-fade-gates.ts Defines the shared, pure calculation for leading and trailing fade visibility.
packages/ui/src/lib/tests/verse-action-fade-gates.test.ts Covers fitting, overflowing, midpoint, endpoint, and one-pixel threshold behavior.
packages/ui/src/native/bible-verse-action-sheet.tsx Moves live tray dimensions and offset into a ref while retaining only fade visibility booleans in React state.
packages/ui/src/native/tests/bible-reader-verse-actions.test.tsx Adds coverage ensuring a layout pass during an active scroll preserves both applicable fades.

Reviews (2): Last reviewed commit: "refactor(ui): extract swatch tray fade g..." | Re-trigger Greptile

Scroll offset stays in a ref; React only stores the fade-gate booleans so a drag does not rebuild the verse action sheet every frame.

Co-authored-by: Cursor <cursoragent@cursor.com>
@cameronapak cameronapak self-assigned this Aug 13, 2026
@cameronapak
cameronapak requested a review from bmanquen August 13, 2026 18:50

@bmanquen bmanquen 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.

Two-axis review (Standards + Spec) against HEAD~1.

Standards: no hard violations. ADR 0017's load-bearing decisions are all intact — the fade still gates on remaining scroll distance, modal={false} and PAN_ACTIVE_OFFSET_Y are untouched, the sheet stays internal, and the explanatory comment block was preserved rather than dropped. No new user-visible strings, so .greptile/rules.md / native-i18n.md don't bite, and .changeset/native-highlights-release.md already covers the sheet.

Spec: not run — no issue reference in the commit, no spec file matching the branch.

Six judgement calls inline, all non-blocking. The one worth acting on is the first: swatchTrayFadeGates is a pure predicate sitting in the component, which is why its only coverage has to boot the whole BibleReader.

Comment thread packages/ui/src/native/bible-verse-action-sheet.tsx Outdated
Comment thread packages/ui/src/native/bible-verse-action-sheet.tsx Outdated
Comment thread packages/ui/src/native/bible-verse-action-sheet.tsx Outdated
Comment thread packages/ui/src/native/bible-verse-action-sheet.tsx
Comment thread packages/ui/src/native/bible-verse-action-sheet.tsx Outdated
Move the remaining-distance predicate to layer 1 so the arithmetic can be
tested without booting BibleReader, and store tray metrics as one ref.

Co-authored-by: Cameron Pak <cameronandrewpak@gmail.com>
@cameronapak
cameronapak merged commit 0e5fb10 into highlights Aug 13, 2026
8 checks passed
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.

3 participants