小编jlb*_*lca的帖子

如何防止ScrollView在键盘弹出时自动滚动到聚焦的TextInput?

当用户点击 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)

textinput scrollview react-native

7
推荐指数
1
解决办法
1706
查看次数

标签 统计

react-native ×1

scrollview ×1

textinput ×1