2018-08-09 00:50:58 +03:00
|
|
|
/**
|
2018-09-12 01:27:47 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2018-08-09 00:50:58 +03:00
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*
|
2019-12-06 02:58:55 +03:00
|
|
|
* @flow strict-local
|
2018-08-09 00:50:58 +03:00
|
|
|
* @format
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2019-07-01 15:10:20 +03:00
|
|
|
import type {BubblingEventHandler, WithDefault} from '../../Types/CodegenTypes';
|
2020-04-17 23:01:17 +03:00
|
|
|
import type {ColorValue} from '../../StyleSheet/StyleSheet';
|
2019-05-08 18:44:25 +03:00
|
|
|
import type {ViewProps} from '../View/ViewPropTypes';
|
2019-11-04 18:42:19 +03:00
|
|
|
import * as React from 'react';
|
2018-08-09 00:50:58 +03:00
|
|
|
|
2019-06-10 13:26:44 +03:00
|
|
|
import codegenNativeComponent from '../../Utilities/codegenNativeComponent';
|
2019-11-04 18:42:19 +03:00
|
|
|
import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
|
2019-09-25 21:42:07 +03:00
|
|
|
import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes';
|
2019-01-08 02:36:33 +03:00
|
|
|
|
2019-06-10 13:26:44 +03:00
|
|
|
type SwitchChangeEvent = $ReadOnly<{|
|
|
|
|
value: boolean,
|
2018-08-09 00:50:58 +03:00
|
|
|
|}>;
|
|
|
|
|
2019-06-10 13:26:44 +03:00
|
|
|
type NativeProps = $ReadOnly<{|
|
|
|
|
...ViewProps,
|
2019-01-08 02:36:33 +03:00
|
|
|
|
2019-06-10 13:26:44 +03:00
|
|
|
// Props
|
2019-07-02 12:59:04 +03:00
|
|
|
disabled?: WithDefault<boolean, false>,
|
|
|
|
value?: WithDefault<boolean, false>,
|
2019-06-10 13:26:44 +03:00
|
|
|
tintColor?: ?ColorValue,
|
|
|
|
onTintColor?: ?ColorValue,
|
|
|
|
thumbTintColor?: ?ColorValue,
|
2018-08-09 00:50:58 +03:00
|
|
|
|
2019-06-10 13:26:44 +03:00
|
|
|
// Deprecated props
|
|
|
|
thumbColor?: ?ColorValue,
|
|
|
|
trackColorForFalse?: ?ColorValue,
|
|
|
|
trackColorForTrue?: ?ColorValue,
|
2018-08-09 00:50:58 +03:00
|
|
|
|
2019-06-10 13:26:44 +03:00
|
|
|
// Events
|
2019-07-01 15:10:20 +03:00
|
|
|
onChange?: ?BubblingEventHandler<SwitchChangeEvent>,
|
2019-06-10 13:26:44 +03:00
|
|
|
|}>;
|
2018-08-09 00:50:58 +03:00
|
|
|
|
2019-11-04 18:42:19 +03:00
|
|
|
type ComponentType = HostComponent<NativeProps>;
|
|
|
|
|
|
|
|
interface NativeCommands {
|
|
|
|
+setValue: (viewRef: React.ElementRef<ComponentType>, value: boolean) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
|
|
|
|
supportedCommands: ['setValue'],
|
|
|
|
});
|
|
|
|
|
2019-08-09 20:06:53 +03:00
|
|
|
export default (codegenNativeComponent<NativeProps>('Switch', {
|
2019-06-19 19:50:29 +03:00
|
|
|
paperComponentName: 'RCTSwitch',
|
2020-05-07 19:40:51 +03:00
|
|
|
excludedPlatforms: ['android'],
|
2019-11-04 18:42:19 +03:00
|
|
|
}): ComponentType);
|