Closed deadcoder0904 closed 6 years ago
What do you think about more "css" approach - use composition of styles instead of override?
// global.js
export default EStyleSheet.create({
button: {
backgroundColor: 'orange',
color: 'white'
}
})
// black-button.js
import globalStyles from './global';
const styles = EStyleSheet.create({
button: {
color: 'black'
}
});
class BlackButton extends React.Component {
render() {
return (
<View style={[globalStyles.button, styles.button]}>
...
</View>
);
}
}
Yep, that can be great too. Idk why I always go the hard way 😂
Idk why I always go the hard way
It's the best way to learn new things! ;)
I prefer using this approach, as I don't have to import
a globalStyle file when I need them (since they're available from the Theme):
// Theme file
EStyleSheet.build({
$Button: {
backgroundColor: 'orange',
color: 'white'
}
})
// Component file
EStyleSheet.create({
button: () => ({
...EStyleSheet.value('$Button'),
color: 'red', // this overrides the default Button's color
}),
})
Sometimes we need to Override Global Styles at only one place & rest must apply default styles.
For example -
Default config -
Proposed config -