简体   繁体   English

反应本机多行,值,小于TextInput组件中的占位符

[英]React Native multiline, value, smaller than placeholder in TextInput component

When adding text into a <TextInput> component with multiline set to false the value text matches the placeholder text font size, whereas if multiline is equal to true , the value text font size is smaller than the placeholder font size. multiline设置为false<TextInput>组件中添加文本时, value文本与placeholder文本字体大小匹配,而如果multiline等于true ,则value文本字体大小小于placeholder字体大小。

Is this a normal behaviour or a bug? 这是正常行为还是错误?

问题

Edit: 编辑:

/* @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>
        )
    }
}

As far as I see, the default font size is actually different for multiline and non-multiline TextInput -s. 据我所知,多行和非多行TextInput -s的默认字体大小实际上是不同的。 One way to handle this is by introducing another component which acts as an abstraction on top of TextInput : 解决此问题的一种方法是通过引入另一个充当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 ]} /> ) } } 

Now you can just use AppTextInput the same way TextInput is supposed to be used, and all issues related to styling inputs are covered in a single place. 现在,您可以AppTextInput假定使用TextInput一样使用AppTextInput ,并且与样式输入有关的所有问题都可以在一个地方找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM