场景:我想要实现如下代码所示的情况。哪里会有:
- 一个多行
TextInput
和其他组件,屏幕将是可滚动的 - 我不希望
TextInput
是可滚动的
问题:在TextInput
中写入一定数量的行后,文本将消失。我仍然可以选择文本并在键盘上获得建议。这就像文本和TextInput
变成了transperant。当TextInput
达到手机屏幕的高度后,就会出现此问题。
这是React Native的一个bug吗?还是我在这里做错了什么?
注意:我使用的是"expo": "~40.0.0"
。此外,下面的代码只是描述情况,而不是实际的代码。
return (
<ScrollView>
<View style={styles.block} />
<View style={styles.block} />
<TextInput
value={content}
onChangeText={setContent}
placeholder="Start writing from here"
multiline
/>
<View style={styles.block} />
<View style={styles.block} />
</ScrollView>
);
const styles = StyleSheet.create({
block: {
height: 200,
backgroundColor: 'blue',
},
});
尝试以下任何解决方案:
- 在TextInput上启用滚动启用
- 显式设置TextInput的高度(例如,通过动态测量内容(
<ScrollView scrollEnabled style={{ marginTop: 100 }}> <TextInput multiline placeholder="type here" scrollEnabled={true} /> </ScrollView>