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 * Add an event handler that is fired when appearance preferences change. 33 */ 34 export function addChangeListener( 35 listener: AppearanceListener, 36 ): NativeEventSubscription; 37} 38 39/** 40 * A new useColorScheme hook is provided as the preferred way of accessing 41 * the user's preferred color scheme (e.g. Dark Mode). 42 */ 43export function useColorScheme(): ColorSchemeName; 44