如何在react-native中检测屏幕是否有圆角 [英] How to detect if screen has rounded corners in react-native

查看:40
本文介绍了如何在react-native中检测屏幕是否有圆角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测设备屏幕是否有圆角并估计圆角的半径(如果可能)?

How can I detect whether device screen has rounded corners and also estimate the radius of the corners (if possible) ?

我想修改我的 view 更典型的 cardview 以适应这些屏幕.我已经通过使用 Dimensions

I want to modify my view more typically cardview to adapt these screens. I have successfully retrieved the screen width and height by using Dimensions

width: Dimensions.get('window').width,
height: Dimensions.get('window').height

我无法使用上述方法根据 4 个角的曲线调整我的父视图.如果我为父视图提供静态半径,它会给你带来糟糕的外观&感觉在矩形屏幕上,这是不可接受的.

I am not able to adapt my parent view according to the curves at 4 corners with above approach. If I give static radius to the parent view it give bad look & feel on rectangular screens and it's not acceptable.

我想到的一种方法是生成所有带圆角的设备的列表,并将边框半径仅应用于这些设备.但是,维护列表并与市场上的新人一起调整列表变得更加困难.

One approach I thought of is generate a list of all devices with rounded corners and apply border radius to only these devices. But it's harder to maintain the list and adapt the list with newcomers in the market.

有人可以帮我吗?任何类型的方法或指南都会真正帮助我.提前致谢

Can anyone help me with it ? Any sort of approach or guideline will really help me. Thank you in advance

推荐答案

在苦苦挣扎之后,我找到了一个更简单的解决方案,为什么我不应该在应用程序首先启动时询问用户他/她是否有圆角屏幕时间和稍后在我的应用程序下的设置中提供一个选项,以便在用户需要时进行更改.

After struggling with it, I came with a much easier solution that why shouldn't I ask user whether he/she has rounded cornered screen when the app starts first time and later giving an option in settings under my app to change whenever user wanted.

我将用户的选择存储在本地存储中,并根据该标志修改了我的视图.现在我不必维护所有设备的列表,而是涵盖所有用例.

I stored user's selection in local storage and modified my view based on that flag. Now I don't have to maintain a list of all devices instead it will cover all use cases.

这篇关于如何在react-native中检测屏幕是否有圆角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