GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - vonovak/react-native-theme-control: Natively control react native application theme at runtime and persist it for the next app start.

BranchesTags
Open more actions menu

Latest commit

 

History

87 Commits
87 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.yarn/releases
.yarn/releases
 
 
android
android
 
 
docs
docs
 
 
example.old
example.old
 
 
example
example
 
 
img
img
 
 
ios
ios
 
 
plugin
plugin
 
 
scripts
scripts
 
 
src
src
 
 
.editorconfig
.editorconfig
 
 
.eslintrc.js
.eslintrc.js
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.prettierrc.js
.prettierrc.js
 
 
.yarnrc.yml
.yarnrc.yml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
app.plugin.js
app.plugin.js
 
 
babel.config.js
babel.config.js
 
 
jest.config.js
jest.config.js
 
 
metro.config.js
metro.config.js
 
 
package.json
package.json
 
 
react-native-theme-control.podspec
react-native-theme-control.podspec
 
 
react-native.config.js
react-native.config.js
 
 
release.config.js
release.config.js
 
 
tsconfig.build.json
tsconfig.build.json
 
 
tsconfig.json
tsconfig.json
 
 
typedoc.config.js
typedoc.config.js
 
 
yarn.lock
yarn.lock
 
 

Repository files navigation

react-native-theme-control

npm version License: MIT

Control the native platform theme from React Native with full support for both React Native Views and native UI components.

Quick Start

npm install @vonovak/react-native-theme-control
# or
yarn add @vonovak/react-native-theme-control

For Expo projects:

{
  "expo": {
    "plugins": ["@vonovak/react-native-theme-control"]
  }
}

Basic usage:

import {
  setThemePreference,
  useThemePreference,
} from '@vonovak/react-native-theme-control';

// Set theme
setThemePreference('dark'); // 'light', 'dark', or 'system'

// Use in components
const theme = useThemePreference(); // Returns current theme preference

Features

✅ Complete Theme Control - Control both React Native Views and native UI components (alerts, date pickers, menus)

✅ Theme Persistence - Automatically recovers and applies your theme before app rendering starts rendering

✅ Native Integration - Control iOS UIApplication Window and Android Activity backgrounds using AppBackground

✅ Expo Support - Works seamlessly with Expo via config plugin

✅ New Architecture Ready - Full support for React Native's New Architecture

Example

The library ensures consistent theming across your entire app - notice how the scroll bars and keyboard adapt to your theme:

Light Mode Dark Mode Modal Background
light dark app background

View complete example project →

Motivation

The use case for the package is explained in a youtube video.

In React Native, you can use the useColorScheme() hook, or other functions from the Appearance API to get information about the system theme.

Note: as of RN 72, the following paragraph isn't true anymore (there is setColorScheme now). However, RN does not maintain the selected color scheme across restarts and doesn't contain other goodies in this package.

Using that information, you can then render your Views in dark or light mode design. However, that information is read-only: you cannot influence what the useColorScheme() hook returns. What if you want to allow the user to choose the application theme? React Native core does not directly expose the APIs to do so.

You might follow one of the many blog posts for theming React Native apps such as here or here. The approach taken by the guides is to store the application theme in the JavaScript part of your app. However, this can easily leave your users with a broken experience because while the React Native views will be rendered correctly, the native views (Alert, Document picker, Date picker, Menu...) will not.

This package provides a solution to change the application theme so that both react native and native components use the same theme - see the relevant part of the video.

Documentation

  • 📖 Installation Guide - Complete setup instructions
  • 🔧 API Reference - Detailed API documentation
  • 💡 Example Project - Working implementation
  • 🎥 Video Tutorial - See it in action

Common Issues

Android activity restarts on theme change? → See solution

Scroll bars not changing color? → See solution

Need help? → Open an issue

Support

If you find this library useful, consider:

  • ⭐ Starring the repository
  • 💖 Sponsoring the project
  • 🐛 Reporting issues

Credits

Some naming inspiration for the Android Navbar components was taken from react-native-bars.

License

MIT

About

Natively control react native application theme at runtime and persist it for the next app start.

Topics

apearancedarkdark-modehacktoberfestreact-nativetheme

Resources

Readme
MIT license
Activity

Stars

175 stars

Watchers

3 watching

Forks

9 forks
Report repository

Releases

Sponsor this project

Used by

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.