Skip to content

A React Native package to let users override the app's color scheme/theme

License

Notifications You must be signed in to change notification settings

plumvillage/react-native-override-color-scheme

Repository files navigation

react-native-override-color-scheme

React Native package to let users override the app's color scheme/theme.

Installation

npm install react-native-override-color-scheme

or

yarn add react-native-override-color-scheme

RN >= 0.60

If you are using RN >= 0.60, only run npx pod-install. Then rebuild your project.

iOS

Optional support for alerts on iOS

⚠️ We use method swizzling to enable support for alerts on iOS. Method swizzling is used by Firebase iOS SDK as well, but it can be problematic in some cases, especially when another library is also swizzling the same method. That’s why we have made this step optional.

To enable support for alerts on iOS, please follow the steps below:

  1. Open your /ios/{projectName}/AppDelegate.m file
  2. At the top of the file, import the OverrideColorScheme module: #import <OverrideColorScheme.h>
  3. And then, within your existing didFinishLaunchingWithOptions method, add [OverrideColorScheme enableAlertSupport]; to the top of the method (see below).
#import <OverrideColorScheme.h> // <--- import

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [OverrideColorScheme enableAlertSupport]; // <--- and add this line
  //...
}

Android

No additional step is required.

Usage

import overrideColorScheme from 'react-native-override-color-scheme';

// ...

overrideColorScheme.setScheme('dark'); // or `light` or `undefined` for system default

See the example for advanced use cases.

Supporting

This package is maintained by the Plum Village App team and used by the App. You can set up a donation if you would like to financially support the further development of Plum Village App and this package.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT