棉布错误在设置样式时重复键
设置我的样式时,如何避免重复键或嵌套三元?我需要更改iOS和某些iPhone的利润。
import DeviceInfo from 'react-native-device-info';
const devices = ['iPhone 12', 'iPhone 12 Pro', 'iPhone 12 Pro Max'];
const styles = StyleSheet.create({
container: {
flexDirection: 'row',
paddingHorizontal: 20,
paddingTop: 10,
marginBottom: Platform.OS === "ios" ? 10 : 0;,
marginBottom: devices.includes(DeviceInfo.getModel()) ? 30 : 0
},
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
怎么样。
marginbottom :( platform.os ===“ ios”&& 10)|| (设备。包括(deviceInfo.getModel()&& 30)|| 0;
它可能不完全适合您想要的东西,但是有了一点修改,应该有可能。
How about this.
marginBottom: (Platform.OS === "ios" && 10) || (devices.includes(DeviceInfo.getModel() && 30 ) || 0;
It may not perfectly fit what you want, but with a little modification it should be possible.
如果您的衬里不允许使用嵌套操作员,您可以定义一个持有数据的变量:
因为该值将始终为
0
for non-ios,30
如果在设备
和10
中包含,则您的逻辑可以看起来像:If your linter does not allow the use of a nested ternary operator, you can define a variable holding the data:
Since the value will always be
0
for non-ios,30
if included indevices
and10
otherwise, your logic can look something like: