##theaming-nb-headref
Customizing NativeBase will be a cakewalk for you. That is due to the fact, NativeBase has categorized its screens into different sections. It provides a separate file inclusive of color schemes for different sections.
Note: NativeBase is built on top of React Native. Hence with any component you can pass the style property which will be merged to the default style of that component.
- Run node node_modules/native-base/ejectTheme.js from your terminal after installing native-base.
- All the theme files and variables get added to your project root. Change the variables or theme files.
- Wrap the code or component to which you want to apply the theme with .
- Pass the variable i.e platform/material/commonColors.js as the parameter of theme function, which is passed as a value to style prop of component .
Now your project is ready for theme customization.
When you run node node_modules/native-base/ejectTheme.js from your terminal, a folder named native-base-theme gets copied to your project root. Inside the directory are two folders named components and variables.
The components folder contains the theme styling files for all the components. This is where you would change the style properties of your components if you need to
For example, if you need to change the height of Button component, you'll need to change this line in native-base-theme/components/Button.js.
The variables folder contains the three preset theme variables. You can change the variables,(color, fontFamily, iconFamily etc) for a uniform look and feel throughout your app.
NativeBase is packed with three preset themes.
Platform:The default theme of NativeBase which maps to the design of the platform where the app runs.Material:Sometimes, you need Material design for both the platforms. Not everyone is a fan but Google does use Material design on iOS. This theme is not 100% material yet but it can be used today.Common Colors:Most of the brands use a common color scheme for both the platforms but they also follow platform specific icons, font and orientation of the components. Common Colors theme is best suited for such use-cases.
Syntax to add Material Design
import {Container, Content, Text, StyleProvider} from 'native-base';
import React, {Component} from 'react-native';
import getTheme from './native-base-theme/components';
import material from './native-base-theme/variables/material';
export default class ThemeExample extends Component {
render() {
return (
<StyleProvider style={getTheme(material)}>
<Container>
<Content>
<Text>
I have changed the text color.
</Text>
</Content>
</Container>
</StyleProvider>
);
}
}- The
<StyleProvider>with theme can be applied to any component of NativeBase. - The theme holds good with all its descendants.
- The above code for theme change works this way:
Go to native-base-theme/variables/platform.js and modify color code for textColor. - Similarly you can customize theme for the rest of NativeBase components by modifying color code of their respective attributes, some of which are explained below.