To get a consistent style for the Text elements (or any other basic element used in the React Native application), our team started creating a library of components for our application that correspond to the styles and style guide name compiled by our development team.
For example, your text component would look like this:
import React, { PropTypes, Component } from 'react'; import ReactNative from 'react-native'; export default class Text extends Component { getProps() { const { fontSize, fontWeight } = this.props; return { fontSize, fontWeight, }; } render() { return ( <ReactNative.Text {...this.getProps()}>{this.props.children}</ReactNative.Text> ); } } Text.propTypes = { fontSize: PropTypes.oneOf([ 25, 20, 15, ]), fontWeight: PropTypes.oneOf([ 'normal', 'bold', ]), }; Text.defaultProps = { fontSize: 20, fontWeight: 'normal', };
By creating a text component in this way, you can determine which styles are available and show developers a warning if they do not use a valid style with PropTypes definitions.
We also wanted the components in this library to easily reference any file in which you needed them, and therefore we gave the main library file a name with the providesModule comment, which some internal React Native components use.
The main library file looks something like this.
module.exports = { get Text() { return require('./Text').default; }, };
Then you just need to import it into some component file where you need a custom Text component.
import { Text } from 'AppNameLibrary';
This is one way to do this. Iβm not sure if this is the best way, but itβs a good way that our team started developing the components, so they are developed sequentially in a way that fits our style guide.
As for changing the text color of the TextInput Android component, just setting color: 'orange' as the style, changing the text to orange for me. We are currently using RN 0.28.