[$125] iOS - Attachments - Password input of protected PDF closes after rotating to landscape
If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.
Version Number: v9.5.5-0 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://test-management.browserstack.com/projects/2219752/test-runs/76493747/folder/13176710/41236945/1815288238 Email or phone of affected tester (no customers): [email protected] Issue reported by: Applause Internal Team Bug source: Exploratory - Significant User Experience Deterioration Device used: iPhone 15 Pro / iOS 27.0.1 App Component: Chat Report View
Action Performed:
Preconditions:
- There is a 1:1 chat with several attachments uploaded (images, videos, files).
- The user has already uploaded a password-protected PDF into this chat.
- Open the Expensify App and log in as the user from the Precondition
- Go to the chat from the Precondition
- Tap on the password-protected PDF preview
- Tap on "Enter the password"
- While the password field is focused, rotate the device to landscape
Expected Result:
The user should stay on the same screen.
Actual Result:
The password input closes, and another attachment opens up.
Note 1: In the App, the first attachment in the chat opens up. Note 2: In mWeb (Safari), the closest attachment in the chat opens up.
Workaround:
Unknown
Platforms:
- [ ] Android: App
- [ ] Android: mWeb Chrome
- [x] iOS: App
- [ ] iOS: mWeb Safari
- [ ] iOS: mWeb Chrome
- [ ] Windows: Chrome
- [ ] MacOS: Chrome Safari
Screenshots/Videos
https://github.com/user-attachments/assets/88c23ebb-be0e-4356-b394-fa43a38faa37
Applause Internal Information Exported by: Svetlana Lazutkina Bug ID: 7280661
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022108314160360869510
- Upwork Job ID: 2108314160360869510
- Last Price Increase: 2026-11-18
Issue Owner
Current Issue Owner: @neerajbachani
While Applause doesn't embed attachments for this bug, here are the links for quick view: https://platform.applause.com/services/links/v1/external/9a766f7707aa90a499c39e41131088e029cf2307068f7f435c99df1d1d3ce7f6
Proposal
Confidence: medium. The code path is confirmed, but I didn't reproduce this on an iOS device. Web testing can't simulate an iOS rotation, so I skipped it.
What is the root cause of that problem?
When the device rotates, the carousel receives a page-change event that it didn't ask for, and it applies that event without checking it.
- iOS app: The native pager sends
onPageSelectedwith position0.updatePagethen callsKeyboard.dismiss()andsetPage(0). This closes the password input and opens the first attachment.onPageSelectedis the only code path that can set page0on native. - Likely regression: fix: Android - Split - Percentage input has to be focused twice to be able to edit it (merged 2026-09-14) bumped
react-native-pager-viewfrom 7.0.2 to 9.0.4. Version 9 rebuilt the iOS pager on a SwiftUITabView. Its selection is two-way bound tocurrentPage, and every change is sent to JS asonPageSelected, including resets caused by layout changes during rotation. - mWeb: The web carousel is a
FlatListpositioned by pixel offset (page * cellWidth). After a resize, a passiveuseEffectcorrects the scroll position. Before it runs, viewability callbacks can read the stale offset and select a neighbouring page. This matches the "closest attachment" note.
The password form isn't required by either mechanism, so rotating on any attachment probably triggers this too. I haven't verified that.
What changes do you think we should make in order to solve the problem?
- Native: In
AttachmentCarouselView/index.native.tsx, applyonPageSelectedonly when it follows a user drag (useonPageScrollStateChanged) or matches a page we set ourselves. Otherwise keep the current page and don't dismiss the keyboard. - Native: In
Pager/index.tsx, store the intended page in a ref. When the window dimensions change, callsetPageWithoutAnimation(intendedPage)so the native selection is restored after rotation. - Web: Change the
cellWidtheffect touseLayoutEffect. While a width change is being corrected, haveupdatePageskipsetPageandKeyboard.dismiss().
What alternative solutions did you explore? (Optional)
- Patch
react-native-pager-view'sPagerView.swiftwithpatch-package. The patch would re-applycurrentPageafter a size change and stop emittingonPageSelectedfor layout-only changes. Report the bug upstream too. This is cleaner long term but adds a patch to maintain. - Revert the pager-view bump. This would bring back the Android bug that the bump fixed.
Investigation details
- The parent carousel's attachment matching returns either the matching index or
-1, never0(AttachmentCarousel/index.tsx:78-105). That points to the native pager event as the source of page0. Pager/index.tsx:147-158passesonPageSelectedstraight to the native view.initialPageis read only when the native view is created, so JS can't restore the page through props.- In pager-view 9.0.4,
PagerView.swiftusesTabView(selection: $props.currentPage),.id(props.children.count), and.onChange(of: props.currentPage) { onPageSelected(...) }. A selection reset or a rebuilt view during rotation goes straight to JS. - Landscape usually flips
shouldUseNarrowLayout, which changes the PDF and password-form layout (PDFView/index.native.tsx:159-175). This could be what makes the native pager rebuild during rotation. I haven't verified this. - Web
updatePagealso callsKeyboard.dismiss()unconditionally and clears the active attachment when no item is visible during the resize (index.tsx:94-121).
To confirm the cause: log updatePage on the iOS simulator and rotate on a plain image and on the password form. Also check whether this reproduces on a build from before 2026-09-14.
Next Steps for Contributor+ team:
To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/103531) to create a draft PR.
To refine: @MelvinBot <your feedback>
To reject: Explain why you are rejecting Melvin's proposal.
Triggered auto assignment to Contributor-plus team member for initial proposal review - @huult (External)
Job added to Upwork: https://www.upwork.com/jobs/~022108314160360869510
Proposal
Please re-state the problem that we are trying to solve in this issue.
On iOS, when viewing a password-protected PDF attachment, rotating the device from portrait to landscape closes the password input and soft keyboard, and the carousel resets or navigates unexpectedly to another attachment.
What is the root cause of that problem?
In src/components/Attachments/AttachmentCarousel/AttachmentCarouselView/index.native.tsx, the native pager emits onPageSelected events during layout recomputation and orientation changes (SwiftUI TabView container re-render).
updatePage unconditionally executes Keyboard.dismiss() and updates the page state:
const updatePage = useCallback(
(newPageIndex: number) => {
Keyboard.dismiss();
setShouldShowArrows(true);
// ...
setPage(newPageIndex);
},
[setShouldShowArrows, attachments, setPage, onNavigate],
);
Because updatePage did not check whether newPageIndex === page:
- When the device rotates while viewing the protected PDF (at current
page), the native layout pass emitsonPageSelected(with position 0 or the current position). Keyboard.dismiss()is immediately triggered, which dismisses the iOS software keyboard and closes the PDF password form modal.- If the pager emitted 0 unprompted during orientation re-measurement,
setPage(0)switches the active attachment back to the first item in the report instead of preserving the currently viewed attachment.
What changes do you think we should make in order to solve the problem?
- In
src/components/Attachments/AttachmentCarousel/AttachmentCarouselView/index.native.tsx, add an early return guard inupdatePageso that whennewPageIndex === page, no redundant page state transition occurs andKeyboard.dismiss()is never called:
const updatePage = useCallback(
(newPageIndex: number) => {
if (newPageIndex === page) {
return;
}
Keyboard.dismiss();
setShouldShowArrows(true);
const item = attachments.at(newPageIndex);
setPage(newPageIndex);
if (newPageIndex >= 0 && item) {
setActiveAttachmentID(item.attachmentID ?? item.source);
if (onNavigate) {
onNavigate(item);
}
}
},
[setShouldShowArrows, attachments, setPage, onNavigate, page],
);
- Additionally, in
AttachmentCarouselPager(src/components/Attachments/AttachmentCarousel/AttachmentCarouselView/index.native.tsx), ensureonPageSelectedonly dispatches whennewPage !== page:
onPageSelected={({nativeEvent: {position: newPage}}) => {
if (newPage !== page) {
updatePage(newPage);
}
}}
This prevents keyboard dismissal on device rotation and preserves the user's active password input screen seamlessly across orientations.
What alternative solutions did you explore? (Optional)
- Dismissing keyboard only on manual touch gestures: Redundant since checking
newPageIndex === pagedirectly resolves both false-positive dismissal and unprompted navigation resets without complex touch event listeners. - Patching
react-native-pager-viewdirectly: Unnecessary overhead since guarding the callback in JS cleanly handles native layout change events without maintaining extra native patches.
Tests
- Open a chat report containing multiple attachments including a password-protected PDF.
- Tap on the protected PDF to open the attachment preview modal.
- Tap on the password input field so the keyboard is focused.
- Rotate the device from portrait to landscape and back.
- Verify that the keyboard remains open, the password modal is intact, and the viewer stays on the current protected PDF.
- Swipe left and right between attachments to confirm normal navigation still works and dismisses the keyboard as intended.
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0163955a2ba22190aa
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Proposal
What is the root cause of that problem?
This issue involves two separate platform behaviors triggering unintended page transitions during device orientation changes:
-
iOS Native (
AttachmentCarouselView/index.native.tsx&Pager/index.tsx):- In
AttachmentCarouselView/index.native.tsx, the native pager (AnimatedPagerViewwrappingreact-native-pager-view9.0.4) emitsonPageSelectedevents during device rotation layout passes when SwiftUI recomputes the view hierarchy. AnimatedPagerViewis initialized once withinitialPage, butreact-native-pager-viewdoes not continuously bind page selection to JS props. When the native iOS container rebuilds during rotation, its internal selection state resets to index 0 and emitsonPageSelected({nativeEvent: {position: 0}}).updatePageinAttachmentCarouselView/index.native.tsxunconditionally invokesKeyboard.dismiss()and executessetPage(newPageIndex). It lacks any validation to check whether the incomingonPageSelectedwas initiated by an active user gesture (isPagerScrolling) or represents an unprompted native layout reset.- As a result, when rotating the device while entering a password for an attachment (e.g. index 2), the native pager emits 0,
updatePage(0)dismisses the software keyboard, and the carousel navigates back to index 0 (the first attachment in the chat), unmounting the password form component and resetting its local state.
- In
-
Mobile Web / Safari (
AttachmentCarouselView/index.tsx):- On web,
updatePageis driven byAnimated.FlatList'sonViewableItemsChanged. - When the device rotates,
windowWidthandcellWidthchange immediately. The resizeuseEffectinvokesscrollRef.current.scrollToIndex({index: page, animated: false}). - However, during the layout transition before
scrollToIndexaligns the scroll offset to the new cell dimensions,onViewableItemsChangedfires with the closest partially visible item. updatePageunconditionally callsKeyboard.dismiss()and updatessetPageto that closest item, closing the password input and opening the neighboring attachment.
- On web,
What changes do you think we should make in order to solve the problem?
-
Native (
src/components/Attachments/AttachmentCarousel/AttachmentCarouselView/index.native.tsx&src/components/Attachments/AttachmentCarousel/Pager/index.tsx):- In
AttachmentCarouselPager(src/components/Attachments/AttachmentCarousel/Pager/index.tsx), track whether the page selection is driven by an active user gesture.usePageScrollHandleralready maintainsisPagerScrolling. - When
onPageSelectedfires:- If
event.nativeEvent.position === page, do not trigger page transitions or keyboard dismissal. - If
event.nativeEvent.position !== pagebut!isPagerScrolling.get(), recognize this as an unprompted native container layout reset (such as device rotation). Re-assert the current active page viapagerRef.current?.setPage(initialPage)and suppress the erroneous navigation to page 0.
- If
- In
AttachmentCarouselView/index.native.tsx, updateupdatePageto only callKeyboard.dismiss()when the target page index is different from the currently active page (newPageIndex !== page).
- In
-
Web (
src/components/Attachments/AttachmentCarousel/AttachmentCarouselView/index.tsx):- In
AttachmentCarouselView/index.tsx, introduce a resize guard ref (isResizingRef). WhencellWidthchanges due to window resize or orientation rotation, setisResizingRef.current = true. - In
updatePage, ignore viewable item updates whileisResizingRef.currentis active, resetting the flag oncescrollToIndexcompletes (e.g. insiderequestAnimationFrame). - Guard
Keyboard.dismiss()so it only fires whenentry.index !== page.
- In
-
Unit Tests:
- Add unit tests in
tests/unit/AttachmentCarouselTest.tsxverifying:updatePagedoes not dismiss the keyboard or emit navigation events when called with the current page index.- Layout/dimension changes preserve the active attachment page index without triggering unprompted navigation callbacks.
- Add unit tests in
What alternative solutions did you explore? (Optional)
- Dismissing keyboard only on blur: Does not solve the unwanted page switch to attachment 0 on native or adjacent attachments on web.
- Checking only
if (newPageIndex === page)inupdatePage: Insufficient on its own because the native pager on iOS emitsposition: 0when the user was viewing attachment 2 or higher; since0 !== 2, that simple check fails to prevent the carousel from switching to the first attachment. Validating gesture state (isPagerScrolling) or suppressing layout-shift events during rotation is essential.
Tests
- Open a chat report with multiple attachments (images/files) and at least one password-protected PDF.
- Tap on the password-protected PDF to open the attachment modal.
- Tap "Enter the password" to open and focus the password text input (keyboard appears).
- Rotate the device from portrait to landscape.
- Verify that the keyboard remains open, the password modal is intact, and the viewer stays on the protected PDF (does not jump to the first attachment).
- Rotate back to portrait and verify the password prompt remains open.
- Swipe left/right between attachments and verify normal swipe navigation functions correctly and dismisses the keyboard as intended.
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0170d6b02e9440e604
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
https://github.com/user-attachments/assets/3591a00a-0836-47f2-bf12-ecb88c078f29
Melvin’s proposal doesn’t fix the issue, so I’ll add the Help Wanted label.
:sos: C+ Help Wanted
Proposal
Please re-state the problem that we are trying to solve in this issue.
On iOS, with the password form of a protected PDF open in the attachment carousel, rotating to landscape dismisses the keyboard/form and the carousel jumps to the first attachment of the chat instead of staying on the PDF.
What is the root cause of that problem?
The native carousel treats every onPageSelected from react-native-pager-view as a user navigation, and since the 9.x upgrade the iOS pager emits a spurious onPageSelected(0) whenever its size changes.
- On iOS the pager is a SwiftUI
TabView(.page). In 9.x it is wrapped in aGeometryReaderand every page gets an explicit.frame(width: proxy.size.width, height: proxy.size.height)(added for vertical paging): https://github.com/callstack/react-native-pager-view/blob/v9.0.4/ios/PagerView.swift#L20-L24 In 8.0.0, used until PR#100149(b6c09f5b1af, merged 2026-09-14), pages had no proxy-driven frame: https://github.com/callstack/react-native-pager-view/blob/v8.0.0/ios/PagerView.swift#L12-L15 - On rotation the proxy size changes, every cell is re-framed, the collection view loses its page offset and SwiftUI writes page
0into theselectionbinding, which is forwarded to JS unconditionally: https://github.com/callstack/react-native-pager-view/blob/v9.0.4/ios/PagerView.swift#L78-L80 - App passes the event straight through to the parent: https://github.com/Expensify/App/blob/b9626f21ad103ac45dea17201bd64a882c148fec/src/components/Attachments/AttachmentCarousel/Pager/index.tsx#L151-L153
updatePage(0)then does exactly what the tester sees:Keyboard.dismiss()closes the password keyboard,setPage(0)/onNavigate(first)switch the modal to the first attachment: https://github.com/Expensify/App/blob/b9626f21ad103ac45dea17201bd64a882c148fec/src/components/Attachments/AttachmentCarousel/AttachmentCarouselView/index.native.tsx#L44-L59setPage(0)flows back asinitialPage, soactivePageIndexbecomes 0 and the PDF item losesisFocused, which is why the form never regains focus: https://github.com/Expensify/App/blob/b9626f21ad103ac45dea17201bd64a882c148fec/src/components/Attachments/AttachmentCarousel/Pager/index.tsx#L74-L77
This matches every detail: iOS App only (Android's ViewPager2 keeps its item across rotation), "the first attachment opens" (page 0, not a neighbour), and in the video the keyboard disappears and the first attachment's spinner appears the moment the rotation ends. Nothing in App touches the pager on rotation, and 9.0.5-9.0.7 do not change this path, so a library bump does not fix it.
What changes do you think we should make in order to solve the problem?
Make AttachmentCarouselPager gate page-selection events: forward only selections the user swiped to, and put the pager back when the native layer moved on its own.
In Pager/index.tsx:
- keep a ref mirror of
activePageIndexand anisUserPagingRefset inonPageScrollStateChangedwhenpageScrollState === 'dragging'(every swipe starts with this state; a layout reset never does); - replace
onPageSelected={onPageSelected}with a local handler:
const handlePageSelected = (e) => {
const {position} = e.nativeEvent;
if (position === activePageIndexRef.current) { isUserPagingRef.current = false; return; }
if (!isUserPagingRef.current) {
// native re-layout (rotation) moved the pager; restore the page the App is on
pagerRef.current?.setPageWithoutAnimation(activePageIndexRef.current);
return;
}
isUserPagingRef.current = false;
onPageSelected?.(e);
};
Repro trace: rotation → native emits onPageSelected(0) with no dragging state → 0 !== activePageIndexRef → pager snapped back to the PDF page, nothing forwarded, so Keyboard.dismiss() and setPage(0) never run and the password field keeps focus. The snap-back echoes onPageSelected(N), which equals the active page and is dropped. Regression safety: a user swipe still starts with dragging and is forwarded unchanged; arrow navigation calls updatePage before pagerRef.setPage (index.native.tsx#L65-L77) and the mount-time onPageSelected(initialPage) already matches the active page, so dropping those echoes changes nothing.
Why the obvious one-liner does not work: snapping in onLayout (setPageWithoutAnimation(activePage.get()) when the width changes) fails in both orderings. Before the SwiftUI reset it sets currentPage to the value it already has, so nothing happens and onPageSelected(0) still follows; after the reset activePage was already overwritten to 0 by the onPageScroll worklet (Pager/index.tsx#L68-L73), so it snaps to the wrong page. The guard has to sit on the event itself.
Secondary (optional): mWeb Safari (Note 2) is a different mechanism: the web carousel derives cellWidth from windowWidth and the FlatList keeps its old offset after rotation, so the nearest row becomes active (https://github.com/Expensify/App/blob/b9626f21ad103ac45dea17201bd64a882c148fec/src/components/Attachments/AttachmentCarousel/AttachmentCarouselView/index.tsx#L86-L90); a scrollToIndex({index: page, animated: false}) when cellWidth changes covers it, outside this report's iOS scope.
What alternative solutions did you explore? (Optional)
onLayoutsnap-back only (above): no-op before the reset, wrong target after it, and it does not stopupdatePage(0)from dismissing the keyboard.- Patch
react-native-pager-view(re-applycurrentPageon size change, or key theTabViewon the size): the binding is already 0 when it runs, soonPageSelected(0)is still emitted, and re-keying drops the text input's first-responder status. Worth an upstream report, but App should not wait on it.
Proposal
Please re-state the problem that we are trying to solve in this issue.
On iOS, while the password field of a password-protected PDF is focused in the attachment carousel, rotating the device to landscape closes the password form and switches the carousel to a different attachment (the first one in the chat).
What is the root cause of that problem?
On native, the carousel is AttachmentCarouselPager, a react-native-pager-view PagerView. Every onPageSelected event coming from it is forwarded straight to updatePage:
https://github.com/Expensify/App/blob/bca2d46d4b68c64fd406d830df400f694543b19e/src/components/Attachments/AttachmentCarousel/AttachmentCarouselView/index.native.tsx#L104-L114
and updatePage treats it as a user navigation: it dismisses the keyboard, changes page, and calls onNavigate with the new item, which makes the modal show that attachment instead of the PDF:
https://github.com/Expensify/App/blob/bca2d46d4b68c64fd406d830df400f694543b19e/src/components/Attachments/AttachmentCarousel/AttachmentCarouselView/index.native.tsx#L43-L60
On iOS, react-native-pager-view 9.x is a SwiftUI TabView with the page style, whose selection is bound to currentPage; any change of that selection is emitted to JS as onPageSelected. When the pager's frame changes (rotation), the underlying collection view keeps its old content offset while the page width changes, so TabView resolves the selection to a different page (in landscape the old offset maps to a lower index, which is why the first attachment opens) and emits onPageSelected without any swipe. With the keyboard up this is made worse in the version we ship (9.0.4): its GeometryReader root still honours the keyboard and safe-area regions, so every page is re-framed several times while the keyboard and safe area change during the rotation (fixed upstream in 9.0.5 and 9.0.6, callstack/react-native-pager-view#1140 and #1150):
https://github.com/Expensify/App/blob/bca2d46d4b68c64fd406d830df400f694543b19e/package.json#L207
Nothing on our side distinguishes a layout-induced selection change from a real swipe. The web carousel has an explicit guard that re-aligns the list to the current page whenever the cell width changes:
https://github.com/Expensify/App/blob/bca2d46d4b68c64fd406d830df400f694543b19e/src/components/Attachments/AttachmentCarousel/AttachmentCarouselView/index.tsx#L237-L246
but the native view has no equivalent, so the spurious selection is accepted and the PDF (and its password form) is replaced.
What changes do you think we should make in order to solve the problem?
- In
AttachmentCarouselPager, track whether the current page change was started by the user: set a ref whenonPageScrollStateChangedreportsdragging, and clear it once that drag's selection has been reported (atidleif the page was already selected during the drag, otherwise when the selection arrives, since iOS can report it after the pager settles). Also record the page we request programmatically in the imperativesetPagehandle (used by the arrow buttons). - Wrap
onPageSelectedthere: if the selected position equals the page the carousel is already on, or the change came from a user drag, or it matches the page we requested programmatically, forward it as today. Otherwise the selection was caused by a layout change (rotation, keyboard), so do not forward it; instead callsetPageWithoutAnimationwith the current page to snap the pager back, and ignore the selection event that the snap-back itself emits. That keepspage, the active attachment and the PDF's local password state untouched, andKeyboard.dismiss()inupdatePageis not triggered. - Bump
react-native-pager-viewto 9.0.6 (the newest 9.0.x allowed by the repo's 7-daymin-release-age), which stops the pager'sGeometryReaderroot from reacting to the keyboard and safe area, so pages are no longer re-framed while the keyboard is open. The guard in steps 1-2 is still needed because a plain rotation changes the frame regardless.
Compare branch: https://github.com/Expensify/App/compare/main...wildan-m:App:wildan/103531-pager-ignore-layout-page-change?expand=1
What alternative solutions did you explore? (Optional)
Remount the pager with a key derived from the window dimensions so it is re-created at the current page after rotation. It keeps the right attachment, but it remounts every carousel item, so the PDF's typed password and focus are lost, and it still cannot stop the onPageSelected that fires before the remount.
🤖 ProposalPolice™ is tracking duplicate proposals for this issue using an OpenAI Conversation. This comment stores that Conversation's ID and can be safely ignored.
Proposal
Please re-state the problem that we are trying to solve in this issue.
On iOS, opening the password form for a protected PDF and rotating the device closes the form. The carousel also leaves the PDF. The same close happens in mobile
Safari when the viewport actually resizes. The field and Confirm should stay on the PDF through landscape and back.
What is the root cause of that problem?
These are two resizes, not one spurious page event.
On the native app, the attachment screen turns keyboard avoidance on by default. Rotation hides the keyboard, so that view shrinks the pager. The pager then
reports a page it was not asked for, and updatePage always dismisses the keyboard and selects that page. With the form open on a later attachment, that reported
page is 0, so the PDF unmounts.
The screen does not turn avoidance off:
https://github.com/Expensify/App/blob/a66a788c1843dfefa4338d2499dfcb3b008d48dc/src/pages/media/AttachmentModalScreen/AttachmentModalContainer/index.native.tsx#L55-L59
The default is on, and that flag is what enables the avoiding view:
https://github.com/Expensify/App/blob/a66a788c1843dfefa4338d2499dfcb3b008d48dc/src/components/ScreenWrapper/ScreenWrapperContainer.tsx#L97-L97
https://github.com/Expensify/App/blob/a66a788c1843dfefa4338d2499dfcb3b008d48dc/src/components/ScreenWrapper/ScreenWrapperContainer.tsx#L202-L205
Every native page-selected event is applied, including the one caused by the resize:
https://github.com/Expensify/App/blob/a66a788c1843dfefa4338d2499dfcb3b008d48dc/src/components/Attachments/AttachmentCarousel/AttachmentCarouselView/index.native.tsx#L44-L56
https://github.com/Expensify/App/blob/a66a788c1843dfefa4338d2499dfcb3b008d48dc/src/components/Attachments/AttachmentCarousel/AttachmentCarouselView/index.native.tsx#L104-L104
On Safari the browser has to resize. Each page is windowWidth wide, and a width change is supposed to scroll back to the current page. That scroll loses the race.
onViewableItemsChanged fires from the old offset first, and updatePage treats that sample as a swipe: it dismisses the keyboard, and if the sample is empty it
clears focus. Either path unmounts the password form. On an iPhone 17 Pro this was traced as 402×714 becoming 874×292 while the form was still mounted, then the
URL changing to the first image. An iPhone 11 simulator never delivered that resize, so it could not show this path.
https://github.com/Expensify/App/blob/a66a788c1843dfefa4338d2499dfcb3b008d48dc/src/components/Attachments/AttachmentCarousel/AttachmentCarouselView/index.tsx#L86-L86
https://github.com/Expensify/App/blob/a66a788c1843dfefa4338d2499dfcb3b008d48dc/src/components/Attachments/AttachmentCarousel/AttachmentCarouselView/index.tsx#L89-L112
https://github.com/Expensify/App/blob/a66a788c1843dfefa4338d2499dfcb3b008d48dc/src/components/Attachments/AttachmentCarousel/AttachmentCarouselView/index.tsx#L208-L217
https://github.com/Expensify/App/blob/a66a788c1843dfefa4338d2499dfcb3b008d48dc/src/components/Attachments/AttachmentCarousel/AttachmentCarouselView/index.tsx#L264-L265
What changes do you think we should make in order to solve the problem?
Stop the iOS resize. Do not filter onPageSelected. On iOS only, disable keyboard avoidance on the attachment screen. Keep it on Android and web. Put the keyboard
height on the password form as padding, so Confirm can scroll above the keyboard without the pager changing size.
shouldEnableKeyboardAvoidingView={!shouldDisableAttachmentModalKeyboardAvoidance}
-contentContainerStyle={styles.p5}
+contentContainerStyle={shouldDisableAttachmentModalKeyboardAvoidance ? [styles.p5, StyleUtils.getPaddingBottom(keyboardHeight)] : styles.p5}
On Safari, do not stop the browser resize. Mark a width change from resize and orientationchange before React re-renders, scroll the current page back, and ignore
viewability until that page is reported again. Dismiss the keyboard only when the reported index is a different page. An empty sample must not clear focus. After
the width has settled, a real swipe or arrow still changes the page. This covers the 17 Pro path that actually resizes, and any phone whose Safari does the same.
It does not try to rotate a simulator that never sends a viewport change.
-Keyboard.dismiss();
-if (!entry) {
- setActiveAttachmentID(null);
- return;
-}
+if (isRestoringPageAfterResize.current) {
+ if (entry?.index === pageRef.current) {
+ isRestoringPageAfterResize.current = false;
+ }
+ return;
+}
+if (!entry || entry.index === pageRef.current) {
+ return;
+}
+Keyboard.dismiss();
What alternative solutions did you explore? (Optional)
Ignoring onPageSelected or a viewability sample without stopping the iOS resize leaves the pager free to report page 0. That is the workaround already tried.
Upgrading react-native-pager-view was ruled out, and remounting the pager on a size key drops the typed password. Locking orientation would hide the bug by
removing landscape. Sizing each page to the visual viewport was checked for the separate landscape clip, where the field runs off the right edge. That clip is
already on main and is not this close-on-rotate bug.
What specific scenarios should we cover in automated tests?
- A viewability sample for a different index, fired while the cell width has just changed, does not call setPage, onNavigate, or Keyboard.dismiss, and the open
attachment stays focused. - After that sample, a sample for the current index clears the guard, and a later different index does navigate.
- An empty viewability sample does not clear focus.
- A viewability change during fullscreen still does nothing.
- On iOS, the attachment screen renders with keyboard avoidance disabled. On Android and web, it stays enabled.
Hi Contributors, I checked this ticket and found that the issue only occurs on a physical device. However, if you can reproduce it on a simulator, that’s fine too!
Could you please reproduce the issue first and share a video showing both the issue before the fix and the result after applying your proposed solution? This will help confirm that you can reproduce the issue and that your proposal actually fixes it.
I’ll prioritize reviewing proposals that include a video demonstrating successful reproduction and a working fix.
Thanks!
Proposal updated — added compare branch with implementation.
Proposal
Update, 2026-10-11. Two changes to what I posted on 10-09:
- Target version is 9.0.6, not 9.0.7. Our
.npmrchasmin-release-age=7and 9.0.7 was published on 10-08, so it can't be installed before 10-15. 9.0.6 already contains both upstream fixes (callstack/react-native-pager-view#1140 and #1150); 9.0.7 only adds an edge-effect fix for vertical pagers. I re-ran my harness on 9.0.6 and added the row below.- In-app evidence in this thread disagrees about the bump. One contributor reports that with 9.0.6 installed the App still receives
onPageSelected(0)and jumps; another reproduced the bug on a dev iOS build and proposes the same bump. My harness shows the native drift on 9.0.4 and none on 9.0.6 / 9.0.7, but it is not the App and never produced theonPageSelected(0)itself, so it cannot settle that. A device recording on 9.0.6 will.
What is the root cause of that problem?
The pixels in the video are rendered by AttachmentCarouselPager (react-native-pager-view), and the regression is in the iOS layout of the version we ship, 9.0.4. It is not an App-side event-handling bug.
https://github.com/Expensify/App/blob/b9626f21ad103ac45dea17201bd64a882c148fec/package.json#L207
Two corrections to the thread first, because they change the fix. 8.0.0 (what we had before #100149) was already a SwiftUI TabView, so "v9 rebuilt the pager on SwiftUI" is not the difference: https://github.com/callstack/react-native-pager-view/blob/v8.0.0/ios/PagerView.swift#L12-L13. What 9.0.2+ added is a GeometryReader root with every page framed to proxy.size:
https://github.com/callstack/react-native-pager-view/blob/v9.0.4/ios/PagerView.swift#L20-L24
In 9.0.4 that proxy still honours the safe area and the keyboard region, so pages are framed smaller than the collection view's page size. Upstream describes exactly this in callstack/react-native-pager-view#1140 (9.0.5) and callstack/react-native-pager-view#1150 (9.0.6). On rotation both the safe area and the keyboard frame change, the cells are re-framed, and the pager is left parked between two pages.
I didn't want to argue this from reading Swift, so I measured it. I compiled the library's unmodified iOS sources (PagerView.swift, PagerViewProvider.swift, PagerScrollDelegate.swift, Extensions.swift) into a small UIKit host: 6 pages, page 3 selected with a focused text field, software keyboard up, -20 horizontal margin like our pageMargin={40}, frames applied asynchronously after rotation the way Fabric commits them. iPhone 17 Pro simulator, iOS 26.5, rotate portrait to landscape, log every delegate callback:
| pager-view | last onPageScroll after rotation |
spurious onPageSelected |
|---|---|---|
| 8.0.0 | position=3 offset=0.000 |
none |
| 9.0.4 | position=2 offset=0.961 |
none |
| 9.0.6 | position=3 offset=0.000 |
none |
| 9.0.7 | position=3 offset=0.000 |
none |
9.0.4 drifted on 3/3 runs, and it drifts with or without the keyboard. 8.0.0, 9.0.6 and 9.0.7 never did.
Two things follow. On 9.0.4 the pager really is knocked off its page by rotation, and that state reaches JS: onPageScroll reports position=2 with a non-zero offset, so activePage becomes the neighbour and isPagerScrolling is stuck true:
https://github.com/Expensify/App/blob/b9626f21ad103ac45dea17201bd64a882c148fec/src/components/Attachments/AttachmentCarousel/Pager/index.tsx#L68-L73
And in none of those runs did the native pager emit onPageSelected by itself on a size change. Once the selection does move, the rest is what the tester sees: updatePage dismisses the keyboard and switches the attachment.
https://github.com/Expensify/App/blob/b9626f21ad103ac45dea17201bd64a882c148fec/src/components/Attachments/AttachmentCarousel/AttachmentCarouselView/index.native.tsx#L44-L59
Limits of what I verified: this is a native harness on a simulator, not the App on a physical device. It reproduces the drift, but not the final selection change, and I have not run the full flow on a device build.
What changes do you think we should make in order to solve the problem?
Fix it at the dependency layer: bump react-native-pager-view from 9.0.4 to 9.0.6.
"react-native-pager-view": "9.0.6"
That brings in both upstream fixes: ignoreSafeArea: true on the hosting controller, and .ignoresSafeArea() on the GeometryReader root. In the harness that is the whole difference between the pager ending at 2.961 and at 3.000.
Why this layer: the wrong state is created natively, before any JS runs. Filtering events in JS can keep page from changing, but the pager would still be sitting between two attachments in landscape with isPagerScrolling stuck.
Blast radius is small. I diffed the 9.0.4 and 9.0.7 npm tarballs: outside lib/, the changes are three iOS Swift files and an import-style change in src/ (root react-native codegen imports, which RN 0.86 exports). 9.0.6 is a subset of that. There are no Android source changes, so the Android fix from #100149 is untouched.
Verification: there is no JS change, so Jest has nothing to assert. The evidence is the harness matrix above. In the PR I would record before/after on a device build for this exact flow, plus rotation on a plain image, swipe and arrow navigation, and the split percentage input from #100149 on Android.
What alternative solutions did you explore? (Optional)
- Re-assert the page from JS when the pager width changes (
setPageWithoutAnimation(page)in an effect). Rejected: in my runs the native selection was still 3 while the offset was wrong, so settingcurrentPageto the value it already has is a no-op. patch-packagethe two upstream hunks onto 9.0.4. Rejected: the bump has no Android source changes to avoid, so a patch only adds maintenance.- Go back to 8.0.0. It doesn't drift, but it brings back the Android bug #100149 fixed.
- The event-gating approach already posted would leave the drift above in place. I'd only add an App-side guard if the bug still reproduces on 9.0.6 in a device build.
Proposal
Please re-state the problem that we are trying to solve in this issue.
On iOS, rotating the device while the password field of a protected PDF is focused closes the password input and the carousel shows a different attachment instead of staying on the PDF.
What is the root cause of that problem?
The page change happens entirely inside the native pager. JS never gets told about it, which is why gating onPageSelected (Melvin's proposal that huult tested) has no effect.
We ship react-native-pager-view 9.0.4
https://github.com/Expensify/App/blob/a3b57851ca4022672935d851993be36ad5ef7920/package.json#L205
In 9.0.4 the SwiftUI root is a GeometryReader and every page is framed to proxy.size. The reader still honours the keyboard and safe area regions, so while rotating with the keyboard up the pages get re-framed several times while the page-style collection view keeps its old content offset
https://github.com/callstack/react-native-pager-view/blob/v9.0.4/ios/PagerView.swift#L19-L38
onPageSelected is only emitted when the currentPage binding changes
https://github.com/callstack/react-native-pager-view/blob/v9.0.4/ios/PagerView.swift#L78-L80
but here the binding doesn't change, only the scroll offset does. The only thing JS receives is onPageScroll from scrollViewDidScroll, and since no drag/decelerate happened, the delegate never sends the clean offset: 0 idle event
https://github.com/callstack/react-native-pager-view/blob/v9.0.4/ios/PagerScrollDelegate.swift#L22-L51
I didn't want to guess this from reading Swift, so I built the unmodified pager-view iOS sources into a small UIKit host on the simulator (iPhone 17 Pro, iOS 26.5, software keyboard): 6 pages, page index 3 has a focused secure text field, then the app rotates to landscape and back. The host mirrors updatePage (dismiss keyboard + change page on any onPageSelected). Log for 9.0.4:
2.225 STEP focus field
4.851 STEP rotate -> landscape
5.049 onPageScroll pos=2.0 off=0.818
5.058 onPageScroll pos=2.0 off=0.959
9.050 STEP rotate -> portrait
9.065 onPageScroll pos=3.0 off=0.030
9.069 onPageScroll pos=7.0 off=0.109
Same run on 9.0.6:
2.203 STEP focus field
4.831 STEP rotate -> landscape
9.029 STEP rotate -> portrait
So on 9.0.4 the pager is pushed off its page by rotation (it even reports pos=7 on a 6 page pager on the way back), and zero onPageSelected events fire in either run. On a device the offset ends up further away and the page holding the focused field scrolls out, so the field resigns first responder and the tester sees another attachment. App state still says we're on the PDF.
The App side makes it worse in one more way. Our scroll worklet takes that drift as real paging
https://github.com/Expensify/App/blob/a3b57851ca4022672935d851993be36ad5ef7920/src/components/Attachments/AttachmentCarousel/Pager/index.tsx#L68-L73
so after the rotation activePage points to the neighbour and isPagerScrolling stays true because the final offset: 0 never comes. isPagerScrolling is what disables pinch/zoom in the lightbox
https://github.com/Expensify/App/blob/a3b57851ca4022672935d851993be36ad5ef7920/src/components/Lightbox/index.tsx#L218
so on 9.0.4 an image attachment can't be zoomed after a rotation either, same root cause.
What changes do you think we should make in order to solve the problem?
Bump react-native-pager-view from 9.0.4 to 9.0.6 (update package-lock.json and ios/Podfile.lock).
9.0.6 puts .ignoresSafeArea() on the GeometryReader root (callstack/react-native-pager-view#1150) and 9.0.5 restores ignoreSafeArea: true on the hosting controller (callstack/react-native-pager-view#1140), so the pages are no longer re-framed for the keyboard and safe area during rotation
https://github.com/callstack/react-native-pager-view/blob/v9.0.6/ios/PagerView.swift#L56-L59
The v9.0.4...v9.0.6 diff only touches 3 iOS Swift files, no JS and no Android, so the Android fix from #100149 stays as is. 9.0.6 is the newest version allowed by our min-release-age right now (9.0.7 only adds the vertical edge effect fix, which we don't need).
No JS change is needed. I'd specifically not add an onPageSelected guard / snap-back here: in the measured flow there is no event to guard, and setPageWithoutAnimation(currentPage) sets the binding to the value it already has, so SwiftUI doesn't re-scroll.
In the PR I'll record before/after on a device build for: the exact issue flow, rotating on a plain image (and pinch zoom after it), swipe + arrow navigation after rotating, and the split percentage input from #100149 on Android.
What specific scenarios should we cover in automated tests?
The bug lives in the native SwiftUI TabView, so a Jest test can't rotate it. Manual/device checks are listed above.
What alternative solutions did you explore? (Optional)
- Gate
onPageSelectedin JS and snap the pager back (Melvin, and a few of the proposals above). In the measured runs noonPageSelectedis emitted during rotation, so the gate never runs. That's consistent with huult still reproducing it with Melvin's approach. patch-packagethe two upstream hunks on 9.0.4. Same Swift change, plus a patch to maintain.- Revert to 8.0.0. Doesn't drift, but brings back the Android bug #100149 fixed.
Proposal
What is the root cause of that problem?
On iOS, react-native-pager-view 9.0.4 (upgraded in #100149) fires a spurious onPageSelected event — typically with position 0 — whenever the device rotates and the native SwiftUI TabView relayouts. The carousel's updatePage handler treats every onPageSelected as a real user navigation: it calls Keyboard.dismiss() (closing the password input) and sets the page to 0 (jumping to the first attachment).
Simply gating the JS callback is not enough because the native pager has already moved to page 0 visually — the carousel must also be programmatically restored to the correct page.
What changes do you think we should make in order to solve the problem?
In AttachmentCarouselView/index.native.tsx, detect rotation inside updatePage by comparing the current window dimensions (Dimensions.get('window')) against the last known dimensions stored in a ref. When a dimension change is detected (rotation), skip all side effects (Keyboard.dismiss, setPage, onNavigate) and instead call pagerRef.current.setPage(currentPage) to programmatically restore the correct page.
Additionally, after the restore call the pager fires another onPageSelected with the now-correct index. Guard against that by returning early when the incoming page index equals the current page, preventing an unnecessary keyboard dismissal.
What alternative solutions did you explore? (Optional)
- Gating
onPageSelectedalone (Melvin's approach) — the C+ reviewer confirmed this does not fix the visual jump because the native pager has already moved to page 0 before JS is notified. - Listening for dimension changes via
useWindowDimensions+useEffectto restore the page — rejected because the effect runs after render, which is too late; the spuriousonPageSelectedfires synchronously from native before the effect has a chance to set a guard flag.
I'll prioritize reviewing proposals that include a video demonstrating successful reproduction and a working fix.
@huult I've updated my proposal and added the before/after videos.
The iOS pager emits onPageSelected(0) when the password keyboard opens. updatePage treats that as a swipe, dismisses the keyboard, and opens the first attachment. The fix returns before updatePage for that selection and snaps the pager back to the PDF. That change is only in AttachmentCarouselView/index.native.tsx. Forwarding onPageScrollStateChanged from Pager/index.tsx is an optional fallback.
I also tested 9.0.6 on its own and the jump still reproduces, so the bump doesn't fix it.