AndroidCheckBoxNativeComponent.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
  13. const requireNativeComponent = require('../../ReactNative/requireNativeComponent');
  14. import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes';
  15. import type {ViewProps} from '../View/ViewPropTypes';
  16. import type {SyntheticEvent} from '../../Types/CoreEventTypes';
  17. import type {ProcessedColorValue} from '../../StyleSheet/processColor';
  18. type CheckBoxEvent = SyntheticEvent<
  19. $ReadOnly<{|
  20. target: number,
  21. value: boolean,
  22. |}>,
  23. >;
  24. type NativeProps = $ReadOnly<{|
  25. ...ViewProps,
  26. /**
  27. * Used in case the props change removes the component.
  28. */
  29. onChange?: ?(event: CheckBoxEvent) => mixed,
  30. /**
  31. * Invoked with the new value when the value changes.
  32. */
  33. onValueChange?: ?(value: boolean) => mixed,
  34. /**
  35. * Used to locate this view in end-to-end tests.
  36. */
  37. testID?: ?string,
  38. on?: ?boolean,
  39. enabled?: boolean,
  40. tintColors:
  41. | {|
  42. true: ?ProcessedColorValue,
  43. false: ?ProcessedColorValue,
  44. |}
  45. | typeof undefined,
  46. |}>;
  47. type NativeType = HostComponent<NativeProps>;
  48. interface NativeCommands {
  49. +setNativeValue: (
  50. viewRef: React.ElementRef<NativeType>,
  51. value: boolean,
  52. ) => void;
  53. }
  54. export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
  55. supportedCommands: ['setNativeValue'],
  56. });
  57. export default (requireNativeComponent<NativeProps>(
  58. 'AndroidCheckBox',
  59. ): NativeType);