diff --git a/packages/react-native/Libraries/Components/Button.js b/packages/react-native/Libraries/Components/Button.js index 2b944380e1f49d..8ae7433bd84ea1 100644 --- a/packages/react-native/Libraries/Components/Button.js +++ b/packages/react-native/Libraries/Components/Button.js @@ -281,10 +281,12 @@ export type ButtonProps = $ReadOnly<{ ``` */ -const Touchable: typeof TouchableNativeFeedback | typeof TouchableOpacity = +const NativeTouchable: + | typeof TouchableNativeFeedback + | typeof TouchableOpacity = Platform.OS === 'android' ? TouchableNativeFeedback : TouchableOpacity; -type ButtonRef = React.ElementRef; +type ButtonRef = React.ElementRef; const Button: component( ref?: React.RefSetter, @@ -362,7 +364,7 @@ const Button: component( : importantForAccessibility; return ( - - + ); }; diff --git a/packages/react-native/Libraries/Components/Pressable/Pressable.js b/packages/react-native/Libraries/Components/Pressable/Pressable.js index ec2d1f6f892957..f994e0e929f4bc 100644 --- a/packages/react-native/Libraries/Components/Pressable/Pressable.js +++ b/packages/react-native/Libraries/Components/Pressable/Pressable.js @@ -8,6 +8,7 @@ * @format */ +import type {ViewStyleProp} from '../../StyleSheet/StyleSheet'; import type { GestureResponderEvent, LayoutChangeEvent, @@ -26,8 +27,6 @@ import useAndroidRippleForView, { import * as React from 'react'; import {memo, useMemo, useRef, useState} from 'react'; -type ViewStyleProp = React.ElementConfig['style']; - export type {PressableAndroidRippleConfig}; export type PressableStateCallbackType = $ReadOnly<{ diff --git a/packages/react-native/Libraries/Components/SafeAreaView/SafeAreaView.js b/packages/react-native/Libraries/Components/SafeAreaView/SafeAreaView.js index bee10606e30425..34097b8ea3b4f6 100644 --- a/packages/react-native/Libraries/Components/SafeAreaView/SafeAreaView.js +++ b/packages/react-native/Libraries/Components/SafeAreaView/SafeAreaView.js @@ -24,7 +24,7 @@ import * as React from 'react'; * sensor housing area on iPhone X). * @deprecated Use `react-native-safe-area-context` instead. This component will be removed in a future release. */ -const exported: component( +const SafeAreaView: component( ref?: React.RefSetter>, ...props: ViewProps ) = Platform.select({ @@ -32,4 +32,4 @@ const exported: component( default: View, }); -export default exported; +export default SafeAreaView; diff --git a/packages/react-native/Libraries/EventEmitter/NativeEventEmitter.js b/packages/react-native/Libraries/EventEmitter/NativeEventEmitter.js index a7453aa3fea119..00c5ecf8779371 100644 --- a/packages/react-native/Libraries/EventEmitter/NativeEventEmitter.js +++ b/packages/react-native/Libraries/EventEmitter/NativeEventEmitter.js @@ -32,7 +32,7 @@ export type {EventSubscription, EmitterSubscription}; export type NativeEventSubscription = EventSubscription; // $FlowFixMe[unclear-type] unclear type of events -type UnsafeObject = Object; +type UnsafeNativeEventObject = Object; /** * `NativeEventEmitter` is intended for use by Native Modules to emit events to @@ -46,8 +46,8 @@ type UnsafeObject = Object; */ export default class NativeEventEmitter< TEventToArgsMap: $ReadOnly< - Record>, - > = $ReadOnly>>, + Record>, + > = $ReadOnly>>, > implements IEventEmitter { _nativeModule: ?NativeModule; diff --git a/packages/react-native/Libraries/LayoutAnimation/LayoutAnimation.js b/packages/react-native/Libraries/LayoutAnimation/LayoutAnimation.js index 505a65b3de46a5..e8332b963d5369 100644 --- a/packages/react-native/Libraries/LayoutAnimation/LayoutAnimation.js +++ b/packages/react-native/Libraries/LayoutAnimation/LayoutAnimation.js @@ -45,7 +45,7 @@ type OnAnimationDidFailCallback = () => void; let isLayoutAnimationEnabled: boolean = ReactNativeFeatureFlags.isLayoutAnimationEnabled(); -function setEnabled(value: boolean) { +function setLayoutAnimationEnabled(value: boolean) { isLayoutAnimationEnabled = isLayoutAnimationEnabled; } @@ -115,7 +115,7 @@ function configureNext( } } -function create( +function createLayoutAnimation( duration: number, type?: LayoutAnimationType, property?: LayoutAnimationProperty, @@ -129,12 +129,16 @@ function create( } const Presets = { - easeInEaseOut: (create( + easeInEaseOut: (createLayoutAnimation( 300, 'easeInEaseOut', 'opacity', ): LayoutAnimationConfig), - linear: (create(500, 'linear', 'opacity'): LayoutAnimationConfig), + linear: (createLayoutAnimation( + 500, + 'linear', + 'opacity', + ): LayoutAnimationConfig), spring: ({ duration: 700, create: { @@ -180,7 +184,7 @@ const LayoutAnimation = { /** * Helper for creating a config for `configureNext`. */ - create, + create: createLayoutAnimation, Types: Object.freeze({ spring: 'spring', linear: 'linear', @@ -208,7 +212,7 @@ const LayoutAnimation = { spring: (configureNext.bind(null, Presets.spring): ( onAnimationDidEnd?: OnAnimationDidEndCallback, ) => void), - setEnabled, + setEnabled: setLayoutAnimationEnabled, }; export default LayoutAnimation; diff --git a/packages/react-native/Libraries/Lists/FlatList.js b/packages/react-native/Libraries/Lists/FlatList.js index f3e28fbce8c894..3835f5d44e90a8 100644 --- a/packages/react-native/Libraries/Lists/FlatList.js +++ b/packages/react-native/Libraries/Lists/FlatList.js @@ -15,6 +15,7 @@ import type { ListRenderItemInfo, ViewabilityConfigCallbackPair, ViewToken, + VirtualizedListProps, } from '@react-native/virtualized-lists'; import * as ReactNativeFeatureFlags from '../../src/private/featureflags/ReactNativeFeatureFlags'; @@ -181,8 +182,6 @@ type FlatListBaseProps = { ...OptionalProps, }; -type VirtualizedListProps = React.ElementConfig; - export type FlatListProps = { ...Omit< VirtualizedListProps, diff --git a/packages/react-native/Libraries/PermissionsAndroid/PermissionsAndroid.js b/packages/react-native/Libraries/PermissionsAndroid/PermissionsAndroid.js index 16e4899ff1c7f1..886a8498c9c130 100644 --- a/packages/react-native/Libraries/PermissionsAndroid/PermissionsAndroid.js +++ b/packages/react-native/Libraries/PermissionsAndroid/PermissionsAndroid.js @@ -130,7 +130,7 @@ const PERMISSIONS = Object.freeze({ * * See https://reactnative.dev/docs/permissionsandroid */ -class PermissionsAndroid { +class PermissionsAndroidImpl { PERMISSIONS: PermissionsType = PERMISSIONS; RESULTS: $ReadOnly<{ DENIED: 'denied', @@ -297,5 +297,6 @@ class PermissionsAndroid { } } -const PermissionsAndroidInstance: PermissionsAndroid = new PermissionsAndroid(); +const PermissionsAndroidInstance: PermissionsAndroidImpl = + new PermissionsAndroidImpl(); export default PermissionsAndroidInstance; diff --git a/packages/react-native/Libraries/ReactNative/AppRegistry.flow.js b/packages/react-native/Libraries/ReactNative/AppRegistry.flow.js index 4b15f8f218d30c..d766debf21f508 100644 --- a/packages/react-native/Libraries/ReactNative/AppRegistry.flow.js +++ b/packages/react-native/Libraries/ReactNative/AppRegistry.flow.js @@ -13,8 +13,8 @@ import type {RootTag} from '../Types/RootTagTypes'; import type {IPerformanceLogger} from '../Utilities/createPerformanceLogger'; import type {DisplayModeType} from './DisplayMode'; -type Task = (taskData: any) => Promise; -export type TaskProvider = () => Task; +type HeadlessTask = (taskData: any) => Promise; +export type TaskProvider = () => HeadlessTask; export type ComponentProvider = () => React.ComponentType; export type ComponentProviderInstrumentationHook = ( diff --git a/packages/react-native/Libraries/Utilities/NativeDeviceInfo.js b/packages/react-native/Libraries/Utilities/NativeDeviceInfo.js index 172f4201d2ba7e..f43454b6cf5347 100644 --- a/packages/react-native/Libraries/Utilities/NativeDeviceInfo.js +++ b/packages/react-native/Libraries/Utilities/NativeDeviceInfo.js @@ -9,6 +9,4 @@ */ export * from '../../src/private/specs_DEPRECATED/modules/NativeDeviceInfo'; -import NativeDeviceInfo from '../../src/private/specs_DEPRECATED/modules/NativeDeviceInfo'; - -export default NativeDeviceInfo; +export {default} from '../../src/private/specs_DEPRECATED/modules/NativeDeviceInfo'; diff --git a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap index 6243b50bfeff85..9dc90db3270e81 100644 --- a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap +++ b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap @@ -1538,10 +1538,10 @@ exports[`public API should not change unintentionally Libraries/Components/Butto accessibilityHint?: ?string, accessibilityLanguage?: ?Stringish, }>; -declare const Touchable: +declare const NativeTouchable: | typeof TouchableNativeFeedback | typeof TouchableOpacity; -type ButtonRef = React.ElementRef; +type ButtonRef = React.ElementRef; declare const Button: component( ref?: React.RefSetter, ...props: ButtonProps @@ -1757,8 +1757,7 @@ declare export default typeof LayoutConformanceNativeComponent; `; exports[`public API should not change unintentionally Libraries/Components/Pressable/Pressable.js 1`] = ` -"type ViewStyleProp = React.ElementConfig[\\"style\\"]; -export type { PressableAndroidRippleConfig }; +"export type { PressableAndroidRippleConfig }; export type PressableStateCallbackType = $ReadOnly<{ pressed: boolean, }>; @@ -1932,11 +1931,11 @@ export { default } from \\"../../../src/private/specs_DEPRECATED/components/RCTS `; exports[`public API should not change unintentionally Libraries/Components/SafeAreaView/SafeAreaView.js 1`] = ` -"declare const exported: component( +"declare const SafeAreaView: component( ref?: React.RefSetter>, ...props: ViewProps ); -declare export default typeof exported; +declare export default typeof SafeAreaView; " `; @@ -4179,11 +4178,11 @@ exports[`public API should not change unintentionally Libraries/EventEmitter/Nat type EmitterSubscription = EventSubscription; export type { EventSubscription, EmitterSubscription }; export type NativeEventSubscription = EventSubscription; -type UnsafeObject = Object; +type UnsafeNativeEventObject = Object; declare export default class NativeEventEmitter< TEventToArgsMap: $ReadOnly< - Record>, - > = $ReadOnly>>, + Record>, + > = $ReadOnly>>, > implements IEventEmitter { constructor(nativeModule?: ?NativeModule): void; @@ -4859,13 +4858,13 @@ export type LayoutAnimationProperties = $ReadOnly<{ }>; type OnAnimationDidEndCallback = () => void; type OnAnimationDidFailCallback = () => void; -declare function setEnabled(value: boolean): void; +declare function setLayoutAnimationEnabled(value: boolean): void; declare function configureNext( config: LayoutAnimationConfig, onAnimationDidEnd?: OnAnimationDidEndCallback, onAnimationDidFail?: OnAnimationDidFailCallback ): void; -declare function create( +declare function createLayoutAnimation( duration: number, type?: LayoutAnimationType, property?: LayoutAnimationProperty @@ -4877,7 +4876,7 @@ declare const Presets: { }; declare const LayoutAnimation: { configureNext: typeof configureNext, - create: typeof create, + create: typeof createLayoutAnimation, Types: LayoutAnimationTypes, Properties: LayoutAnimationProperties, checkConfig(...args: Array): void, @@ -4885,7 +4884,7 @@ declare const LayoutAnimation: { easeInEaseOut: (onAnimationDidEnd?: OnAnimationDidEndCallback) => void, linear: (onAnimationDidEnd?: OnAnimationDidEndCallback) => void, spring: (onAnimationDidEnd?: OnAnimationDidEndCallback) => void, - setEnabled: typeof setEnabled, + setEnabled: typeof setLayoutAnimationEnabled, }; declare export default typeof LayoutAnimation; " @@ -4940,8 +4939,7 @@ declare export default typeof FillRateHelper; `; exports[`public API should not change unintentionally Libraries/Lists/FlatList.js 1`] = ` -"declare const VirtualizedList: typeof VirtualizedLists.VirtualizedList; -type RequiredProps = { +"type RequiredProps = { data: ?$ReadOnly<$ArrayLike>, }; type OptionalProps = { @@ -4971,7 +4969,6 @@ type FlatListBaseProps = { ...RequiredProps, ...OptionalProps, }; -type VirtualizedListProps = React.ElementConfig; export type FlatListProps = { ...Omit< VirtualizedListProps, @@ -6147,7 +6144,7 @@ type PermissionsType = $ReadOnly<{ }>; export type PermissionStatus = \\"granted\\" | \\"denied\\" | \\"never_ask_again\\"; export type Permission = $Values; -declare class PermissionsAndroid { +declare class PermissionsAndroidImpl { PERMISSIONS: PermissionsType; RESULTS: $ReadOnly<{ DENIED: \\"denied\\", @@ -6168,7 +6165,7 @@ declare class PermissionsAndroid { permissions: Array ): Promise<{ [permission: Permission]: PermissionStatus, ... }>; } -declare const PermissionsAndroidInstance: PermissionsAndroid; +declare const PermissionsAndroidInstance: PermissionsAndroidImpl; declare export default typeof PermissionsAndroidInstance; " `; @@ -6434,8 +6431,8 @@ declare export default typeof AppContainer; `; exports[`public API should not change unintentionally Libraries/ReactNative/AppRegistry.flow.js 1`] = ` -"type Task = (taskData: any) => Promise; -export type TaskProvider = () => Task; +"type HeadlessTask = (taskData: any) => Promise; +export type TaskProvider = () => HeadlessTask; export type ComponentProvider = () => React.ComponentType; export type ComponentProviderInstrumentationHook = ( component_: ComponentProvider, @@ -8365,7 +8362,7 @@ declare export default typeof NativeDevLoadingView; exports[`public API should not change unintentionally Libraries/Utilities/NativeDeviceInfo.js 1`] = ` "export * from \\"../../src/private/specs_DEPRECATED/modules/NativeDeviceInfo\\"; -declare export default typeof NativeDeviceInfo; +export { default } from \\"../../src/private/specs_DEPRECATED/modules/NativeDeviceInfo\\"; " `; @@ -8961,12 +8958,12 @@ declare export default ErrorUtils; `; exports[`public API should not change unintentionally Libraries/vendor/emitter/EventEmitter.js 1`] = ` -"type UnsafeObject = Object; +"type UnsafeEventObject = Object; export interface EventSubscription { remove(): void; } export interface IEventEmitter< - TEventToArgsMap: $ReadOnly>>, + TEventToArgsMap: $ReadOnly>>, > { addListener>( eventType: TEvent, @@ -8982,8 +8979,8 @@ export interface IEventEmitter< } declare export default class EventEmitter< TEventToArgsMap: $ReadOnly< - Record>, - > = $ReadOnly>>, + Record>, + > = $ReadOnly>>, > implements IEventEmitter { constructor(): void; diff --git a/packages/react-native/Libraries/vendor/emitter/EventEmitter.js b/packages/react-native/Libraries/vendor/emitter/EventEmitter.js index 545bafe0ee81bc..01dcd481796a49 100644 --- a/packages/react-native/Libraries/vendor/emitter/EventEmitter.js +++ b/packages/react-native/Libraries/vendor/emitter/EventEmitter.js @@ -9,14 +9,14 @@ */ // $FlowFixMe[unclear-type] unclear type of events -type UnsafeObject = Object; +type UnsafeEventObject = Object; export interface EventSubscription { remove(): void; } export interface IEventEmitter< - TEventToArgsMap: $ReadOnly>>, + TEventToArgsMap: $ReadOnly>>, > { addListener>( eventType: TEvent, @@ -41,7 +41,7 @@ interface Registration { } type Registry< - TEventToArgsMap: $ReadOnly>>, + TEventToArgsMap: $ReadOnly>>, > = { [K in keyof TEventToArgsMap]: Set>, }; @@ -68,8 +68,8 @@ type Registry< */ export default class EventEmitter< TEventToArgsMap: $ReadOnly< - Record>, - > = $ReadOnly>>, + Record>, + > = $ReadOnly>>, > implements IEventEmitter { #registry: Registry; @@ -157,7 +157,7 @@ export default class EventEmitter< } function allocate< - TEventToArgsMap: $ReadOnly>>, + TEventToArgsMap: $ReadOnly>>, TEvent: $Keys, TEventArgs: TEventToArgsMap[TEvent], >( diff --git a/packages/react-native/src/private/specs_DEPRECATED/components/SwitchNativeComponent.js b/packages/react-native/src/private/specs_DEPRECATED/components/SwitchNativeComponent.js index 5d5d784d6bcb10..6ddb0cb20d977e 100644 --- a/packages/react-native/src/private/specs_DEPRECATED/components/SwitchNativeComponent.js +++ b/packages/react-native/src/private/specs_DEPRECATED/components/SwitchNativeComponent.js @@ -21,7 +21,7 @@ import codegenNativeCommands from '../../../../Libraries/Utilities/codegenNative import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent'; import * as React from 'react'; -type SwitchChangeEvent = $ReadOnly<{ +type NativeSwitchChangeEvent = $ReadOnly<{ value: boolean, target: Int32, }>; @@ -42,7 +42,7 @@ type SwitchNativeProps = $ReadOnly<{ trackColorForTrue?: ?ColorValue, // Events - onChange?: ?BubblingEventHandler, + onChange?: ?BubblingEventHandler, }>; type ComponentType = HostComponent; diff --git a/packages/virtualized-lists/Lists/VirtualizedSectionList.js b/packages/virtualized-lists/Lists/VirtualizedSectionList.js index 4e6331bb3f6c53..9f4796467b72d3 100644 --- a/packages/virtualized-lists/Lists/VirtualizedSectionList.js +++ b/packages/virtualized-lists/Lists/VirtualizedSectionList.js @@ -17,17 +17,17 @@ import invariant from 'invariant'; import * as React from 'react'; import {useEffect, useState} from 'react'; -type DefaultSectionT = { +type DefaultVirtualizedSectionT = { data: any, [key: string]: any, }; -export type SectionData = +export type SectionData = | ($ReadOnly> & SectionT) | (SectionBase & SectionT) | SectionT; -export type SectionBase = { +export type SectionBase = { /** * The data for rendering items in this section. */ @@ -55,11 +55,11 @@ export type SectionBase = { ... }; -type RequiredProps = { +type RequiredProps = { sections: $ReadOnlyArray>, }; -type OptionalProps = { +type OptionalProps = { /** * Default renderer for every item in every section. */ @@ -100,7 +100,10 @@ type OptionalProps = { onEndReached?: ?({distanceFromEnd: number, ...}) => void, }; -export type VirtualizedSectionListProps = { +export type VirtualizedSectionListProps< + ItemT, + SectionT = DefaultVirtualizedSectionT, +> = { ...RequiredProps, ...OptionalProps, ...Omit, @@ -122,7 +125,10 @@ type State = {childProps: VirtualizedListProps, ...}; */ class VirtualizedSectionList< ItemT, - SectionT: SectionBase = DefaultSectionT, + SectionT: SectionBase< + ItemT, + DefaultVirtualizedSectionT, + > = DefaultVirtualizedSectionT, > extends React.PureComponent< VirtualizedSectionListProps, State, @@ -613,7 +619,10 @@ function ItemWithSeparator( const VirtualizedSectionListComponent = VirtualizedSectionList as component< ItemT, - SectionT: SectionBase = DefaultSectionT, + SectionT: SectionBase< + ItemT, + DefaultVirtualizedSectionT, + > = DefaultVirtualizedSectionT, >( ref: React.RefSetter< interface {