响应本机响应视图Iphone x

时间:2019-01-27 14:13:19

标签: ios react-native responsive-design-view

在为Iphone X样式时,我遇到了一个小问题,我使用了来自react-native-response-screen的widthPercentageToDP和heightPercentageToDP来使视图相似,除了Iphone X以外,在大多数运行良好的设备中,它都工作得很好有点,但我想使视图尽可能准确。

  <View style={styles.container}>
                <ImageBackground source={require('../../assets/acc.png')} style={styles.bgImg}>
                    <View style={styles.headerView}>
                    <FontAwesome style={styles.setting}  name="cog" size={hp('4%')} color="#6B6466" />
                    <Text style={styles.headerText}>My Account</Text>
                    </View >

                    <View style={styles.imgView} >
                        <Image source={require('../../assets/user.png')} style={styles.accImg}/>
                        <Text style={styles.name}> John doe</Text>
                        <Text style={styles.number}> 123456789</Text>
                    </View>
                    <View style={styles.bottomView}>
                    <View style={styles.bottomView2}>

                        <TouchableOpacity style={styles.inboxView}>
                            <Text style={styles.inboxNumber}>12</Text>
                            <Text style={styles.inboxText}>Inbox</Text>
                        </TouchableOpacity>
                        <TouchableOpacity style={styles.inboxView}>
                            <Text style={styles.inboxNumber}>17</Text>
                            <Text style={styles.inboxText}>Sent</Text>
                        </TouchableOpacity>
                    </View>
                    </View>
                </ImageBackground>
            </View>

样式

const styles = StyleSheet.create({
    container: {
        flex: 1, backgroundColor: '#fff'
    },
    bgImg:{
        height: hp('40%'), width: '100%'
    },
    setting:{
        color:'white'
    },
    headerText:{
        flex:1,textAlign:'center',fontSize:wp('5%'),fontFamily:Fonts.Cairo,marginRight:10,color:'white'
    },
    headerView:{
        flexDirection:'row',justifyContent:'space-between',marginHorizontal:10,marginTop:hp('5%')
    },
    imgView:{
        flex:1,
        alignItems:'center'
    },
    accImg:{
        height:wp('30%'),width:wp('30%'),borderRadius:wp('15%'),marginTop:wp('3%')
    },
    name:{
        color:'white',fontFamily:Fonts.Cairo,fontSize:wp('4%'),textAlign:'center'
    },
    number:{
        color:'white',fontSize:wp('4%'),textAlign:'center'
    },
    bottomView:{
        flex:1,
        justifyContent:'flex-end'
    },
    inboxNumber:{
        color:'white',
        textAlign:'center',
        fontSize:wp('4%')
    },
    inboxText:{
        color:'white',
        textAlign:'center',
        fontSize:wp('4%'),
        fontFamily:Fonts.Cairo
    }, 
    bottomView2:{
        flexDirection:'row',
        justifyContent:'space-between',
        marginHorizontal:10,
        marginBottom:wp('3%')
    },

});

输出 enter image description here

1 个答案:

答案 0 :(得分:0)

Iphone X正在渲染真实的结果,这就是您的布局的样子,其他设备没有足够的渲染空间,它们“重叠”了视图...看您的视图,您有imagebackground wich占据了屏幕的40%,在您的头中,header wich将正常渲染,因为它在render函数中更高。

下面有一个具有flex:1的视图,并且在一个图像内,该图像具有基于屏幕的值,下面有2行文本,如果该图像比该视图大,则会将文本推到该视图之外,从而侵入下面的邻居视图

下面有2个touchableopacitys的视图。它们不应重叠。实际上,请尝试将overflow:'hidden'添加到imgView样式

------标题------

//////// IMAGE ////////

//////// IMAGE ////////

//////// Johndo ///////

//////// 12345 ////////

按钮//////按钮

就像iphone正在显示

<ImageBackground source={require('../../assets/acc.png')} style={styles.bgImg}>
                    <View style={styles.headerView}>
                    //here is the header
                    </View >

                    <View style={styles.imgView} >
                       // below is the image , the name , and the number
                    </View>
                    <View style={styles.bottomView}>
                    //below it should be the 2 buttons , not overlapping, BELOW
                    </View>
                </ImageBackground>