Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

numberOfLines TextInput property not working

I have created an application in react-native and I have an option to chat in messages option. when I click inside TextInput and type two lines, the upper line gets hidden. To fix this I saw in the docs numberOfLines property but it did not work.

Here is my code:

<TextInput

                ref='textInput'
                multiline={true}
                numberOfLines: {5}
                onChangeText={this.onChangeText}
                style={[styles.textInput, {height: context.props.textInputHeight}]}
                placeholder={context.props.placeholder}
                placeholderTextColor="#5A5A5A"
                value={context.state.text}/>

I tried it in getDefaultProps function too:

getDefaultProps() {
    return {
      placeholder: 'Type a message...',
      navHeight: 70,
      textInputHeight: 44,
      numberOfLines:5,
      maxHeight: Screen.height,
    };
  },

But did not worked.

like image 330
Ankush Rishi Avatar asked Mar 11 '16 09:03

Ankush Rishi


People also ask

How do you Unfocus TextInput react native?

Wrap the View component that is the parent of the TextInput in a Pressable component and then pass Keyboard. dismiss to the onPress prop. So, if the user taps anywhere outside the TextInput field, it will trigger Keyboard. dismiss , which will result in the TextInput field losing focus and the keyboard being hidden.

How do you increase TextInput height in react native?

We are going to use onContentSizeChange prop provided by TextInput to watch input box for content size changes and accordingly call our updateSize function which will update the height of our TextInput. In our render process we are going to use the height to create anew style to use with our TextInput.

How do I use onSubmitEditing react native?

onSubmitEditing is triggered when you click the text input submit button (keyboard button). onChangeText is triggered when you type any symbol in the text input. In your example, you will achieve what you need in both cases.


2 Answers

To resume:

<TextInput
  ...
  numberOfLines={Platform.OS === 'ios' ? null : numberOfLines}
  minHeight={(Platform.OS === 'ios' && numberOfLines) ? (20 * numberOfLines) : null}
/>
like image 83
Made in Moon Avatar answered Sep 20 '22 09:09

Made in Moon


You can use maxHeight and minHeight to accept what you want. For standard text fontSize, giving maxHeight={60} will make TextInput scrollable after 3 lines. This is good for IOS - for Android you can use numberOfLines prop.

like image 26
David Avatar answered Sep 19 '22 09:09

David