React-native <View> 组件的 "elevation" 样式导致丑陋的阴影
React-native <View> component's "elevation" style is causing ugly shadows
海拔样式属性为 Android 5.0+ 启用框阴影。
我是否在此处对 'elevation' 做了一些不寻常的事情,以导致在下面的屏幕截图中可以看到的丑陋之处?另外,有什么方法可以定义阴影偏移量吗?
模拟器是运行 6.0 (> 5.0),所以这不是问题所在。我是 运行 react-native 25.1.
"dependencies": {
"react": "^0.14.8",
"react-native": "^0.25.1",
"react-native-gcm-android": "^0.2.0",
"react-native-material-design": "^0.3.5",
"react-native-system-notification": "^0.1.10",
"react-redux": "^4.4.5",
"redux": "^3.5.2"
}
Here's react-native's documentation for View component styling
这是我的渲染方法:
render() {
return (
<ListView
dataSource={alertData}
renderRow={(rowData) =>
<View style={style.cardContainer}>
<Text>{rowData.blah}</Text>
<Text>{"#" + rowData.foo}</Text>
<Text>{rowData.blah}</Text>
<Text>{rowData.foo}</Text>
<Text>{rowData.baz}</Text>
</View>
}
/>
);
}
以及样式声明:
var style = StyleSheet.create({
cardContainer : {
elevation : 3,
flex : 1,
margin : 10,
padding : 10,
borderWidth : 2,
borderColor : beeStyles.colors.lightGray
}
});
不知何故导致了这个...
缺少的部分是 backgroundColor。向 View 容器添加 backgroundColor : '<anything>'
样式使那些奇怪的内部阴影消失。
您可以添加背景颜色:backgroundColor : '#000';
一个很好用的组件:
import React from 'react'
import { View, StyleSheet, ViewPropTypes } from 'react-native'
import PropTypes from 'prop-types'
const SingleSidedShadowCard = ({ children, style }) => (
<View style={[ styles.container, style ]}>
{ children }
</View>
);
const styles = StyleSheet.create({
container:{
overflow: 'hidden',
paddingBottom: 5,
}
});
SingleSidedShadowCard.propTypes = {
children: PropTypes.element,
style: ViewPropTypes.style,
};
export default SingleSidedShadowCard;
海拔样式属性为 Android 5.0+ 启用框阴影。
我是否在此处对 'elevation' 做了一些不寻常的事情,以导致在下面的屏幕截图中可以看到的丑陋之处?另外,有什么方法可以定义阴影偏移量吗?
模拟器是运行 6.0 (> 5.0),所以这不是问题所在。我是 运行 react-native 25.1.
"dependencies": {
"react": "^0.14.8",
"react-native": "^0.25.1",
"react-native-gcm-android": "^0.2.0",
"react-native-material-design": "^0.3.5",
"react-native-system-notification": "^0.1.10",
"react-redux": "^4.4.5",
"redux": "^3.5.2"
}
Here's react-native's documentation for View component styling
这是我的渲染方法:
render() {
return (
<ListView
dataSource={alertData}
renderRow={(rowData) =>
<View style={style.cardContainer}>
<Text>{rowData.blah}</Text>
<Text>{"#" + rowData.foo}</Text>
<Text>{rowData.blah}</Text>
<Text>{rowData.foo}</Text>
<Text>{rowData.baz}</Text>
</View>
}
/>
);
}
以及样式声明:
var style = StyleSheet.create({
cardContainer : {
elevation : 3,
flex : 1,
margin : 10,
padding : 10,
borderWidth : 2,
borderColor : beeStyles.colors.lightGray
}
});
不知何故导致了这个...
缺少的部分是 backgroundColor。向 View 容器添加 backgroundColor : '<anything>'
样式使那些奇怪的内部阴影消失。
您可以添加背景颜色:backgroundColor : '#000';
一个很好用的组件:
import React from 'react'
import { View, StyleSheet, ViewPropTypes } from 'react-native'
import PropTypes from 'prop-types'
const SingleSidedShadowCard = ({ children, style }) => (
<View style={[ styles.container, style ]}>
{ children }
</View>
);
const styles = StyleSheet.create({
container:{
overflow: 'hidden',
paddingBottom: 5,
}
});
SingleSidedShadowCard.propTypes = {
children: PropTypes.element,
style: ViewPropTypes.style,
};
export default SingleSidedShadowCard;