Skip to content

[iOS] UIKit's scroll to a focused field can leave the pager between pages #1230

Open

Description

@TaduJR

Environment

  • react-native-pager-view: main
  • React Native 0.88.0, new architecture
  • iPhone 18 Pro simulator, iOS 27.0, release build

Description

When a text field on another page takes focus, UIKit scrolls the pager's collection view to reveal it: scrollRectToVisible, twice and animated, once while the field becomes first responder and once from the keyboard notification. That scroll replaces the slide TabView is running and stops at the smallest offset that shows the field, and UIKit leaves the pager there.

The selection and the screen then disagree. onPageSelected reports page 2 while the pager rests nearest page 1, the log reads selected 2 and then state idle at 1, and the screen shows a sliver of page 0 beside page 1. Because the pager is not on a page boundary nothing reports a rest, so the input on the page being left keeps focus with the keyboard open.

Measuring the collection view's offset at scrollViewDidEndScrollingAnimation, against a 402 pt page:

run end offset
interrupt, with the arriving page's input focused in the same handler 377
interrupt, no focus 804
interrupt, keyboard already open from the previous page 804
focus on arrival, single setPage, no interrupt 402

Both ingredients are needed, and 377 is not arbitrary: it is the least the pager can scroll to bring that field on screen.

A per-instance override is viable, since PagerGestureObserver.installGestureArbitration already gives the pager's collection view its own runtime subclass. It is a behaviour change: an app that focuses an input on a page it is not showing would see nothing move, where today the pager is dragged between pages instead. An enclosing scroll view is unaffected, since in a pager inside a ScrollView inside a KeyboardAvoidingView the pager receives no reveal at all in 6 of 6 runs, and every one goes to the outer scroll view and the field's own editor.

Reproducible Demo

The example app has the screen already: Issue #1154 Page Change Focus Repro. Its event log reflows as it grows, which shifts the timing, so give the events box a fixed height first (height: 44 on styles.events) to see this reliably.

  1. Open the screen in a release build
  2. Tap onPress, so the arriving page's input is focused in the same handler as the command
  3. Tap the input on page 0, so the keyboard opens
  4. Tap Go 1 then 2, which sends setPage(1) and then setPage(2) from onPageSelected
  5. The pager stops between pages and stays there. The status line reads Selected: 2, the log ends state idle at 1, and the input on page 1 is still focused with the keyboard open

With that fixed height, two runs in six end this way on main. Without it the screen's own timing hides it most of the time, though the same case failed CI on #1224 with Selected: 1 | Focused: input 1 | Keyboard: visible | Scrolls: 9.

A fix is open as #1234, which declines the reveal from iOS 16 rather than repairing the landing after it.

Activity

  1. changed the title [-][iOS] A setPage that interrupts another can leave the pager between pages[/-] [+][iOS] An interrupted setPage leaves the pager between pages when an input takes focus mid-slide[/+] on Nov 5, 2026
  2. JaydeepAgravat commented on Nov 6, 2026

    @JaydeepAgravat

    Hi! Thanks for the detailed measurements. I'd like to look into this.

    I'll start by reproducing it in the example app (interrupt a setPage and focus an input on the arriving page), then check why the scroll ends 25 pt short when both happen. My guess is the keyboard's content inset change lands mid-animation. If that's it, the fix would be to snap to the target page once the animation ends.

    OK if I take it?

  3. KisaneNeko commented on Nov 6, 2026

    @KisaneNeko
    Collaborator

    @JaydeepAgravat I believe it'll be addressed in: #1227
    Update: actually, i think the main issue (being stuck between pages) will not be addressed. If you pick this up, I'd recommend waiting for 1227 to hit main or branching off of it as it addresses the side-issue when pager goes back to the previous page

  4. TaduJR commented on Nov 6, 2026

    @TaduJR
    ContributorAuthor

    I was working on this on just after opening the issue. Raised a PR.

    @KisaneNeko

    #1227 doesn't cover the strand, and #1234 now does, so they're complementary rather than overlapping in effect imo.

  5. changed the title [-][iOS] An interrupted setPage leaves the pager between pages when an input takes focus mid-slide[/-] [+][iOS] UIKit's scroll to a focused field can leave the pager between pages[/+] on Nov 6, 2026
  6. JaydeepAgravat commented on Nov 6, 2026

    @JaydeepAgravat

    Ah nice, thanks both. Since #1234 already covers it, I'll leave this one to you @TaduJR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions