
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
react-native-themes
Advanced tools
$ npm install react-native-themes --save
OR
$ yarn add react-native-themes --save
//colors.js
import Theme from 'react-native-themes';
const colors = new Theme.Colors({
DEFAULT_THEME: {
backgroundColor: '#fff',
},
DARK_THEME: {
backgroundColor: '#3b5998',
}
});
export default colors;
Note - Do not forget to import this file at the top of your component(ie. App.js).
By default the first theme in the colors template is selected. In the root component of your app like App.js, register ThemeListeners for the component to act on the default theme applied.
//App.js
componentWillMount() {
this.listener = Theme.addThemeListener(() => {
this.setState({});
});
}
componentWillUnmount() {
Theme.removeThemeListener(this.listener);
}
Create the stylesheet for your components as a function.
Example -
import { StyleSheet } from 'react-native';
const styles = (colors) => {
return StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: colors.backgroundColor,
},
...
});
}
export default styles;
In the components where you would like to apply the theme colors call the getStyles(stylesheet) function in componentWillMount().
import Theme from 'react-native-themes';
import stylesheet from './styles'; //Stylesheet created in Step 2
let styles;
class MyComponent extends Component {
...
componentWillMount(){
styles = Theme.getStyles(stylesheet);
//use the styles for styling the components in render methods.
}
...
}
Note
For inline styles, you can get the colors by calling Theme.getColors()
Example
render(){
const colors = Theme.getColors();
return (
<View style={{ backgroundColor: colors.backgroundColor, flex:1 }}>
...
</View>
);
}
By default the first color theme will be applied. If you want to change the color theme you need to call the Theme.setColorTheme(themeName, callback)
themeName - Name of the theme defined in Step 1.callback - Callback function to be called after theme is setExample-
import Theme from 'react-native-themes';
...
render(){
//have to fetch styles again as the Theme Change
//will re-render the Component.
styles = Theme.getStyles(stylesheet);
return (
...
<Button
onPress={() => {
if (Theme.getColorTheme() === 'DEFAULT_THEME') {
Theme.setColorTheme('DARK_THEME', () => {
this.setState({}); //force re-render of the component
});
} else {
Theme.setColorTheme('DEFAULT_THEME', () => {
this.setState({}); //force re-render of the component
}));
}
}}
title="Change Theme" />
...
);
}
Bugs? Comments? Features? PRs and Issues happily welcomed!
Sandeep Tiwari
FAQs
Library that allows you to integrate multiple themes
We found that react-native-themes demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.