javascript - 升级到 0.56 后的 React-Native Shadow
问题描述
我已经升级了 react-native 依赖项,并且我的视图的 shadow 属性存在一些奇怪的问题。它为 View 中的每个孩子设置阴影,而不是在它应该在的实际视图上。它只发生在 iOS 上,android 继续工作。
我增加了 shadowOpacity 以了解实际发生的情况,并且如上所述,每个项目都有一个阴影,但不是主容器。
render() {
return (
<View style={styles.taskContainer}>
<TouchableOpacity onPress={this.props.onPress}>
<View style={styles.taskContentContainer}>
<Text style={styles.title}>{this.props.task.title}</Text>
<View row spread style={{ marginTop: 5 }}>
{this.state.profileImgUrl ? (
<FastImage
...
taskContainer: {
marginLeft: 10,
marginRight: 10,
marginTop: 11,
//ios
shadowOpacity: 0.15,
shadowRadius: 4,
shadowOffset: {
height: 1,
width: 0
},
//android
elevation: 2.5,
borderRadius: 5,
borderWidth: 0,
marginBottom: 2
},
解决方案
在尝试提高 Android 性能时,我已经阅读了有关过度绘制的信息,因此我试图通过不对子视图应用任何不必要的背景颜色来减少它。因为父视图已经设置了背景颜色,所以我通过该方法减少了过度绘制。现在问题似乎是新的更新处理带有阴影的视图并且没有(或透明的)背景颜色下降到它们的子视图。
解决方案:
添加"backgroundColor: "white"
到 taskContainer 样式。
推荐阅读
- c# - c# winforms表单边框中带边框颜色的圆角边框
- reactjs - 如何一次从多个 url 获取数据 useffect 和 promise.all
- angular - StackBlitz ngcc 在启用 Ivy 的情况下无法在我的 npm 库上运行
- c# - Xamarin Forms 在 For 循环中使用匿名方法
- c++ - 两个私有嵌套类之间的友谊
- reactjs - 无法在组件中使用挂钩
- swiftui - 在swiftui中使用组合从服务器获取更多数据时如何追加
- arrays - 计算一个数字在随机数组中出现的次数
- c - 不使用 struct 在 C 中显示所有数据
- c++ - 为什么 Visual Studio 试图从 Team Fortress 2 加载 SDL2?