From 9c57a7f20925765da69590256ca8755b71735cdb Mon Sep 17 00:00:00 2001 From: Luna Wei Date: Tue, 3 Jan 2023 18:09:06 -0800 Subject: [PATCH] ESM ActivityIndicator Summary: Changelog: [General][Changed] ActivityIndicator and remove .flow Reviewed By: yungsters Differential Revision: D42203449 fbshipit-source-id: 52ab1111166d23b7304e8406f299d23f9fd6f399 --- .../ActivityIndicator.flow.js | 58 ------------------- .../ActivityIndicator/ActivityIndicator.js | 10 ++-- .../__tests__/ActivityIndicator-test.js | 5 +- index.js | 3 +- jest/setup.js | 9 ++- 5 files changed, 17 insertions(+), 68 deletions(-) delete mode 100644 Libraries/Components/ActivityIndicator/ActivityIndicator.flow.js diff --git a/Libraries/Components/ActivityIndicator/ActivityIndicator.flow.js b/Libraries/Components/ActivityIndicator/ActivityIndicator.flow.js deleted file mode 100644 index ebfb8272cb2579..00000000000000 --- a/Libraries/Components/ActivityIndicator/ActivityIndicator.flow.js +++ /dev/null @@ -1,58 +0,0 @@ -/** - * 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 type {HostComponent} from '../../Renderer/shims/ReactNativeTypes'; -import type {ViewProps} from '../View/ViewPropTypes'; - -import {type ColorValue} from '../../StyleSheet/StyleSheet'; -import * as React from 'react'; - -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 0b57dc1273bd29..655d13d67ce4d6 100644 --- a/Libraries/Components/ActivityIndicator/ActivityIndicator.js +++ b/Libraries/Components/ActivityIndicator/ActivityIndicator.js @@ -10,8 +10,8 @@ */ 'use strict'; +import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes'; import type {ViewProps} from '../View/ViewPropTypes'; -import type {ActivityIndicator as ActivityIndicatorType} from './ActivityIndicator.flow'; import StyleSheet, {type ColorValue} from '../../StyleSheet/StyleSheet'; import Platform from '../../Utilities/Platform'; @@ -184,8 +184,10 @@ const ActivityIndicator = ( ``` */ -const ActivityIndicatorWithRef: ActivityIndicatorType = - React.forwardRef(ActivityIndicator); +const ActivityIndicatorWithRef: React.AbstractComponent< + Props, + HostComponent, +> = React.forwardRef(ActivityIndicator); ActivityIndicatorWithRef.displayName = 'ActivityIndicator'; const styles = StyleSheet.create({ @@ -203,4 +205,4 @@ const styles = StyleSheet.create({ }, }); -module.exports = ActivityIndicatorWithRef; +export default ActivityIndicatorWithRef; diff --git a/Libraries/Components/ActivityIndicator/__tests__/ActivityIndicator-test.js b/Libraries/Components/ActivityIndicator/__tests__/ActivityIndicator-test.js index 1c1338618976d8..e2e3657cb4a18b 100644 --- a/Libraries/Components/ActivityIndicator/__tests__/ActivityIndicator-test.js +++ b/Libraries/Components/ActivityIndicator/__tests__/ActivityIndicator-test.js @@ -11,9 +11,10 @@ 'use strict'; +import * as React from 'react'; + const ReactNativeTestTools = require('../../../Utilities/ReactNativeTestTools'); -const ActivityIndicator = require('../ActivityIndicator'); -const React = require('react'); +const ActivityIndicator = require('../ActivityIndicator').default; describe('', () => { it('should set displayName to prevent regressions', () => { diff --git a/index.js b/index.js index 7965754840d252..9cdf616821c1f3 100644 --- a/index.js +++ b/index.js @@ -108,7 +108,8 @@ module.exports = { .default; }, get ActivityIndicator(): ActivityIndicator { - return require('./Libraries/Components/ActivityIndicator/ActivityIndicator'); + return require('./Libraries/Components/ActivityIndicator/ActivityIndicator') + .default; }, get Button(): Button { return require('./Libraries/Components/Button'); diff --git a/jest/setup.js b/jest/setup.js index 93745e789adc23..3112707451595c 100644 --- a/jest/setup.js +++ b/jest/setup.js @@ -164,11 +164,14 @@ jest const mockScrollView = jest.requireActual('./mockScrollView'); return mockScrollView(baseComponent); }) - .mock('../Libraries/Components/ActivityIndicator/ActivityIndicator', () => - mockComponent( + .mock('../Libraries/Components/ActivityIndicator/ActivityIndicator', () => ({ + __esModule: true, + default: mockComponent( '../Libraries/Components/ActivityIndicator/ActivityIndicator', + null, + true, ), - ) + })) .mock('../Libraries/AppState/AppState', () => ({ addEventListener: jest.fn(() => ({ remove: jest.fn(),