Create simple ThemeProvider and Default Theme

This commit is contained in:
Ahmed Magdy
2016-10-21 01:42:43 +02:00
parent 1b13980561
commit 9ea9bb9801
3 changed files with 50 additions and 1 deletions

View File

@@ -1,7 +1,7 @@
[ignore]
# Ignore node_modules folder
.node_modules
<PROJECT_ROOT>/node_modules
<PROJECT_ROOT>/ReactNativePaperExample
[version]

17
src/DefaultTheme.js Normal file
View File

@@ -0,0 +1,17 @@
// @flow
import {
indigo500,
indigo700,
pinkA200
} from './styles/colors';
const DefaultTheme = () => {
return {
primaryColor: indigo500,
primaryDarkColor: indigo700,
accentColor: pinkA200,
};
};
export default DefaultTheme;

32
src/ThemeProvider.js Normal file
View File

@@ -0,0 +1,32 @@
// @flow
import {
Component,
PropTypes
} from 'react';
import DefaultTheme from './DefaultTheme';
class ThemeProvider extends Component {
static propTypes = {
children: PropTypes.element,
theme: PropTypes.object,
};
static childContextTypes = {
theme: PropTypes.object,
};
getChildContext() {
return {
theme: this.props.theme || DefaultTheme(),
};
}
render() {
return this.props.children;
}
}
export default ThemeProvider;