AndroidDialogPickerNativeComponent.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. * @format
  8. * @flow strict-local
  9. */
  10. 'use strict';
  11. import * as React from 'react';
  12. import codegenNativeCommands from '../../Utilities/codegenNativeCommands';
  13. import requireNativeComponent from '../../ReactNative/requireNativeComponent';
  14. import type {
  15. DirectEventHandler,
  16. Int32,
  17. WithDefault,
  18. } from '../../Types/CodegenTypes';
  19. import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes';
  20. import type {TextStyleProp} from '../../StyleSheet/StyleSheet';
  21. import type {ColorValue} from '../../StyleSheet/StyleSheetTypes';
  22. import type {ProcessedColorValue} from '../../StyleSheet/processColor';
  23. import type {ViewProps} from '../../Components/View/ViewPropTypes';
  24. type PickerItem = $ReadOnly<{|
  25. label: string,
  26. color?: ?ProcessedColorValue,
  27. |}>;
  28. type PickerItemSelectEvent = $ReadOnly<{|
  29. position: Int32,
  30. |}>;
  31. type NativeProps = $ReadOnly<{|
  32. ...ViewProps,
  33. style?: ?TextStyleProp,
  34. // Props
  35. color?: ?ColorValue,
  36. backgroundColor?: ?ColorValue,
  37. enabled?: WithDefault<boolean, true>,
  38. items: $ReadOnlyArray<PickerItem>,
  39. prompt?: WithDefault<string, ''>,
  40. selected: Int32,
  41. // Events
  42. onSelect?: DirectEventHandler<PickerItemSelectEvent>,
  43. |}>;
  44. type NativeType = HostComponent<NativeProps>;
  45. interface NativeCommands {
  46. +setNativeSelectedPosition: (
  47. viewRef: React.ElementRef<NativeType>,
  48. index: number,
  49. ) => void;
  50. }
  51. export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
  52. supportedCommands: ['setNativeSelectedPosition'],
  53. });
  54. export default (requireNativeComponent<NativeProps>(
  55. 'AndroidDialogPicker',
  56. ): NativeType);