SwitchNativeComponent.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * Copyright (c) Facebook, Inc. and its 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. * @flow strict-local
  8. * @format
  9. */
  10. 'use strict';
  11. import type {BubblingEventHandler, WithDefault} from '../../Types/CodegenTypes';
  12. import type {ColorValue} from '../../StyleSheet/StyleSheetTypes';
  13. import type {ViewProps} from '../View/ViewPropTypes';
  14. import * as React from 'react';
  15. import codegenNativeComponent from '../../Utilities/codegenNativeComponent';
  16. import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
  17. import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes';
  18. type SwitchChangeEvent = $ReadOnly<{|
  19. value: boolean,
  20. |}>;
  21. type NativeProps = $ReadOnly<{|
  22. ...ViewProps,
  23. // Props
  24. disabled?: WithDefault<boolean, false>,
  25. value?: WithDefault<boolean, false>,
  26. tintColor?: ?ColorValue,
  27. onTintColor?: ?ColorValue,
  28. thumbTintColor?: ?ColorValue,
  29. // Deprecated props
  30. thumbColor?: ?ColorValue,
  31. trackColorForFalse?: ?ColorValue,
  32. trackColorForTrue?: ?ColorValue,
  33. // Events
  34. onChange?: ?BubblingEventHandler<SwitchChangeEvent>,
  35. |}>;
  36. type ComponentType = HostComponent<NativeProps>;
  37. interface NativeCommands {
  38. +setValue: (viewRef: React.ElementRef<ComponentType>, value: boolean) => void;
  39. }
  40. export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
  41. supportedCommands: ['setValue'],
  42. });
  43. export default (codegenNativeComponent<NativeProps>('Switch', {
  44. paperComponentName: 'RCTSwitch',
  45. excludedPlatform: 'android',
  46. }): ComponentType);