关于javascript:numberOfLines TextInput属性不起作用

numberOfLines TextInput property not working

我已经在react-native中创建了一个应用程序,并且可以选择在消息中聊天选项。当我在TextInput内单击并键入两行时,上面的行被隐藏了。为了解决这个问题,我在docs numberOfLines属性中看到了它,但是它不起作用。

这是我的代码:

1
2
3
4
5
6
7
8
9
10
<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}/>

我也在getDefaultProps函数中尝试过它:

1
2
3
4
5
6
7
8
9
getDefaultProps() {
    return {
      placeholder: 'Type a message...',
      navHeight: 70,
      textInputHeight: 44,
      numberOfLines:5,
      maxHeight: Screen.height,
    };
  },

但是没有用。


要恢复:

1
2
3
4
5
<TextInput
  ...
  numberOfLines={Platform.OS === 'ios' ? null : numberOfLines}
  minHeight={(Platform.OS === 'ios' && numberOfLines) ? (20 * numberOfLines) : null}
/>


您可以使用maxHeightminHeight接受您想要的内容。对于标准文本fontSize,给出maxHeight={60}将使TextInput在3行之后可滚动。这对IOS很有用-对于Android,您可以使用numberOfLines属性。


您有numberOfLines: {5},应为numberOfLines={5}。还是仅在SO中出现错字?

此外,还建议设置样式textAlignVertical: 'top'


您应该设置maxHeight。我确实设置了maxHeight={70}