Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-native TextInput displays wrong when changing height on Android

I have a TextInput with the following style:

amountInput: {
  flex: 1,
  backgroundColor: 'rgba(255, 255, 255, 0.1)',
  color: 'rgba(255, 255, 255, 0.9)',
},

On iOS it correctly looks like it doesn't have enough padding:

enter image description here

On Android is has enormous padding by default:

enter image description here

Not a problem - I'll set a right and left padding, and a height:

amountInput: {
  flex: 1,
  backgroundColor: 'rgba(255, 255, 255, 0.1)',
  height: 30,
  paddingRight: 5,
  paddingLeft: 5,
  color: 'rgba(255, 255, 255, 0.9)',
}

Looks good on iOS:

enter image description here

But Android messes up:

enter image description here

How can I make an Android input box like the penultimate iOS screenshot? Thanks.

like image 643
Dominic Avatar asked Jun 17 '16 09:06

Dominic


People also ask

How do I change the height of TextInput in react native?

Firstly Let's import React Native default TextInput to our code. Inside our component state we will define two properties value & height. value to hold our TextInput value & height to control our TextInput height.

How do I clear the TextInput value in react native?

Add the method submitAndClear to our class and set the <button /> component's onPress prop to this. submitAndClear. Change the <button /> component's title prop to the string 'Submit' Add the prop clearButtonMode='always' to the <TextInput /> component — this will give us an option to clear the text at any time.

What is TextInput in React Native?

TextInput is a Core Component that allows the user to enter text. It has an onChangeText prop that takes a function to be called every time the text changed, and an onSubmitEditing prop that takes a function to be called when the text is submitted.

How do I disable react native TextInput?

Use caretHidden={true} if you want to disable all operation like Cut Paste Copy. It will also hide your cursor as well.


1 Answers

Android adds some default padding on top and bottom, you can reset them by adding paddingVertical: 0 to your element' style.

like image 65
Ivan Chernykh Avatar answered Nov 13 '22 11:11

Ivan Chernykh