RCTPickerNativeComponent.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. const requireNativeComponent = require('../../ReactNative/requireNativeComponent');
  12. import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes';
  13. import type {SyntheticEvent} from '../../Types/CoreEventTypes';
  14. import type {TextStyleProp} from '../../StyleSheet/StyleSheet';
  15. import type {ProcessedColorValue} from '../../StyleSheet/processColor';
  16. import codegenNativeCommands from '../../Utilities/codegenNativeCommands';
  17. import * as React from 'react';
  18. type PickerIOSChangeEvent = SyntheticEvent<
  19. $ReadOnly<{|
  20. newValue: number | string,
  21. newIndex: number,
  22. |}>,
  23. >;
  24. type RCTPickerIOSItemType = $ReadOnly<{|
  25. label: ?Label,
  26. value: ?(number | string),
  27. textColor: ?ProcessedColorValue,
  28. |}>;
  29. type Label = Stringish | number;
  30. type NativeProps = $ReadOnly<{|
  31. items: $ReadOnlyArray<RCTPickerIOSItemType>,
  32. onChange: (event: PickerIOSChangeEvent) => void,
  33. selectedIndex: number,
  34. style?: ?TextStyleProp,
  35. testID?: ?string,
  36. accessibilityLabel?: ?string,
  37. |}>;
  38. type ComponentType = HostComponent<NativeProps>;
  39. interface NativeCommands {
  40. +setNativeSelectedIndex: (
  41. viewRef: React.ElementRef<ComponentType>,
  42. index: number,
  43. ) => void;
  44. }
  45. export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
  46. supportedCommands: ['setNativeSelectedIndex'],
  47. });
  48. const RCTPickerNativeComponent: ComponentType = requireNativeComponent<NativeProps>(
  49. 'RCTPicker',
  50. );
  51. export default RCTPickerNativeComponent;