[英]React-Native ScrollView makes TextInput vanish
Being pretty new to React Native, hopefully this is an obvious oversight, but I've experimented and not found a solution. 作为React Native的新手,希望这是一个明显的疏忽,但是我已经尝试过并且没有找到解决方案。 It's a pretty straightforward problem: when I have a couple of Views and a TextInput, everything lays out as expected. 这是一个非常简单的问题:当我有几个Views和一个TextInput时,一切都按预期布置。 When I wrap them in a ScrollView, the Views remain but the TextInput no longer renders. 当我将它们包装在ScrollView中时,Views仍然保留,但TextInput不再呈现。 I have not been able to figure out why. 我一直无法弄清楚为什么。
To test and share it I created an rnplay app here: https://rnplay.org/apps/P774EQ 为了测试和共享它,我在这里创建了一个rnplay应用程序: https ://rnplay.org/apps/P774EQ
As you can see, the text in the Views wrapping the TextInput appear as expected, but the TextInput isn't there. 如您所见,包装了TextInput的视图中的文本按预期显示,但TextInput不存在。 If you just remove the ScrollView (lines 18 & 39), the TextInput appears. 如果仅删除ScrollView(第18和39行),则将显示TextInput。
Hopefully someone experienced will look at this and have an answer in a few seconds because I'm pretty sure I'm just missing something obvious. 希望有经验的人可以看一下并在几秒钟内得到答案,因为我敢肯定我只是缺少明显的东西。 Thanks in advance. 提前致谢。
1) Line17: style={styles.scrollview}
=> style={styles.scrollView}
, you have a spell mistake. 1)第17行: style={styles.scrollview}
=> style={styles.scrollView}
,您遇到拼写错误。
2) Use contentContainerStyle
for ScrollView ( for more details about contentContainerStyle ) 2)将contentContainerStyle
用于ScrollView( 有关contentContainerStyle的更多详细信息 )
<ScrollView keyboardDismissMode='interactive' style={styles.scrollview} contentContainerStyle={styles.contentContainerStyle}>
and here is the contentContainerStyle: 这是contentContainerStyle:
contentContainerStyle: {
flex: 1,
}
3) The flex
property of message
style is better to set as .125
because the flex
of inputcontainer
is .75
. 3)最好将message
样式的flex
属性设置为.125
因为inputcontainer
的flex
为.75
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.