AndroidSwitchNativeComponent.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 * as React from 'react';
  12. import type {
  13. WithDefault,
  14. BubblingEventHandler,
  15. } from 'react-native/Libraries/Types/CodegenTypes';
  16. import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
  17. import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
  18. import type {HostComponent} from 'react-native/Libraries/Renderer/shims/ReactNativeTypes';
  19. import type {ColorValue} from '../../StyleSheet/StyleSheetTypes';
  20. import type {ViewProps} from '../View/ViewPropTypes';
  21. type SwitchChangeEvent = $ReadOnly<{|
  22. value: boolean,
  23. |}>;
  24. type NativeProps = $ReadOnly<{|
  25. ...ViewProps,
  26. // Props
  27. disabled?: WithDefault<boolean, false>,
  28. enabled?: WithDefault<boolean, true>,
  29. thumbColor?: ?ColorValue,
  30. trackColorForFalse?: ?ColorValue,
  31. trackColorForTrue?: ?ColorValue,
  32. value?: WithDefault<boolean, false>,
  33. on?: WithDefault<boolean, false>,
  34. thumbTintColor?: ?ColorValue,
  35. trackTintColor?: ?ColorValue,
  36. // Events
  37. onChange?: BubblingEventHandler<SwitchChangeEvent>,
  38. |}>;
  39. type NativeType = HostComponent<NativeProps>;
  40. interface NativeCommands {
  41. +setNativeValue: (
  42. viewRef: React.ElementRef<NativeType>,
  43. value: boolean,
  44. ) => void;
  45. }
  46. export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
  47. supportedCommands: ['setNativeValue'],
  48. });
  49. export default (codegenNativeComponent<NativeProps>('AndroidSwitch', {
  50. interfaceOnly: true,
  51. }): NativeType);