UNPKG

1.74 kBTypeScriptView Raw
1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @format
8 */
9
10import {NativeEventSubscription} from '../EventEmitter/RCTNativeAppEventEmitter';
11
12type ColorSchemeName = 'light' | 'dark' | null | undefined;
13
14export namespace Appearance {
15 type AppearancePreferences = {
16 colorScheme: ColorSchemeName;
17 };
18
19 type AppearanceListener = (preferences: AppearancePreferences) => void;
20
21 /**
22 * Note: Although color scheme is available immediately, it may change at any
23 * time. Any rendering logic or styles that depend on this should try to call
24 * this function on every render, rather than caching the value (for example,
25 * using inline styles rather than setting a value in a `StyleSheet`).
26 *
27 * Example: `const colorScheme = Appearance.getColorScheme();`
28 */
29 export function getColorScheme(): ColorSchemeName;
30
31 /**
32 * Set the color scheme preference. This is useful for overriding the default
33 * color scheme preference for the app. Note that this will not change the
34 * appearance of the system UI, only the appearance of the app.
35 * Only available on iOS 13+ and Android 10+.
36 */
37 export function setColorScheme(
38 scheme: ColorSchemeName | null | undefined,
39 ): void;
40
41 /**
42 * Add an event handler that is fired when appearance preferences change.
43 */
44 export function addChangeListener(
45 listener: AppearanceListener,
46 ): NativeEventSubscription;
47}
48
49/**
50 * A new useColorScheme hook is provided as the preferred way of accessing
51 * the user's preferred color scheme (e.g. Dark Mode).
52 */
53export function useColorScheme(): ColorSchemeName;