• Stars
    star
    110
  • Rank 316,770 (Top 7 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 2 years ago
  • Updated almost 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

react-native-theme-control

Control the native platform theme from React Native.

βœ… Control theme of RN Views, as well as native UI controls (alerts, native menus, date pickers... on both Android and iOS)

βœ… Control the color of the ApplicationWindow (iOS) or the current Activity (Android) using AppBackground

βœ… Recover the theme upon app startup

βœ… Supports Expo via a config plugin

βœ… New Architecture supported

Additionally, provides functionality to control the appearance (background and border color, light / dark buttons) of the Android navbar.

The package is tested with RN >= 0.66.1 (last tested with RN 73, Expo 49). See RN version support.

Example

Notice the color of scroll bar and keyboard in the screenshots below.

light mode dark mode application background in modal
light dark app background

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 and usage instructions can be found here.

The library api is documented in detail here.

More usage examples can be found in the example project.

This Package Was Sponsorware πŸ’°πŸ’°πŸ’°

This package was only available to my GitHub Sponsors, but is now publicly available tweet.

Enjoy, and thanks for the support! ❀️

Sponsorware idea is not mine, learn more about Sponsorware at github.com/sponsorware/docs πŸ’°.

I simply adopted it because making open source is a lot of fun but is not sustainable without compensation.

Credits

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

License

MIT

More Repositories

1

react-navigation-header-buttons

Easily render header buttons for react-navigation
TypeScript
808
star
2

react-navigation-props-mapper

Forwards react-navigation params to your screen component's props directly
TypeScript
397
star
3

react-native-add-calendar-event

Create, view or edit events in react native using the standard iOS / Android dialogs
Objective-C
321
star
4

react-native-simple-toast

Cross-platform Toast experience for React Native
Objective-C++
286
star
5

react-navigation-backhandler

Easily handle Android back button behavior with React-Navigation.
JavaScript
198
star
6

react-native-bottom-toolbar

UI Bar in javascript for react native
JavaScript
47
star
7

react-navigation-mst-demo

demo of react-navigation with mobx state tree
JavaScript
37
star
8

react-native-round-checkbox

iOS-styled round checkbox for RN
JavaScript
30
star
9

react-native-platforms

React Native Platform Shortcuts
TypeScript
22
star
10

navigation-experimental-fork

NavigationExperimental from RN 0.43.3. Useful when you still depend on it in RN >= 0.44.
JavaScript
7
star
11

react-native-flabel-textfield

Floating label text input for RN
JavaScript
5
star
12

react-to-imperative

Convert React (Native) components for imperative use.
TypeScript
5
star
13

react-native-radio-button-android

native android radio button for react native
Java
4
star
14

text_locator

ROS package for detecting and recognizing text in images
C++
3
star
15

react-native-keyboard-utils

Simple components for common use cases with keyboard
JavaScript
2
star
16

react-native-document-picker

replacement for accidentally deleted fork - to be deleted. Please use https://www.npmjs.com/package/react-native-document-picker
C#
2
star
17

phone8uip

bachelor thesis text
TeX
1
star
18

vonovak

1
star