22

I have the following stripped down render result:

return (
  <View style={{backgroundColor:'red'}}>
    <TextInput value={'Hello'}/>
  </View>
);

The generated TextInput is not visible in iOS, unless I specify the height, and when using flexDirection:'row' in its container, I need to specify its width as well.

This only happens with iOS, Android seems to work as expected.

Is there a way of displaying a TextInput in iOS without fixed size?

Current dependencies:

  "dependencies": {
    "react-native": "=0.18.1",
    "react-native-orientation": "=1.12.2",
    "react-native-vector-icons": "=1.1.0"
  },

iOS:

enter image description here

Android:

enter image description here

Changing the render like this:

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

has the following result:

iOS:

enter image description here

Android:

enter image description here

Giannis
  • 5,286
  • 15
  • 58
  • 113

4 Answers4

38

You need to define a height for the textInput. Try:

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

Or, if you do not want to define a height on your TextInput, you can define the height on the containing view, and flex:1 on the TextInput:

<View style={{ height:60 }}>
    <TextInput style={{ flex:1, backgroundColor: '#ededed' }} />
</View>
Nader Dabit
  • 52,483
  • 13
  • 107
  • 91
1

Faced the same issue, but it rendered when I removed alignItems:'center' from the top most parent view in the render() function.

mad_greasemonkey
  • 864
  • 2
  • 15
  • 32
1

Use style={{ color: 'black' }}.

This solves the problem.

KetZoomer
  • 2,701
  • 3
  • 15
  • 43
0

when we use an TextInput in react-native the TextInput will not expand to fill the space available to it by default instead we have to add style rule that how big the TextInput should be.if your not add style for TextInput with height you cant appear the TextInput

Dulanga Heshan
  • 1,335
  • 1
  • 19
  • 36