ReactNative TextInput不可见iOS

Gia*_*nis 18 ios react-native

我有以下剥离渲染结果:

return (
  <View style={{backgroundColor:'red'}}>
    <TextInput value={'Hello'}/>
  </View>
);
Run Code Online (Sandbox Code Playgroud)

生成的TextInput在iOS中不可见,除非我指定高度,并且当在其容器中使用flexDirection:'row'时,我还需要指定其宽度.

这只发生在iOS上,Android似乎按预期工作.

有没有一种在没有固定大小的iOS中显示TextInput的方法?

当前依赖关系:

  "dependencies": {
    "react-native": "=0.18.1",
    "react-native-orientation": "=1.12.2",
    "react-native-vector-icons": "=1.1.0"
  },
Run Code Online (Sandbox Code Playgroud)

iOS版:

在此输入图像描述

安卓:

在此输入图像描述

像这样更改渲染:

return (
  <View style={{backgroundColor:'red'}}>
    <Text>text</Text>
    <TextInput value={'Hello'}/>
  </View>
);
Run Code Online (Sandbox Code Playgroud)

有以下结果:

iOS版:

在此输入图像描述

安卓:

在此输入图像描述

Nad*_*bit 31

您需要为textInput定义高度.尝试:

return (
  <View style={{backgroundColor:'red'}}>
    <Text>text</Text>
    <TextInput style={{ backgroundColor: '#ededed', height: 60 }} value={'Hello'}/>
  </View>
);
Run Code Online (Sandbox Code Playgroud)

或者,如果您不想在TextInput上定义高度,则可以在包含视图上定义高度,并在TextInput上定义flex:1:

<View style={{ height:60 }}>
    <TextInput style={{ flex:1, backgroundColor: '#ededed' }} />
</View>
Run Code Online (Sandbox Code Playgroud)