当用户点击 aTextInput内部的 a时ScrollView,后者会自动向下滚动,这样文本字段就不会被键盘覆盖。
虽然这是一种非常有用且确实是可预期的行为,但有什么方法可以防止这种情况发生吗?
我希望ScrollView键盘弹出后保持在完全相同的滚动位置,即使文本字段因此被它覆盖。
这是一个例子:
import React, {Component} from "react";
import {ScrollView, Text, TextInput} from "react-native";
export default class App extends Component {
render() {
return (
<ScrollView style={{flex: 1}}>
{/* Something to fill the screen */}
<Text style={{fontSize: 70}}>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</Text>
{/* TextInput on the keyboard level */}
<TextInput style={{borderWidth: 1}} />
</ScrollView>
);
}
}
Run Code Online (Sandbox Code Playgroud)