react-native - 反应原生中的 BoxShadow
问题描述
我正在尝试在 react-native 版本 0.59.9 中围绕视图创建一个框阴影
我尝试了“shadowOffSet”和所有阴影属性,但没有用
import React, { Component } from 'react';
import { Text, View, StyleSheet, PixelRatio } from 'react-native';
const styles = {
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#ecf0f1',
},
}
export default class Card extends Component {
render() {
return (
<View style={styles.container}>
<View style={{
borderWidth: 1,
borderRadius: 20,
borderColor: '#ddd',
borderBottomWidth: 0,
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.8,
shadowRadius: 20,
borderWidth: (1 / PixelRatio.getPixelSizeForLayoutSize(1)),
elevation: 1,
justifyContent: 'center',
alignItems: 'center',
overflow: this.props.overflow ? this.props.overflow : 'hidden',
width: 120,
height: 150}}>
<Text>Mine</Text>
</View>
</View>
);
}
}
结果附为截图
https://user-images.githubusercontent.com/14028306/60788321-0a283500-a17a-11e9-841d-5604982783ac.jpg
解决方案
您可以使用 react native box 阴影生成器来获得最佳实践。
https://ethercreative.github.io/react-native-shadow-generator/
推荐阅读
- sql - 这个 Teradata 查询效率低吗?
- python-3.x - 为什么任务计划程序不运行我的 Python 脚本
- javascript - ReactJs中的路由,点击链接后移除/卸载父组件
- java - 什么会启动 Connection evictor 线程以及如何避免这些线程累积?
- prism - Theme-ui/prism 不适用于 gatsbyjs 降价文件
- flutter - Flutter有状态小部件导入找不到功能
- r - 在新列中获取所有 NA [变异]
- java - 是否可以在 java 中使用 RabbitMQ 从配置中创建多个队列和交换?
- python - 玩家在pygame中没有移动
- angular - “typeof ExampleService”类型中缺少属性“save”,但在“ExampleAbstractClassService”类型中是必需的