From 7959a63a1a18c2f45ea8674e3b08a164e6301029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ma=C5=82ecki?= Date: Tue, 29 Apr 2025 06:06:16 -0700 Subject: [PATCH] Migrate `rn-tester` codegen types imports to use root exported `CodegenTypes` namespace (#50976) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/50976 This is the second part of the migration of `rn-tester` package to use root imports. In this diff the `CodegenTypes` namespace is used to define Codegen primitives. Changelog: [Internal] Reviewed By: huntie Differential Revision: D73780584 fbshipit-source-id: c13c2dfcfa4d023978a9463af1d2a3bf7b72476c --- .../js/MyNativeViewNativeComponent.js | 26 +++++++------------ .../NativeCxxModuleExample.js | 13 +++++----- .../NativeScreenshotManager.js | 5 ++-- 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/packages/rn-tester/NativeComponentExample/js/MyNativeViewNativeComponent.js b/packages/rn-tester/NativeComponentExample/js/MyNativeViewNativeComponent.js index 10ca618c3e9..ea136a67b8d 100644 --- a/packages/rn-tester/NativeComponentExample/js/MyNativeViewNativeComponent.js +++ b/packages/rn-tester/NativeComponentExample/js/MyNativeViewNativeComponent.js @@ -8,26 +8,20 @@ * @format */ -import type {HostComponent, ViewProps} from 'react-native'; -import type { - BubblingEventHandler, - Double, - Float, - Int32, -} from 'react-native/Libraries/Types/CodegenTypes'; +import type {CodegenTypes, HostComponent, ViewProps} from 'react-native'; import * as React from 'react'; import {codegenNativeCommands, codegenNativeComponent} from 'react-native'; type Event = $ReadOnly<{ - values: $ReadOnlyArray, + values: $ReadOnlyArray, boolValues: $ReadOnlyArray, - floats: $ReadOnlyArray, - doubles: $ReadOnlyArray, + floats: $ReadOnlyArray, + doubles: $ReadOnlyArray, yesNos: $ReadOnlyArray<'yep' | 'nope'>, strings: $ReadOnlyArray, - latLons: $ReadOnlyArray<{lat: Double, lon: Double}>, - multiArrays: $ReadOnlyArray<$ReadOnlyArray>, + latLons: $ReadOnlyArray<{lat: CodegenTypes.Double, lon: CodegenTypes.Double}>, + multiArrays: $ReadOnlyArray<$ReadOnlyArray>, }>; type LegacyStyleEvent = $ReadOnly<{ @@ -36,12 +30,12 @@ type LegacyStyleEvent = $ReadOnly<{ type NativeProps = $ReadOnly<{ ...ViewProps, - opacity?: Float, - values: $ReadOnlyArray, + opacity?: CodegenTypes.Float, + values: $ReadOnlyArray, // Events - onIntArrayChanged?: ?BubblingEventHandler, - onLegacyStyleEvent?: ?BubblingEventHandler< + onIntArrayChanged?: ?CodegenTypes.BubblingEventHandler, + onLegacyStyleEvent?: ?CodegenTypes.BubblingEventHandler< LegacyStyleEvent, 'alternativeLegacyName', >, diff --git a/packages/rn-tester/NativeCxxModuleExample/NativeCxxModuleExample.js b/packages/rn-tester/NativeCxxModuleExample/NativeCxxModuleExample.js index 78dfab45093..f29bf8bc780 100644 --- a/packages/rn-tester/NativeCxxModuleExample/NativeCxxModuleExample.js +++ b/packages/rn-tester/NativeCxxModuleExample/NativeCxxModuleExample.js @@ -8,8 +8,7 @@ * @format */ -import type {TurboModule} from 'react-native'; -import type {EventEmitter} from 'react-native/Libraries/Types/CodegenTypes'; +import type {CodegenTypes, TurboModule} from 'react-native'; import {TurboModuleRegistry} from 'react-native'; @@ -77,11 +76,11 @@ export type CustomDeviceEvent = { }; export interface Spec extends TurboModule { - +onPress: EventEmitter; - +onClick: EventEmitter; - +onChange: EventEmitter; - +onSubmit: EventEmitter; - +onEvent: EventEmitter; + +onPress: CodegenTypes.EventEmitter; + +onClick: CodegenTypes.EventEmitter; + +onChange: CodegenTypes.EventEmitter; + +onSubmit: CodegenTypes.EventEmitter; + +onEvent: CodegenTypes.EventEmitter; +getArray: (arg: Array) => Array; +getBool: (arg: boolean) => boolean; +getConstants: () => ConstantsStruct; diff --git a/packages/rn-tester/NativeModuleExample/NativeScreenshotManager.js b/packages/rn-tester/NativeModuleExample/NativeScreenshotManager.js index 4cdbbb3b662..a04cca85a83 100644 --- a/packages/rn-tester/NativeModuleExample/NativeScreenshotManager.js +++ b/packages/rn-tester/NativeModuleExample/NativeScreenshotManager.js @@ -8,12 +8,11 @@ * @format */ -import type {TurboModule} from 'react-native'; -import type {UnsafeObject} from 'react-native/Libraries/Types/CodegenTypes'; +import type {CodegenTypes, TurboModule} from 'react-native'; import {TurboModuleRegistry} from 'react-native'; -export type ScreenshotManagerOptions = UnsafeObject; +export type ScreenshotManagerOptions = CodegenTypes.UnsafeObject; export interface Spec extends TurboModule { +getConstants: () => {};