Skip to content

Commit

Permalink
[Breaking Change] Use React.createContext
Browse files Browse the repository at this point in the history
  • Loading branch information
xotahal committed Jun 26, 2018
1 parent 82de3c2 commit ebb0bc5
Show file tree
Hide file tree
Showing 34 changed files with 235 additions and 304 deletions.
3 changes: 2 additions & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "react-native-material-ui",
"version": "1.22.4",
"version": "1.30.0",
"description": "React Native Material Design Components",
"main": "./index.js",
"scripts": {
Expand Down Expand Up @@ -35,6 +35,7 @@
},
"dependencies": {
"color": "3.0.0",
"hoist-non-react-statics": "^2.5.5",
"lodash.merge": "^4.0.0",
"prop-types": "^15.5.10",
"react-native-material-design-styles": "^0.2.6"
Expand Down
17 changes: 7 additions & 10 deletions src/ActionButton/ActionButton.react.js
Expand Up @@ -18,6 +18,7 @@ import RippleFeedback from '../RippleFeedback';
/* eslint-disable import/no-unresolved, import/extensions */
import getPlatformElevation from '../styles/getPlatformElevation';
/* eslint-enable import/no-unresolved, import/extensions */
import withTheme from '../styles/withTheme';

function darkenOrLighten(color, ratio = 0.5) {
const c = Color(color);
Expand Down Expand Up @@ -83,13 +84,10 @@ const defaultProps = {
hidden: false,
rippleColor: null,
};
const contextTypes = {
uiTheme: PropTypes.object.isRequired, // eslint-disable-line
};

function getStyles(props, context, state) {
const { actionButton } = context.uiTheme;
const { size } = props;
function getStyles(props, state) {
const { size, theme } = props;
const { actionButton } = theme;

const local = {
container: {},
Expand Down Expand Up @@ -230,7 +228,7 @@ class ActionButton extends PureComponent {
return rippleColor;
}

const styles = getStyles(this.props, this.context, this.state);
const styles = getStyles(this.props, this.state);

const { backgroundColor } = StyleSheet.flatten(styles.container);

Expand Down Expand Up @@ -471,7 +469,7 @@ class ActionButton extends PureComponent {
render() {
const { render } = this.state;

const styles = getStyles(this.props, this.context, this.state);
const styles = getStyles(this.props, this.state);

if (render === 'toolbar') {
return this.renderToolbarTransition(styles);
Expand All @@ -486,6 +484,5 @@ class ActionButton extends PureComponent {

ActionButton.propTypes = propTypes;
ActionButton.defaultProps = defaultProps;
ActionButton.contextTypes = contextTypes;

export default ActionButton;
export default withTheme(ActionButton);
24 changes: 12 additions & 12 deletions src/Avatar/Avatar.react.js
Expand Up @@ -5,6 +5,7 @@ import { View, Image, Text, StyleSheet } from 'react-native';
import { ViewPropTypes } from '../utils';
/* eslint-enable import/no-unresolved, import/extensions */
import Icon from '../Icon';
import withTheme from '../styles/withTheme';

const propTypes = {
/**
Expand Down Expand Up @@ -38,6 +39,10 @@ const propTypes = {
container: ViewPropTypes.style,
content: Text.propTypes.style, // eslint-disable-line
}),
/**
* Theme
*/
theme: PropTypes.any, // eslint-disable-line
};
const defaultProps = {
image: null,
Expand All @@ -48,13 +53,10 @@ const defaultProps = {
size: 48,
style: {},
};
const contextTypes = {
uiTheme: PropTypes.object.isRequired, // eslint-disable-line
};

function getStyles(props, context) {
const { avatar } = context.uiTheme;
const { size } = props;
function getStyles(props) {
const { size, theme } = props;
const { avatar } = theme;

const local = {};

Expand All @@ -74,13 +76,12 @@ function getStyles(props, context) {

class Avatar extends PureComponent {
render() {
const { image, icon, iconSize, iconColor, text } = this.props;
const { uiTheme } = this.context;
const { avatar, spacing } = uiTheme;
const { image, icon, iconSize, iconColor, text, theme } = this.props;
const { avatar, spacing } = theme;

let content = null;

const styles = getStyles(this.props, this.context);
const styles = getStyles(this.props);

if (icon) {
const color = iconColor || StyleSheet.flatten(avatar.content).color;
Expand All @@ -102,6 +103,5 @@ class Avatar extends PureComponent {

Avatar.propTypes = propTypes;
Avatar.defaultProps = defaultProps;
Avatar.contextTypes = contextTypes;

export default Avatar;
export default withTheme(Avatar);
15 changes: 6 additions & 9 deletions src/Badge/Badge.react.js
Expand Up @@ -5,6 +5,7 @@ import PropTypes from 'prop-types';
/* eslint-enable import/no-unresolved, import/extensions */
import Icon from '../Icon';
import { ViewPropTypes } from '../utils';
import withTheme from '../styles/withTheme';

const propTypes = {
/**
Expand Down Expand Up @@ -59,13 +60,10 @@ const defaultProps = {
},
},
};
const contextTypes = {
uiTheme: PropTypes.object.isRequired, // eslint-disable-line
};

function getStyles(props, context) {
const { badge, palette } = context.uiTheme;
const { accent, size, stroke } = props;
function getStyles(props) {
const { accent, size, stroke, theme } = props;
const { badge, palette } = theme;

const local = {
container: {},
Expand Down Expand Up @@ -160,7 +158,7 @@ class Badge extends PureComponent {
}

render() {
const styles = getStyles(this.props, this.context);
const styles = getStyles(this.props);

return (
<View style={{ flexDirection: 'row' }}>
Expand All @@ -173,6 +171,5 @@ class Badge extends PureComponent {

Badge.propTypes = propTypes;
Badge.defaultProps = defaultProps;
Badge.contextTypes = contextTypes;

export default Badge;
export default withTheme(Badge);
14 changes: 7 additions & 7 deletions src/BottomNavigation/BottomNavigation.react.js
Expand Up @@ -5,6 +5,8 @@ import { View, Animated, Easing, StyleSheet } from 'react-native';
import { ViewPropTypes } from '../utils';
/* eslint-enable import/no-unresolved, import/extensions */

import withTheme from '../styles/withTheme';

import BottomNavigationAction from './BottomNavigationAction.react';

const propTypes = {
Expand Down Expand Up @@ -32,12 +34,9 @@ const defaultProps = {
hidden: false,
style: {},
};
const contextTypes = {
uiTheme: PropTypes.object.isRequired, // eslint-disable-line
};

function getStyles(props, context) {
const { bottomNavigation } = context.uiTheme;
function getStyles(props) {
const { bottomNavigation } = props.theme;
const local = {};

return {
Expand Down Expand Up @@ -131,8 +130,9 @@ class BottomNavigation extends PureComponent {

BottomNavigation.propTypes = propTypes;
BottomNavigation.defaultProps = defaultProps;
BottomNavigation.contextTypes = contextTypes;

BottomNavigation.Action = BottomNavigationAction;

export default BottomNavigation;
const ThemedBottomNavigation = withTheme(BottomNavigation);

export default ThemedBottomNavigation;
11 changes: 4 additions & 7 deletions src/BottomNavigation/BottomNavigationAction.react.js
Expand Up @@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
import { StyleSheet, View, Text } from 'react-native';
import { ViewPropTypes } from '../utils';
/* eslint-enable import/no-unresolved, import/extensions */
import withTheme from '../styles/withTheme';

import RippleFeedback from '../RippleFeedback';
import Icon from '../Icon';
Expand Down Expand Up @@ -46,12 +47,9 @@ const defaultProps = {
disabled: false,
style: {},
};
const contextTypes = {
uiTheme: PropTypes.object.isRequired, // eslint-disable-line
};

function getStyles(props, context) {
const { bottomNavigationAction } = context.uiTheme;
function getStyles(props) {
const { bottomNavigationAction } = props.theme;

const local = {};

Expand Down Expand Up @@ -120,6 +118,5 @@ class BottomNavigationAction extends PureComponent {

BottomNavigationAction.propTypes = propTypes;
BottomNavigationAction.defaultProps = defaultProps;
BottomNavigationAction.contextTypes = contextTypes;

export default BottomNavigationAction;
export default withTheme(BottomNavigationAction);
24 changes: 10 additions & 14 deletions src/Button/Button.react.js
Expand Up @@ -9,6 +9,7 @@ import RippleFeedback from '../RippleFeedback';
/* eslint-disable import/no-unresolved, import/extensions */
import getPlatformElevation from '../styles/getPlatformElevation';
/* eslint-enable import/no-unresolved, import/extensions */
import withTheme from '../styles/withTheme';

const propTypes = {
testID: PropTypes.string,
Expand Down Expand Up @@ -62,21 +63,17 @@ const defaultProps = {
upperCase: true,
style: {},
};
const contextTypes = {
uiTheme: PropTypes.object.isRequired, // eslint-disable-line
};

function getStyles(props, context, state) {
function getStyles(props, state) {
const { primary, accent, disabled, raised, theme } = props;
const {
button,
buttonFlat,
buttonRaised,
buttonDisabled,
buttonRaisedDisabled,
} = context.uiTheme;

const { primary, accent, disabled, raised } = props;
const { palette } = context.uiTheme;
palette,
} = theme;

const local = {
container: {},
Expand Down Expand Up @@ -139,7 +136,7 @@ class Button extends PureComponent {
constructor(props) {
super(props);
this.state = {
elevation: 2, // eslint-disable-line
elevation: 2, // eslint-disable-line
};
}

Expand All @@ -153,13 +150,13 @@ class Button extends PureComponent {

setElevation = () => {
this.setState({
elevation: 4, // eslint-disable-line
elevation: 4, // eslint-disable-line
});
};

removeElevation = () => {
this.setState({
elevation: 2, // eslint-disable-line
elevation: 2, // eslint-disable-line
});
};

Expand Down Expand Up @@ -199,7 +196,7 @@ class Button extends PureComponent {
testID,
} = this.props;

const styles = getStyles(this.props, this.context, this.state);
const styles = getStyles(this.props, this.state);

const content = (
<View style={styles.container} pointerEvents="box-only">
Expand Down Expand Up @@ -229,6 +226,5 @@ class Button extends PureComponent {

Button.propTypes = propTypes;
Button.defaultProps = defaultProps;
Button.contextTypes = contextTypes;

export default Button;
export default withTheme(Button);
15 changes: 6 additions & 9 deletions src/Card/Card.react.js
Expand Up @@ -5,6 +5,7 @@ import PropTypes from 'prop-types';
/* eslint-enable import/no-unresolved, import/extensions */
import RippleFeedback from '../RippleFeedback';
import { ViewPropTypes } from '../utils';
import withTheme from '../styles/withTheme';

const propTypes = {
children: PropTypes.node,
Expand All @@ -18,12 +19,9 @@ const defaultProps = {
onPress: null,
style: {},
};
const contextTypes = {
uiTheme: PropTypes.object.isRequired, // eslint-disable-line
};

function getStyles(props, context) {
const { card } = context.uiTheme;
function getStyles(props) {
const { card } = props.theme;

const local = {};

Expand All @@ -43,12 +41,12 @@ class Card extends PureComponent {
super(props, context);

this.state = {
styles: getStyles(props, context),
styles: getStyles(props),
};
}

componentWillReceiveProps(nextProps) {
this.setState({ styles: getStyles(nextProps, this.context) });
this.setState({ styles: getStyles(nextProps) });
}

renderContent = () => {
Expand Down Expand Up @@ -79,6 +77,5 @@ class Card extends PureComponent {

Card.propTypes = propTypes;
Card.defaultProps = defaultProps;
Card.contextTypes = contextTypes;

export default Card;
export default withTheme(Card);

0 comments on commit ebb0bc5

Please sign in to comment.