AndroidSwipeRefreshLayoutNativeComponent.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 'react-native/Libraries/Utilities/codegenNativeCommands';
  13. import codegenNativeComponent from '../../Utilities/codegenNativeComponent';
  14. import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes';
  15. import type {
  16. DirectEventHandler,
  17. Float,
  18. Int32,
  19. WithDefault,
  20. } from '../../Types/CodegenTypes';
  21. import type {ColorValue} from '../../StyleSheet/StyleSheetTypes';
  22. import type {ViewProps} from '../View/ViewPropTypes';
  23. type NativeProps = $ReadOnly<{|
  24. ...ViewProps,
  25. /**
  26. * Whether the pull to refresh functionality is enabled.
  27. */
  28. enabled?: WithDefault<boolean, true>,
  29. /**
  30. * The colors (at least one) that will be used to draw the refresh indicator.
  31. */
  32. colors?: ?$ReadOnlyArray<ColorValue>,
  33. /**
  34. * The background color of the refresh indicator.
  35. */
  36. progressBackgroundColor?: ?ColorValue,
  37. /**
  38. * Size of the refresh indicator, see RefreshControl.SIZE.
  39. *
  40. * This type isn't currently accurate. It really is specific numbers
  41. * hard coded in the Android platform.
  42. *
  43. * Also, 1 isn't actually a safe default. We are able to set this here
  44. * because native code isn't currently consuming the generated artifact.
  45. * This will end up being
  46. * size?: WithDefault<'default' | 'large', 'default'>,
  47. */
  48. size?: WithDefault<Int32, 1>,
  49. /**
  50. * Progress view top offset
  51. */
  52. progressViewOffset?: WithDefault<Float, 0>,
  53. /**
  54. * Called when the view starts refreshing.
  55. */
  56. onRefresh?: ?DirectEventHandler<null>,
  57. /**
  58. * Whether the view should be indicating an active refresh.
  59. */
  60. refreshing: boolean,
  61. |}>;
  62. type NativeType = HostComponent<NativeProps>;
  63. interface NativeCommands {
  64. +setNativeRefreshing: (
  65. viewRef: React.ElementRef<NativeType>,
  66. value: boolean,
  67. ) => void;
  68. }
  69. export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
  70. supportedCommands: ['setNativeRefreshing'],
  71. });
  72. export default (codegenNativeComponent<NativeProps>(
  73. 'AndroidSwipeRefreshLayout',
  74. ): NativeType);