From 6f60c5f3cd5f1d2f1daeb6b0c118f3fc4eb3a73c Mon Sep 17 00:00:00 2001 From: Luna Wei Date: Wed, 24 Aug 2022 15:18:45 -0700 Subject: [PATCH] Add Flow type for ActivityIndicator Summary: Changelog: [Internal] - Add a type definition for ActivityIndicator Reviewed By: NickGerleman Differential Revision: D38850509 fbshipit-source-id: c3ca50be8fbcec0f0f43b036f8768f4462fa4991 --- .../ActivityIndicator.flow.js | 57 +++++++++++++++++++ .../ActivityIndicator/ActivityIndicator.js | 8 +-- 2 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 Libraries/Components/ActivityIndicator/ActivityIndicator.flow.js diff --git a/Libraries/Components/ActivityIndicator/ActivityIndicator.flow.js b/Libraries/Components/ActivityIndicator/ActivityIndicator.flow.js new file mode 100644 index 00000000000000..712a5b69410215 --- /dev/null +++ b/Libraries/Components/ActivityIndicator/ActivityIndicator.flow.js @@ -0,0 +1,57 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow + */ + +'use strict'; +import * as React from 'react'; +import {type ColorValue} from '../../StyleSheet/StyleSheet'; +import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes'; +import type {ViewProps} from '../View/ViewPropTypes'; + +type IndicatorSize = number | 'small' | 'large'; + +type IOSProps = $ReadOnly<{| + /** + Whether the indicator should hide when not animating. + + @platform ios + */ + hidesWhenStopped?: ?boolean, +|}>; + +type Props = $ReadOnly<{| + ...ViewProps, + ...IOSProps, + + /** + Whether to show the indicator (`true`) or hide it (`false`). + */ + animating?: ?boolean, + + /** + The foreground color of the spinner. + + @default {@platform android} `null` (system accent default color) + @default {@platform ios} '#999999' + */ + color?: ?ColorValue, + + /** + Size of the indicator. + + @type enum(`'small'`, `'large'`) + @type {@platform android} number + */ + size?: ?IndicatorSize, +|}>; + +export type ActivityIndicator = React.AbstractComponent< + Props, + HostComponent, +>; diff --git a/Libraries/Components/ActivityIndicator/ActivityIndicator.js b/Libraries/Components/ActivityIndicator/ActivityIndicator.js index eb8b733e15a2cd..1c4fbd67f5d60a 100644 --- a/Libraries/Components/ActivityIndicator/ActivityIndicator.js +++ b/Libraries/Components/ActivityIndicator/ActivityIndicator.js @@ -14,8 +14,8 @@ import * as React from 'react'; import Platform from '../../Utilities/Platform'; import StyleSheet, {type ColorValue} from '../../StyleSheet/StyleSheet'; import View from '../View/View'; -import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes'; import type {ViewProps} from '../View/ViewPropTypes'; +import type {ActivityIndicator as ActivityIndicatorType} from './ActivityIndicator.flow'; const PlatformActivityIndicator = Platform.OS === 'android' @@ -183,10 +183,8 @@ const ActivityIndicator = ( ``` */ -const ActivityIndicatorWithRef: React.AbstractComponent< - Props, - HostComponent, -> = React.forwardRef(ActivityIndicator); +const ActivityIndicatorWithRef: ActivityIndicatorType = + React.forwardRef(ActivityIndicator); ActivityIndicatorWithRef.displayName = 'ActivityIndicator'; const styles = StyleSheet.create({