简体   繁体   English

反应本机 <Text> 没有包裹在内部弯曲

[英]React-native <Text> not wrapped in inner flex

First some pseudo code: 首先是一些伪代码:

render(){
    return(
        <View style={{flexDirection:'row', flexWrap:'wrap'}}>
            <View style={{flexDirection:'column', flexWrap:'wrap'}}>
                <View style={{flexDirection:'row', flexWrap:'wrap', flexShrink:1}}>
                    <Text>azeaeazeazeazeazeazeazearzetareutaeriauzertaiueyrtaieuyrtaieyrtaieuyrtaieuyrtaieuzyrt</Text>
                </View>
            </View>
            <View style={{borderWidth:1}}/>
            <View style={{flexDirection:'column', flexWrap:'wrap'}}>
                <Text>azeaeazeazeazeazeazeazearzetareutaeriauzertaiueyrtaieuyrtaieyrtaieuyrtaieuyrtaieuzyrt</Text>
            </View>
        </View>
    )
}

What I want is to have my screen split and that the text gets wrapped on both sides. 我想要的是分割屏幕,并使文本两边都换行。

What happens is the first textis written on one line (so it gets off the screen), to its right is the "borderWidth:1" and next line is the second text, overflowing 发生的情况是第一行文本写在一行上(因此它离开了屏幕),其右边是“ borderWidth:1”,下一行是第二行文本,溢出

The final goal is a sign form which displays correctly as long as I don't put it in a "flexDirection:row" view, which I need to since I want both forms side by side (and up and down for responsive if on mobile) 最终目标是一个符号形式,只要我不将其放置在“ flexDirection:row”视图中,它就可以正确显示,这是我需要的,因为我希望两种形式都可以并排(如果在移动设备上,则上下响应) )

Any hint ? 有什么提示吗?

By the way the correctly displaying form is set like this : 顺便说一下,正确显示的表单设置如下:

render(){
    return(

            <View style={{justifyContent: "flex-start", alignItems: "stretch", minWidth:wp(10)}}>
                <View style={{flexWrap:'wrap', flexShrink:1}}>
                    <Text style={{textAlign:'center'}}>Create your WaitForMe account.</Text>
                    <Text style={{textAlign:'center'}}>It’s free and only takes a minute.</Text>
                    <Text style={{fontWeight:'bold', margin: 2}}>Email</Text>
                    <TextInput style={{borderWidth: 1, margin: 2}} placeholder="E-mail address" onChangeText={(mail) => this.setState({mail})} onBlur={()=>this.validateSignUpForm()}/>
                    <Text style={{color:'red', margin: 2}}>{this.state.errors.mail}</Text>
                    <Text style={{fontWeight:'bold', margin: 2}}>Password</Text>
                    <TextInput style={{borderWidth: 1, margin: 2}} placeholder="Password" onChangeText={(password) => this.setState({password})} onBlur={()=>this.validateSignUpForm()}/>
                    <Text style={{color:'red', margin: 2}}>{this.state.errors.password}</Text>
                    <Text style={{margin:2, flexShrink:1}}>Passwords must be at least 8 characters long and contain at least 1 letter, 1 number and a special character</Text>
                    <Text style={{fontWeight:'bold', margin: 2}}>Confirm password</Text>
                    <TextInput style={{borderWidth: 1, margin: 2}} placeholder="Confirm password" onChangeText={(confirm) => this.setState({confirm})} onBlur={()=>this.validateSignUpForm()}/>
                    <Text style={{color:'red', margin: 2}}>{this.state.errors.confirm}</Text>
                </View>
                <Button title="Sign up" onPress={()=>this.signUp()} disabled={this.state.signUpDisabled}/>
            </View>
    )
}

Correct behaviour: large screen: 正确的行为:大屏幕: 在此处输入图片说明 small screen: 小屏幕: 在此处输入图片说明

Bad behaviour (when put inside a flexDirection:'row' 不良行为(当放置在flexDirection中时:'row'

small screen cropped: 小屏幕裁剪: 在此处输入图片说明

you should be specifying display: 'flex' in your parent component(s). 您应该在父组件中指定display: 'flex' This is the only way its children will be treated as flex items. 这是将其子项视为弹性项的唯一方法。

Your "good" examples are just working out of coincidence. 您的“好”例子只是巧合。 https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox#The_flex_container https://developer.mozilla.org/zh-CN/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox#The_flex_container

here's some pseudocode so you knwow ht 这是一些伪代码,所以您知道

<View style={{ display: 'flex', flexDirection: 'column' }}>
    <View style={{ display: 'flex', flex: 5 }}>                   
        <Text style={{ flex: 1, flexWrap:'wrap', flexShrink:1 }}></Text>
        <Text style={{ flex: 1, flexWrap:'wrap', flexShrink:1 }}></Text>
        <Text style={{ flex: 1 }}></Text>
        <TextInput style={{ flex: 3 }}/>
        <Text style={{ flex: 1, flexWrap:'wrap', flexShrink:1 }}></Text>
    </View>
    <Button style={{ flex: 1 }} />
</View>

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

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