![](/img/trans.png)
[英]Minimal height of multiline adjustable reusable React-Native TextInput component
[英]React Native multiline, value, smaller than placeholder in TextInput component
將multiline
設置為false
的<TextInput>
組件中添加文本時, value
文本與placeholder
文本字體大小匹配,而如果multiline
等於true
,則value
文本字體大小小於placeholder
字體大小。
這是正常行為還是錯誤?
編輯:
/* @flow */
import React from 'react'
import Separator from './components/Separator'
import {Button, StyleSheet, TextInput, View} from 'react-native'
const styles = StyleSheet.create({
subject: {
height: 20,
},
body: {
height: 100,
},
})
export default class NewQuestion extends React.Component {
static navigationOptions = ({navigation}) => ({
title: 'AIBU',
headerLeft: (
<Button
onPress={() => {
navigation.goBack()
}}
title="Back"
/>
),
})
state = {
subject: '',
body: '',
}
render() {
return (
<View>
<TextInput
autoFocus
onChangeText={subject => this.setState({subject})}
placeholder="Enter your AIBU subject..."
style={styles.subject}
value={this.state.subject}
/>
<Separator />
<TextInput
multiline
onChangeText={body => this.setState({body})}
placeholder="Enter your AIBU description..."
style={styles.body}
value={this.state.body}
/>
</View>
)
}
}
據我所知,多行和非多行TextInput
-s的默認字體大小實際上是不同的。 解決此問題的一種方法是通過引入另一個充當TextInput
之上的抽象的TextInput
:
const styles = StyleSheet.create({ text: { fontFamily: 'System', fontStyle: 'normal', fontSize: 20, lineHeight: 20, letterSpacing: 0.6 } }) export default class AppTextInput extends Component { static propTypes = { style: TextInput.propTypes.style } static defaultProps = { style: {} } render() { return ( <TextInput {...this.props} style={[ styles.text, this.props.style ]} /> ) } }
現在,您可以AppTextInput
假定使用TextInput
一樣使用AppTextInput
,並且與樣式輸入有關的所有問題都可以在一個地方找到。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.