Skip to content

fix(ui-ios): #5200 — scrollViewSetOffset binds y, restores without animation#5449

Merged
proggeramlug merged 1 commit into
mainfrom
fix/5200-scrollview-set-offset-y
Jun 19, 2026
Merged

fix(ui-ios): #5200 — scrollViewSetOffset binds y, restores without animation#5449
proggeramlug merged 1 commit into
mainfrom
fix/5200-scrollview-set-offset-y

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Fixes #5200.

Problem

scrollViewSetOffset(sv, x, y) ignored y and always used x. The shared dispatch row already declares three args (Widget, F64, F64):

// crates/perry-dispatch/src/ui_table.rs
MethodRow { method: "scrollViewSetOffset", runtime: "perry_ui_scrollview_set_offset",
            args: &[ArgKind::Widget, ArgKind::F64, ArgKind::F64], ret: ReturnKind::Void },

…but the iOS FFI and impl took a single offset and bound it to the first f64 (x):

pub extern "C" fn perry_ui_scrollview_set_offset(scroll_handle: i64, offset: f64) { ... }
pub fn set_offset(scroll_handle: i64, offset: f64) {
    let point = CGPoint::new(0.0, offset);  // offset = x (usually 0) → contentOffset.y = 0
    ...
}

So setContentOffset received (0, x) with x almost always 0, and any caller doing scrollViewSetOffset(sv, 0, savedY) snapped to the top instead of savedY — scroll-position restoration broke on every rebuild.

Fix

Thread both coordinates through the FFI into the impl, and set the offset without animation (this path restores position, so animating is wrong):

pub extern "C" fn perry_ui_scrollview_set_offset(scroll_handle: i64, x: f64, y: f64) {
    widgets::scrollview::set_offset(scroll_handle, x, y);
}
pub fn set_offset(scroll_handle: i64, x: f64, y: f64) {
    let point = CGPoint::new(x, y);
    let _: () = msg_send![&*scroll_view, setContentOffset: point, animated: false];
}

cargo check -p perry-ui-ios is clean (only pre-existing warnings).

Note

The same single-offset signature exists in the other native UI backends (perry-ui-macos, tvos, visionos, android, gtk4, windows) and the JS/wasm runtimes, all fed by the same 3-arg dispatch row — so they share this latent y-ignored bug. This PR is scoped to iOS per the issue; the sibling backends are worth a follow-up.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Scroll view positioning now supports both horizontal and vertical offsets independently.
  • Bug Fixes

    • Updated scroll view restoration to use non-animated positioning for more reliable scroll behavior.

…imation

The `scrollViewSetOffset` dispatch row already declares three args
(Widget, F64, F64), but the iOS FFI and impl took a single `offset` and
bound it to the first f64 (x). `setContentOffset` therefore got
`(0, x)` with x almost always 0, snapping the view to the top instead
of the requested y. Restoring scroll position across rebuilds
(`scrollViewSetOffset(sv, 0, savedY)`) always jumped to the top.

Take both coordinates through the FFI into the impl, and set the offset
without animation since this is used to restore position.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e79709fd-5edc-40c5-a62c-bf530fa5044c

📥 Commits

Reviewing files that changed from the base of the PR and between 8b71256 and d666ea2.

📒 Files selected for processing (2)
  • crates/perry-ui-ios/src/ffi/widgets_basic.rs
  • crates/perry-ui-ios/src/widgets/scrollview.rs

📝 Walkthrough

Walkthrough

The iOS scroll view FFI function perry_ui_scrollview_set_offset and its backing implementation set_offset are updated to accept two f64 parameters (x, y) instead of one. The implementation constructs a CGPoint from both coordinates and sets the content offset with animated: false.

Changes

Scroll Offset x/y Fix

Layer / File(s) Summary
set_offset implementation and FFI wrapper
crates/perry-ui-ios/src/widgets/scrollview.rs, crates/perry-ui-ios/src/ffi/widgets_basic.rs
set_offset now takes x and y, builds CGPoint::new(x, y), and passes animated: false to setContentOffset. The FFI wrapper perry_ui_scrollview_set_offset is updated to accept and forward both parameters.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

A rabbit once scrolled but kept landing on top,
The y was ignored — what an unfortunate flop!
Now x and y hop together in sync,
CGPoint gets both with a nod and a wink.
No animation needed, just snap to the right spot! 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main fix: updating scrollViewSetOffset to properly bind both x and y coordinates and restore scroll position without animation.
Description check ✅ Passed The description includes a clear summary, detailed problem statement, solution with code examples, and notes on scope. However, it lacks explicit test plan checkboxes completion or confirmation of cargo checks.
Linked Issues check ✅ Passed The PR fully addresses #5200 by fixing the iOS FFI signature and implementation to accept both x and y coordinates and properly pass them to setContentOffset without animation.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the iOS implementation of scrollViewSetOffset as described in #5200. No unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/5200-scrollview-set-offset-y

Comment @coderabbitai help to get the list of available commands and usage tips.

@proggeramlug proggeramlug merged commit 20efa94 into main Jun 19, 2026
15 checks passed
@proggeramlug proggeramlug deleted the fix/5200-scrollview-set-offset-y branch June 19, 2026 11:40
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.

iOS: scrollViewSetOffset(sv, x, y) ignores y — always scrolls to 0 (FFI takes one offset, binds x)

1 participant