UNPKG

weex-nuke

Version:

基于 Rax 、Weex 的高性能组件体系 ~~

67 lines (58 loc) 1.51 kB
/** @jsx createElement */ import { PropTypes, Component } from 'rax'; import Theme from './theme'; /** * Provides a theme to child components trough context. */ export default class StyleProvider extends Component { static propTypes = { children: PropTypes.element.isRequired, style: PropTypes.object, }; static defaultProps = { style: {}, }; static childContextTypes = { theme: PropTypes.object, androidConfigs: PropTypes.object, compatibilityConfigs: PropTypes.object, commonConfigs: PropTypes.object, }; constructor(props, context) { super(props, context); this.state = { theme: this.createTheme(props), }; } getChildContext() { return { theme: this.state.theme, androidConfigs: this.getAndroidConfigs(this.props), compatibilityConfigs: this.getCompatConfigs(this.props), commonConfigs: this.getCommonConfigs(this.props), }; } componentWillReceiveProps(nextProps) { if (nextProps.style !== this.props.style) { this.setState({ theme: this.createTheme(nextProps), }); } } getAndroidConfigs(props) { return props.androidConfigs || {}; } getCompatConfigs(props) { return props.compatibilityConfigs || {}; // {toRemString:true} } getCommonConfigs(props) { return props.commonConfigs || {}; // {zoomFont:true} } createTheme(props) { return new Theme(props.style); } render() { const { children } = this.props; return children; } }