3.4 Inheritance
1.pass styles as props
class InheritanceStyle extends Component {
render() {
return (
<View style={this.props.parentColor}>
</View>
);
}
}
class Main extends Component {
handleReady(str){
console.log(str);
}
render() {
return (
<View style={styles.container}>
<InheritanceStyle parentColor={styles.blue}/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1
},
blue: {
flex: 1,
backgroundColor: 'blue'
}
});
2.concatenation styles
BaseStyles.js
import { StyleSheet,Dimensions } from 'react-native';
let winSize = Dimensions.get('window');
const BaseStyles = StyleSheet.create({
text: {
fontSize: 40/winSize.scale
}
});
export default BaseStyles;
import BaseStyles from './BaseStyles';
class InheritanceStyle extends Component {
render() {
return (
<View style={this.props.parentColor}>
<Text style={[BaseStyles.text, styles.text]}> this is a long text </Text>
</View>
);
}
}
const styles = StyleSheet.create({
text:{
color: '#ffffff'
}
});