mirror of
https://github.com/zhigang1992/react-native-paper.git
synced 2026-05-10 13:14:26 +08:00
Create simple ThemeProvider and Default Theme
This commit is contained in:
@@ -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
17
src/DefaultTheme.js
Normal 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
32
src/ThemeProvider.js
Normal 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;
|
||||
Reference in New Issue
Block a user