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 type * as React from 'react';
11import {Constructor} from '../../../types/private/Utilities';
12import {NativeMethods} from '../../../types/public/ReactNativeTypes';
13import {ColorValue, StyleProp} from '../../StyleSheet/StyleSheet';
14import {ViewStyle} from '../../StyleSheet/StyleSheetTypes';
15import {ViewProps} from '../View/ViewPropTypes';
16import {NativeSyntheticEvent, TargetedEvent} from '../../Types/CoreEventTypes';
17
18export interface SwitchPropsIOS extends ViewProps {
19  /**
20   * Background color when the switch is turned on.
21   *
22   * @deprecated use trackColor instead
23   */
24  onTintColor?: ColorValue | undefined;
25
26  /**
27   * Color of the foreground switch grip.
28   *
29   * @deprecated use thumbColor instead
30   */
31  thumbTintColor?: ColorValue | undefined;
32
33  /**
34   * Background color when the switch is turned off.
35   *
36   * @deprecated use trackColor instead
37   */
38  tintColor?: ColorValue | undefined;
39}
40
41export interface SwitchChangeEventData extends TargetedEvent {
42  value: boolean;
43}
44
45export interface SwitchChangeEvent
46  extends NativeSyntheticEvent<SwitchChangeEventData> {}
47
48export interface SwitchProps extends SwitchPropsIOS {
49  /**
50   * Color of the foreground switch grip.
51   */
52  thumbColor?: ColorValue | undefined;
53
54  /**
55   * Custom colors for the switch track
56   *
57   * Color when false and color when true
58   */
59  trackColor?:
60    | {
61        false?: ColorValue | null | undefined;
62        true?: ColorValue | null | undefined;
63      }
64    | undefined;
65
66  /**
67   * If true the user won't be able to toggle the switch.
68   * Default value is false.
69   */
70  disabled?: boolean | undefined;
71
72  /**
73   * Invoked with the change event as an argument when the value changes.
74   */
75  onChange?:
76    | ((event: SwitchChangeEvent) => Promise<void> | void)
77    | null
78    | undefined;
79
80  /**
81   * Invoked with the new value when the value changes.
82   */
83  onValueChange?: ((value: boolean) => Promise<void> | void) | null | undefined;
84
85  /**
86   * Used to locate this view in end-to-end tests.
87   */
88  testID?: string | undefined;
89
90  /**
91   * The value of the switch. If true the switch will be turned on.
92   * Default value is false.
93   */
94  value?: boolean | undefined;
95
96  /**
97   * On iOS, custom color for the background.
98   * Can be seen when the switch value is false or when the switch is disabled.
99   */
100  ios_backgroundColor?: ColorValue | undefined;
101
102  style?: StyleProp<ViewStyle> | undefined;
103}
104
105/**
106 * Renders a boolean input.
107 *
108 * This is a controlled component that requires an `onValueChange` callback that
109 * updates the `value` prop in order for the component to reflect user actions.
110 * If the `value` prop is not updated, the component will continue to render
111 * the supplied `value` prop instead of the expected result of any user actions.
112 */
113declare class SwitchComponent extends React.Component<SwitchProps> {}
114declare const SwitchBase: Constructor<NativeMethods> & typeof SwitchComponent;
115export class Switch extends SwitchBase {}
116