ios - React Native 响应式 View Iphone x

标签 ios react-native responsive-design-view

我在为 Iphone X 设计样式时遇到了一个小问题,我使用了 react-native-responsive-screen 中的 widthPercentageToDP 和 heightPercentageToDP 来使 View 相似,在除 Iphone X 之外的大多数设备上它都能完美运行,区别有点小有点,但我想让 View 尽可能准确。

  <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

最佳答案

Iphone X 正在渲染真实的结果,这就是你的布局的样子,其他设备没有足够的渲染空间,它们“重叠”了 View ......看看你的 View ,你有一个图像背景它占据了屏幕的 40%,里面有一个标题,它会正常呈现,因为它在渲染功能中更高。

下面是一个带有 flex:1 的 View ,在图像内部有基于屏幕的值,下面有 2 行文本,如果图像比 View 大,它会将文本推到 View 之外,侵入下面的相邻 View

在下面,您可以看到带有 2 个 touchableopacity 的 View 。它们不应该重叠。事实上,尝试将 overflow:'hidden' 添加到 imgView 样式

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

///////图片////////

///////图片////////

///////约翰多///////

///////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>

关于ios - React Native 响应式 View Iphone x,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54389044/

相关文章:

React-native --variant 选项

html - 如何使 slider 图像完全响应?

objective-c - 如何将 iPhone 笔记导入我的应用程序?

iphone - iOS 测试驱动开发 : Testing a method that uses UIVIew animateWithDuration:animations:completion:

ios - 覆盖 UIColor 的 isEqual : method within Category

javascript - 使用 Javascript 格式化 NdefFormatable NFC 标签

android - 如何在 React Native(iOS 和 Android)中获取设备的当前国家/地区?

css - 响应式设计和边距

ios - 如何获得屏幕上显示的图像的准确持续时间计时器?