ScrollView doesn't scroll to focused element
未关闭
还没有人认领这个 Issue。
Component: ScrollView
Help Wanted :octocat:
Needs: Attention
Newer Patch Available
Platform: Android
- 主要语言
- C++
- 星标
- 127k
- 派生
- 25.3k
- 平均合并
- 1 天 23 小时
- 30 天内合并 PR
- 4
描述
Environment
Android API: 28
Device: AndroidTV emulator and Xiaomi MI BOX
React Native: 0.61.5
Description
Sometimes ScrollView doesn't scroll to currently focused element on AndroidTV devices. Looks like issue is triggered because of two scroll events, one from ReactScrollView.java arrowScroll method and one from requestChildFocus. Issue seems to occur only when scrolling on the bottom of ScrollView.
React Native version:
"0.61.5"
Steps To Reproduce
- Navigate with keyboard/remote controller up and down on between last rows of ScrollView.
Expected Results
Scroll follows focused element
Snack, code example, screenshot, or link to a repository:
App.ts example:
import React from 'react';
import {View, StyleProp, TextStyle, ViewStyle, TouchableOpacity, ScrollView, Text} from 'react-native';
const styles: {[name: string]: StyleProp<ViewStyle> | StyleProp<TextStyle>} = {
container: {
position: 'absolute',
width: '100%',
height: '100%',
backgroundColor: '#000',
justifyContent: 'flex-end',
alignContent: 'center'
}
};
const rows = [1,2,3,4,5,6,7,8,9];
const columns = ['a', 'b', 'c', 'd', 'e', 'f'];
type Props = {
text: string;
number: number;
}
const MyButton = (props: Props) => {
return (
<TouchableOpacity
style={{width: 200, height: 200, margin: 50, backgroundColor: `rgba(100,255,0,0.3)`}}
key={props.text + props.number}
onPress={() => {}}
>
<Text>{props.text + props.number}</Text>
</TouchableOpacity>
);
};
const App = () => {
return (
<View style={styles.container}>
<ScrollView>
{rows.map((number) => (
<ScrollView
horizontal={true}
key={'scrollview' + number}
>
{columns.map((text) => <MyButton text={text} number={number} key={text + number} />)}
</ScrollView>
))
}
</ScrollView>
</View>
);
};
export default App;
In gif below i navigated up and down only:

贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 ReactScrollView.java 开始,尤其关注报告中描述的 arrowScroll 和 requestChildFocus 方法。使用提供的 App.ts 示例,在 AndroidTV 模拟器或 Xiaomi MI BOX 上通过在最后几行之间移动来复现该问题。完成的标准是:在底部附近上下移动时,ScrollView 始终跟随获得焦点的元素。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- android, react-native
- 领域
- mobile
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100