Skip to content

feat: return a Promise from every scroll method - #34

Closed
SectionTN wants to merge 17 commits into
mainfrom
plan/scroll-commands
Closed

SectionTN wants to merge 17 commits into
mainfrom
plan/scroll-commands

Conversation

@SectionTN

@SectionTN SectionTN commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

the scroll methods on the ref returned nothing, so an app had no way to wait for a scroll before it highlights or focuses a row. scrollToIndex, scrollToOffset and scrollToEnd now return a Promise that resolves when the list comes to rest, or when a drag, a newer scroll or an unmount stops it first. it never rejects. a scroll sent in the same frame as new data keeps its Promise and lands on the new rows.

the ref also gets the rest of what FlatList, FlashList and LegendList refs have: scrollToItem, scrollToTop, scrollIndexIntoView, scrollItemIntoView, setNativeProps, flashScrollIndicators, getScrollResponder and getNativeScrollRef. a ref typed as FlatList<Item>, FlashListRef<Item> or LegendListRef fits the ref prop, FlumeRef<Item> types the Promises, and Reanimated's scrollTo scrolls the list. new props: scrollViewRef and refScrollView, the four keyboard events, progressViewOffset, alignItemsAtEnd, persistentScrollbar on Android, and on iOS scrollsToTop, onScrollToTop, alwaysBounceHorizontal, indicatorStyle, directionalLockEnabled, canCancelContentTouches, scrollToOverflowEnabled and automaticallyAdjustsScrollIndicatorInsets.

Android never drew a scroll bar, so showsVerticalScrollIndicator and flashScrollIndicators did nothing there. the RecyclerView is built in code and never got a scroll bar drawable. it now takes ScrollView's default style, as React Native's ScrollView does, so Android lists show their scroll bars like a FlatList.

Summary by CodeRabbit

  • New Features

    • Added Promise-based scrolling methods for scrolling to items, bringing items into view, scrolling to points, and flashing indicators.
    • Added scroll-to-top events and keyboard event callbacks, plus support for additional native scroll settings.
    • Added end alignment and refresh-spinner offset options, and Android persistent scrollbar support.
    • Added compatibility with common list refs and access to ScrollView responder methods.
  • Bug Fixes

    • Scroll commands now resolve when scrolling settles or is interrupted, and out-of-range index requests can wait for data to arrive.

setData(next) and scrollToIndex in one handler send the command before the data. On Android
the waiting jump kept slots for the old keys, which never render, so it sat on the new top
rows until its 1 s deadline. With a list shorter than the index, both platforms clamped to the
old last row and stayed there (rows 94-99 on Android, 495-499 on iOS, for index 200). A data
change now aims the waiting jump at its index in the new rows and keeps its deadline, and an
index past the data waits for the data to grow.
Each scroll command now carries an id, and Android sends onScrollCommandEnd with it once the
list rests: after the layout pass and realign of an instant scroll, at the idle state after a
glide, and at once when nothing moves. A drag, leaving the window and anchoring's own scroll
end the command early. New data sends a command still on its way to its target in the new
rows, where anchoring used to put back the old top row and the list ended at its last row.
Each scroll command now sends onScrollCommandEnd with its id on iOS once the
list rests: right after an instant scroll, at the end of a glide or a realign,
and at once when nothing moves. A drag, the status bar, anchoring's own scroll
and leaving the window end the command early. UIKit ends a glide that a newer
scroll interrupts from inside that newer call, so only the end of the
command's own glide lands it.
An animated scroll sent while another glide ran never reported its end and
jumped to its target instead of gliding. UIKit ends the replaced glide from
inside the new setContentOffset call, and that callback re-landed on the new
target, which stopped the new glide. The callback now ignores the glide being
replaced, so the new one carries on and its own end lands the command.
scrollToIndex, scrollToOffset and scrollToEnd now return a Promise that
resolves once the list rests after the scroll, or when a drag, a newer scroll
or an unmount ends it first. A scroll sent in the same frame as new data is
sent again after that data reaches native, under a new id the Promise
follows, so setData and scrollToIndex from one handler land on the new rows.
On iOS the first one could stop 1.5 rows past the index. The out-of-range
warning now checks the index against the data at the end of that frame.
A scroll command sent while a finger held the list, from a timer or an onScroll
handler, landed under the finger and waited for the list to rest. After a release
without momentum no layout runs, so nothing ended it, and its Promise stayed pending
until the next command (24 s in one run). The end of a drag without momentum now ends it.
scrollToItem, scrollToTop, scrollIndexIntoView and scrollItemIntoView return a Promise
like the other scroll methods, and setNativeProps reaches the list's native view. The
into-view methods scroll only when the row is not fully visible, to the edge it is past,
as LegendList does. The list also takes the four keyboard event props, progressViewOffset
and alignItemsAtEnd.
Reanimated's scrollTo and code written against a ScrollView ref now reach the list.
The native scrollTo and flashScrollIndicators commands take ScrollView's names and
arguments, and scrollTo ends the scroll in flight and moves along the list's axis from
the content start. getScrollResponder returns a ScrollView-shaped object, which
scrollViewRef and refScrollView also receive, and getNativeScrollRef returns the host view.
A ref typed for FlatList, FlashList or LegendList failed to type-check against Flume's
ref prop, since the prop asked for every member of Flume's handle. The prop now takes
the members the three lists share, and the item type still comes from data. FlumeRef
takes the item type, and ComponentRef<typeof Flume> reads the handle with its Promises.
The status bar tap now reports onScrollToTop with the scroll event, both when UIKit
scrolls the list and when a list that can show React rows scrolls through its own jump,
whose glide UIKit never reports. scrollsToTop takes the tap away from a list and stays off
by default for a horizontal one. Android accepts the prop and ignores it, as React Native does.
The list never showed a scroll bar on Android, so showsVerticalScrollIndicator and
flashScrollIndicators had nothing to show. A RecyclerView built in code gets no scroll bar
drawable, since only a style with android:scrollbars creates one. The list now takes
ScrollView's default style, as React Native's ScrollView does, and draws its bars outside
the padding.
FlatList takes alwaysBounceHorizontal, indicatorStyle, directionalLockEnabled,
canCancelContentTouches, scrollToOverflowEnabled and automaticallyAdjustsScrollIndicatorInsets
on iOS and persistentScrollbar on Android, and Flume dropped them. Each now reaches the native
list, and the other platform accepts it and ignores it, as React Native does.
The Chat and React tabs show the last scroll command, how long its Promise took to settle
and how many are still open. The React tab gets an Into view 40 button.
A reset while an animated scroll ran its last stretch resolved the scroll's Promise at once,
then sent the scroll again with no id, so code after the await ran before the list arrived.
The list stopped the old glide before taking the command up again, and that stop looked like
the scroll's rest. The command now restarts before the glide stops and ends at the real rest.
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request expands Flume’s scroll props and ref methods. Scroll commands now return promises that settle through native completion events. Android and iOS add command tracking, jump-target handling, and scroll-to-top behavior. Examples and documentation cover the updated API.

