Skip to content

Commit

Permalink
Add Flow type for ActivityIndicator
Browse files Browse the repository at this point in the history
Summary: Changelog: [Internal] - Add a type definition for ActivityIndicator

Reviewed By: NickGerleman

Differential Revision: D38850509

fbshipit-source-id: c3ca50be8fbcec0f0f43b036f8768f4462fa4991
  • Loading branch information
Luna Wei authored and facebook-github-bot committed Aug 24, 2022
1 parent 355feaf commit 6f60c5f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
57 changes: 57 additions & 0 deletions Libraries/Components/ActivityIndicator/ActivityIndicator.flow.js
Original file line number Diff line number Diff line change
@@ -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<mixed>,
>;
8 changes: 3 additions & 5 deletions Libraries/Components/ActivityIndicator/ActivityIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -183,10 +183,8 @@ const ActivityIndicator = (
```
*/

const ActivityIndicatorWithRef: React.AbstractComponent<
Props,
HostComponent<mixed>,
> = React.forwardRef(ActivityIndicator);
const ActivityIndicatorWithRef: ActivityIndicatorType =
React.forwardRef(ActivityIndicator);
ActivityIndicatorWithRef.displayName = 'ActivityIndicator';

const styles = StyleSheet.create({
Expand Down

0 comments on commit 6f60c5f

Please sign in to comment.