React-Native文本输入框防止滚动

5

我有一个使用React Native编写的屏幕,其中包含单行TextInput:

<ScrollView>
    ...
    <TextInput />
    ...
</ScrollView>

当我尝试滚动屏幕,而我的初始点击落在TextInput上时,屏幕滚动不起作用。它几乎试图在TextInput内滚动,但没有任何内容可以滚动。这是TextInput的样子:

<TextInput
    style={{...styles.rowInput, color: theme.textColor}}
    onChangeText={(text) => this.setState({name: text})}
    selectTextOnFocus={false}
    autoCapitalize="words"
    numberOfLines={1}
    underlineColorAndroid="transparent"
    autoCorrect={false}
    placeholder="Enter Your Name"
    placeholderTextColor={borderColor}
    maxLength={24} />

有什么想法是为什么这种情况会发生?

可以添加你自己的样式。rowInput - Gaudam Thiyagarajan
你能解决这个问题吗?我也遇到了同样的问题! - froston
1个回答

0

这与ScrollView有关,您可以通过将keyboardShouldPersistTaps设置为“Handled”来解决此问题。请尝试此方法。

<ScrollView
    keyboardShouldPersistTaps={'handled'}>
        ...
        <TextInput />
        ...
</ScrollView>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接