Changes: Scroll API and Native Behavior

Layer / File(s) Summary
Public scroll contracts and props
src/types.ts, src/specs/FlumeViewNativeComponent.ts, src/props.ts, src/foreign.ts
The public types and native command contract add scroll-view props, keyboard callbacks, ref methods, command completion events, and commands for scrolling into view and flashing indicators. Prop normalization adds defaults for native scroll settings, progressViewOffset, and alignItemsAtEnd.
JavaScript command tracking and ref wiring
src/commands.ts, src/Flume.tsx, src/keyboard.ts, src/__tests__/*, src/__tests__/types/*, package.json, tsconfig.legacy-types.json
Scroll methods track request IDs and return promises that settle on native completion. Pending commands can be resent after data updates. The ref adds item, top, and into-view methods, plus responder access. Keyboard event props subscribe only when callbacks are provided. Tests cover command completion, ref methods, keyboard subscriptions, prop defaults, and ref typing. Typecheck adds the legacy-types configuration.
Command state and jump-target primitives
android/src/main/java/me/sectiontn/flume/JumpGate.kt, android/src/main/java/me/sectiontn/flume/JumpTarget.kt, android/src/main/java/me/sectiontn/flume/ScrollCommands.kt, cpp/adapter/JumpGate.h, cpp/adapter/ScrollCommands.*, android/src/test/java/me/sectiontn/flume/*Test.kt, cpp/tests/*_test.cpp
Kotlin and C++ helpers track command IDs and landed state, settle only when scrolling is at rest, and calculate into-view positions. Jump gates can retarget pending jumps while retaining their deadlines. Tests cover these state and targeting rules.
Android scroll commands and completion
android/src/main/java/me/sectiontn/flume/FlumeRecyclerView.kt, android/src/main/java/me/sectiontn/flume/FlumeView.kt, android/src/main/java/me/sectiontn/flume/FlumeViewManager.kt, android/src/main/java/me/sectiontn/flume/ScrollEvents.kt, android/src/main/java/me/sectiontn/flume/ScrollTargets.kt, android/src/test/java/me/sectiontn/flume/ScrollEventsTest.kt
Android forwards request IDs to scroll operations and emits command-end events. Index and end scrolling use jump targets that can be recalculated when rows change. The view also adds into-view scrolling, point scrolling, and indicator flashing, and ends commands on interruption or detachment.
iOS scroll commands and status-bar taps
ios/FLMView.mm, ios/FLMScrollEvents.mm, cpp/adapter/ScrollEvents.h
iOS adds scroll-view property handling and request-ID-based command tracking. Commands settle after landing and pending work complete, or end when interrupted. Status-bar taps emit scroll-to-top events.
Examples and API documentation
example/src/scrollStatus.ts, example/src/screens/*Screen.tsx, example/src/types/refs.types.tsx, README.md
Examples display scroll-promise status, exercise horizontal and inverted scrolling, and demonstrate list-ref typing. The README documents props, methods, Promise settlement, and migration details.

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant Flume
  participant NativeList
  Caller->>Flume: Call scroll method
  Flume->>NativeList: Send command with request ID
  NativeList->>Flume: Emit command completion event
  Flume->>Caller: Resolve scroll promise
Loading

Possibly related PRs

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@SectionTN

Copy link
Copy Markdown
Owner Author

split into smaller PRs so each one can be reviewed on its own: #35 (Android scroll bars, on main), then the stack #36 to #43 in merge order.

@SectionTN SectionTN closed this Nov 27, 2026
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.

1 participant