consider the following use case;
my current project uses custom fonts, which means we want that all Text
components have fontFamily: Fonts.Normal
. (of course this can be any other style default)
my first intuition was to create a new component and use it all across the project, e.g
var Fonts = require('./../Fonts'); var DefaultText = React.createClass({ propTypes: { style: Text.propTypes.style }, render() { return ( <Text style={[styles.text, this.props.style]}>{this.props.children}</Text> ); } }); var styles = StyleSheet.create({ text: { fontFamily: Fonts.Normal } });
IMO, this approach is very error prone, since it's very easy to forget about this and use the RN Text
.
I'm interesting to know if currently there's an alternative to this approach?
I think that, just like a web app has a default.css
, a RN app should provide a way to define defaults - some like:
var React = require('react-native'); var { AppRegistry, StyleSheet, Text } = React; var defaultTextStyle = StyleSheet.create({ text: { fontFamily: Fonts.Normal } }); AppRegistry.registerComponentStyle(Text, defaultTextStyle) // or maybe just Text.defaultProps.style = defaultTextStyle // before/after the app is registered? AppRegistry.registerComponent('MyApp', () => MyApp);
Thoughts?
@ide @JohnyDays /cc
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4