[iOS] Focused TextInput keeps focus and keyboard after switching pages (v9)
維護者通常 1 天內回覆
評估
- 難度
- 4/5
- 預估耗時
- 1-2 天
- 新手友好度
- 69/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- ios, react-native, swift, typescript
研究方向
Start at the iOS PagerViewProvider path that forwards onPageSelected and inspect how it handles focus when the selected page changes. Compare with the Android fix in #1155, which clears focus outside the selected page and hides the keyboard. Reproduce with the provided two-page TextInput example using setPage and a swipe; done when leaving a page blurs its input and the keyboard follows.
由索引模型根據 Issue 內容生成。
描述
Environment
- react-native-pager-view: 9.0.9 (also present in 9.0.8)
- React Native: 0.88, New Architecture
- Xcode 27, iOS 27.0 simulator (iPhone 18 Pro)
- iOS only. The Android half of this was fixed in #1155 and shipped in 9.0.8.
Description
This is the iOS half of #1154, which was fixed for Android only.
A TextInput that's focused on one page stays focused after you switch to another page, whether with setPage or a swipe. The keyboard stays open, nothing on the page you land on is focused, and typing still goes into the input that's now off-screen, so the user edits a field they can't see.
The iOS implementation never touches focus. PagerViewProvider forwards onPageSelected and leaves the first responder alone, and SwiftUI's paged TabView keeps the neighbouring pages in the view hierarchy, so the input that was left behind holds the first responder and the keyboard with it.
keyboardDismissMode doesn't cover this. It defaults to none, and even on-drag only reacts to a drag, so setPage never dismisses. Dismissing the keyboard is also not the same as blurring, which is what leaves keystrokes going into the off-screen field.
Android behaved the same way until #1155, which clears focus held outside the selected page when a page is selected, and hides the keyboard explicitly. The two platforms disagree today: the same code blurs on Android 9.0.8 and keeps focus on iOS.
Expected: leaving a page blurs an input focused on it and the keyboard follows, as it now does on Android.
Actual: the input keeps focus, the keyboard stays open, and keystrokes go to the off-screen page.
Here is the moment it goes wrong, with a status line showing the selected page, the focused input and the keyboard: the pager is on page 0, while page 1's input still holds focus and the keyboard.
Found in Expensify/App#101157, where a pager hosts a form on each tab.
Reproducible Demo
import { useRef } from 'react';
import { Button, StyleSheet, TextInput, View } from 'react-native';
import PagerView from 'react-native-pager-view';
export function Repro() {
const ref = useRef<PagerView>(null);
return (
<PagerView ref={ref} style={StyleSheet.absoluteFill} initialPage={0}>
{[0, 1].map((page) => (
<View key={page} style={{ flex: 1, padding: 24, gap: 12 }}>
<TextInput placeholder={`Input ${page}`} style={{ borderWidth: 1, padding: 12 }} />
<Button title={`Go to page ${1 - page}`} onPress={() => ref.current?.setPage(1 - page)} />
</View>
))}
</PagerView>
);
}
- Focus
Input 1on page 1 and wait for the keyboard. - Tap Go to page 0, or swipe back to page 0.
- Type.
The keyboard never closes, and the characters land in Input 1 while page 0 is on screen. Swipe back and you'll find the text in the input you couldn't see.
- 主要語言
- TypeScript
- 星號
- 3.4k
- 分支
- 488
- 平均合併
- 2 天 3 小時
- 30 天內合併 PR
- 28
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
callstack/react-native-pager-view 的其他 Issue
-
難度 4/5 1-2 天 新手友好度 58/100
callstack/react-native-pager-view#1196 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 73/100
callstack/react-native-pager-view#1191 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 58/100
callstack/react-native-pager-view#1189 ·
維護者通常 1 天內回覆
-
iOS: PagerScrollDelegate proxies to itself and overflows the stack when the weak originalDelegate dies可能已有人在做 @lvlrSajjad 於 42 天前認領。 未關閉
難度 4/5 3-5 天 新手友好度 25/100
callstack/react-native-pager-view#1146 ·
維護者通常 1 天內回覆
-
難度 5/5 一週以上 新手友好度 35/100
callstack/react-native-pager-view#1144 · 1 個 reaction ·
維護者通常 1 天內回覆
查看 callstack/react-native-pager-view 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 68/100
awesome-dsh-plugin/awesome-dsh-plugin#9184 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 75/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 85/100
farion1231/cc-switch#8829 ·
維護者通常 1 天內回覆
-
[core-client] Remove unused hand-maintained transport helpers after the definition-table cutover未關閉doc-audit enhancement
難度 2/5 1-3 小時 新手友好度 88/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 85/100