Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextInput Alignment Not Centered iOS React-Native

Tags:

react-native

Why does iOS not center the text input control? I am including the render and stylesheet code:

left android, right ios

render() {
  return (

  <View style={styles.container}>
    <TextInput
           style={styles.input}
           onChangeText={(text) => this.setState({text})}
           underlineColorAndroid='rgba(0,0,0,0)'
           value={this.state.text}
           placeholder= 'username'
           />
  </View>
)
}


  const styles = StyleSheet.create({
  container: {
  flex: 1,
  justifyContent: 'center',
  alignItems: 'center',
  backgroundColor: '#13493A'
}

 input: {
   height: 40,
   width: 250,
   borderRadius: 5,
   backgroundColor: '#598176',
   color: 'white',
   marginTop: 30,
   textAlign: 'center'
  }
});

Thank you in advance, Anthonie

like image 872
Anthonie Avatar asked Oct 24 '25 21:10

Anthonie


1 Answers

Looking on the issue tracker, this appears to be a bug in React Native on iOS: #11892 So your code should work but doesn't. There is a listed workaround which is to add alignSelf: 'center' to the TextInput's styles (see example).

like image 137
Michael Cheng Avatar answered Oct 27 '25 10:10

Michael Cheng