From 4f94028ca686cac8bf2b772de518d385879dbb06 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Wed, 25 Jun 2025 00:16:24 -0700 Subject: [PATCH] Reduce symbol collisions in the API snapshot (#52213) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/52213 Changelog: [Internal] Reviewed By: huntie Differential Revision: D77207979 fbshipit-source-id: 10d8b9c8f24ddb52423197f5aa300402b1e45ebe --- .../Libraries/Components/Button.js | 10 +++--- .../EventEmitter/NativeEventEmitter.js | 6 ++-- .../LayoutAnimation/LayoutAnimation.js | 16 +++++---- .../react-native/Libraries/Lists/FlatList.js | 5 ++- .../PermissionsAndroid/PermissionsAndroid.js | 5 +-- .../Libraries/ReactNative/AppRegistry.flow.js | 4 +-- .../Libraries/Utilities/NativeDeviceInfo.js | 4 +-- .../__snapshots__/public-api-test.js.snap | 36 +++++++++---------- .../Libraries/vendor/emitter/EventEmitter.js | 12 +++---- .../components/SwitchNativeComponent.js | 4 +-- .../Lists/VirtualizedSectionList.js | 25 ++++++++----- 11 files changed, 70 insertions(+), 57 deletions(-) diff --git a/packages/react-native/Libraries/Components/Button.js b/packages/react-native/Libraries/Components/Button.js index 2b944380e1f..8ae7433bd84 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/EventEmitter/NativeEventEmitter.js b/packages/react-native/Libraries/EventEmitter/NativeEventEmitter.js index a7453aa3fea..00c5ecf8779 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 505a65b3de4..e8332b963d5 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 32d3fd20e94..3835f5d44e9 100644 --- a/packages/react-native/Libraries/Lists/FlatList.js +++ b/packages/react-native/Libraries/Lists/FlatList.js @@ -15,14 +15,13 @@ import type { ListRenderItemInfo, ViewabilityConfigCallbackPair, ViewToken, + VirtualizedListProps, } from '@react-native/virtualized-lists'; import * as ReactNativeFeatureFlags from '../../src/private/featureflags/ReactNativeFeatureFlags'; import {type ScrollResponderType} from '../Components/ScrollView/ScrollView'; import View from '../Components/View/View'; -import VirtualizedLists, { - type VirtualizedListProps, -} from '@react-native/virtualized-lists'; +import VirtualizedLists from '@react-native/virtualized-lists'; import memoizeOne from 'memoize-one'; import * as React from 'react'; diff --git a/packages/react-native/Libraries/PermissionsAndroid/PermissionsAndroid.js b/packages/react-native/Libraries/PermissionsAndroid/PermissionsAndroid.js index 16e4899ff1c..886a8498c9c 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 4b15f8f218d..d766debf21f 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 172f4201d2b..f43454b6cf5 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 6145e6ac40c..e8404c0c529 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 @@ -1539,10 +1539,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 @@ -4179,11 +4179,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 +4859,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 +4877,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 +4885,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; " @@ -6145,7 +6145,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\\", @@ -6166,7 +6166,7 @@ declare class PermissionsAndroid { permissions: Array ): Promise<{ [permission: Permission]: PermissionStatus, ... }>; } -declare const PermissionsAndroidInstance: PermissionsAndroid; +declare const PermissionsAndroidInstance: PermissionsAndroidImpl; declare export default typeof PermissionsAndroidInstance; " `; @@ -6432,8 +6432,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, @@ -8363,7 +8363,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\\"; " `; @@ -8959,12 +8959,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, @@ -8980,8 +8980,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 545bafe0ee8..01dcd481796 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 5d5d784d6bc..6ddb0cb20d9 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 4e6331bb3f6..9f4796467b7 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 {