Я пытаюсь остановить фокусирование, распространяющееся от последнего элемента в React Native, используя nextFocusRight, но все же фокус распространяется на следующий вид. Согласно этому запросу pull , он должен работать, но, тем не менее, я столкнулся с той же проблемой
Мой код:
App.js
export default class App extends Component {
render() {
const data = [];
for (let i = 0; i < 10; i++)
data.push(i);
return (
<View>
<View>
{[1, 2].map(() => (
<ScrollView horizontal style={{ height: 210 }}>
{data.map(i => <Item id={i} buttonRef={this.buttonRef} />)}
</ScrollView>
))}
</View>
</View>
);
}
}
Item.js
export default class Item extends Component {
myRef = null;
componentDidMount() {
const { id } = this.props;
if (id == 0) {
this.myRef.setNativeProps({ nextFocusLeft: findNodeHandle(this.myRef) })
} else if (id == 9) {
this.myRef.setNativeProps({ nextFocusRight: findNodeHandle(this.myRef) })
}
}
render() {
const { id } = this.props;
return (
<TouchableOpacity
key={id}
ref={(c) => this.myRef = c}
>
<View
style={{
backgroundColor: 'grey',
width: 100,
height: 100,
}}
>
<Text style={{ fontSize: 60 }}>{id}</Text>
</View>
</TouchableOpacity>
)
}
}
Что здесь не так? Кто-нибудь знает?