
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
react-native-appearance
Advanced tools
Polyfill for `Appearance` API which will likely be available in `react-native@>=0.61`. iOS only.
Polyfill for Appearance API to detect preferred color scheme (light/dark) in React Native 0.59, 0.60 and perhaps more (ymmv outside of these two!). The Appearance API will likely be available in react-native@>=0.61.
This library is currently iOS only, and on iOS < 13 the color scheme will always be 'no-preference'.
Install the library using either Yarn:
yarn add react-native-appearance
or npm:
npm install --save react-native-appearance
You then need to link the native parts of the library for the platforms you are using. The easiest way to link the library is using the CLI tool by running this command from the root of your project:
react-native link react-native-appearance
If you can't or don't want to use the CLI tool, you can also manually link the library using the instructions below (click on the arrow to show them):
Either follow the instructions in the React Native documentation to manually link the framework or link using Cocoapods by adding this to your Podfile:
pod 'react-native-appearance', :path => '../node_modules/react-native-appearance'
First, you need to wrap your app in the AppearanceProvider. At the root of your app, do the following:
import { AppearanceProvider } from 'react-native-appearance';
export default () => (
<AppearanceProvider>
<App />
</AppearanceProvider>
);
Now you can use Appearance and useColorScheme anywhere in your app.
import { Appearance, useColorScheme } from 'react-native-appearance';
/**
* Get the current color scheme
*/
Appearance.getColorScheme();
/**
* Subscribe to color scheme changes with a hook
*/
function MyComponent() {
let colorScheme = useColorScheme();
if (colorScheme === 'dark') {
// render some dark thing
} else {
// render some light thing
}
}
/**
* Subscribe to color scheme without a hook
*/
let subscription = Appearance.addChangeListener(({ colorScheme }) => {
// do something with color scheme
});
// Remove the subscription at some point
subscription.remove()
This was mostly written by Facebook for inclusion in React Native core. It is provided here as a separate module so people can opt-in to using it without updating entirely to the newest React Native version.
FAQs
Polyfill for `Appearance` API which will be available in `react-native@0.62`.
The npm package react-native-appearance receives a total of 2,872 weekly downloads. As such, react-native-appearance popularity was classified as popular.
We found that react-native-appearance 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.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.