1 - In your case, styles are a StyleSheet object.
You need to use the StyleSheet.flatten function as shown below:
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF'
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
var styleObj = StyleSheet.flatten([styles.container])
console.warn(styleObj.backgroundColor==='#F5FCFF') //=>true
2 - handle the component style:
var flattenStyle = require('flattenStyle');
var backgroundColor = flattenStyle(this.props.style).backgroundColor;
More details here:
https://facebook.imtqy.com/react-native/docs/stylesheet.html
and
fooobar.com/questions/624914 / ...
source
share