diff --git a/jest.config.js b/jest.config.js index 6e98ae747ea4..a91ef75838af 100644 --- a/jest.config.js +++ b/jest.config.js @@ -32,6 +32,8 @@ module.exports = { '/packages/react-native/src/react-private-interface.js', '^react-native/setup-env$': '/packages/react-native/src/setup-env.js', + '^react-native/unstable-internals-do-not-use$': + '/packages/react-native/src/unstable-internals-do-not-use.js', }, setupFiles: ['./packages/jest-preset/jest/local-setup.js'], fakeTimers: { diff --git a/packages/babel-plugin-codegen/__tests__/__snapshots__/index-test.js.snap b/packages/babel-plugin-codegen/__tests__/__snapshots__/index-test.js.snap index c038ee55988e..f86c0eaa8a0b 100644 --- a/packages/babel-plugin-codegen/__tests__/__snapshots__/index-test.js.snap +++ b/packages/babel-plugin-codegen/__tests__/__snapshots__/index-test.js.snap @@ -15,7 +15,9 @@ interface NativeCommands { +seek: (viewRef: React.ElementRef, position: number) => void, +stop: (viewRef: React.ElementRef) => void, } -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const { + NativeComponentRegistry +} = require('react-native'); let nativeComponentName = 'Module'; export const __INTERNAL_VIEW_CONFIG = { uiViewClassName: \\"Module\\", @@ -39,7 +41,9 @@ interface NativeCommands { +pause: (viewRef: React.ElementRef) => void, +play: (viewRef: React.ElementRef) => void, } -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const { + NativeComponentRegistry +} = require('react-native'); let nativeComponentName = 'Module'; export const __INTERNAL_VIEW_CONFIG = { uiViewClassName: \\"Module\\", @@ -63,7 +67,9 @@ interface NativeCommands { +mute: (viewRef: React.ElementRef) => void, +unmute: (viewRef: React.ElementRef) => void, } -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const { + NativeComponentRegistry +} = require('react-native'); let nativeComponentName = 'Module'; export const __INTERNAL_VIEW_CONFIG = { uiViewClassName: \\"Module\\", @@ -93,13 +99,15 @@ interface NativeCommands { +hotspotUpdate: (viewRef: React.ElementRef, x: Int32, y: Int32) => void, +scrollTo: (viewRef: React.ElementRef, y: Int32, animated: boolean) => void, } -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); const { ConditionallyIgnoredEventHandlers -} = require('react-native/Libraries/NativeComponent/ViewConfigIgnore'); +} = require('react-native/unstable-internals-do-not-use'); const { - dispatchCommand -} = require(\\"react-native/Libraries/ReactNative/RendererProxy\\"); + NativeComponentRegistry +} = require('react-native'); +const { + Renderer +} = require(\\"react-native/unstable-internals-do-not-use\\"); let nativeComponentName = 'RCTModule'; export const __INTERNAL_VIEW_CONFIG = { uiViewClassName: \\"RCTModule\\", @@ -127,10 +135,10 @@ export const __INTERNAL_VIEW_CONFIG = { export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL_VIEW_CONFIG); export const Commands = { hotspotUpdate(ref, x, y) { - dispatchCommand(ref, \\"hotspotUpdate\\", [x, y]); + Renderer.dispatchCommand(ref, \\"hotspotUpdate\\", [x, y]); }, scrollTo(ref, y, animated) { - dispatchCommand(ref, \\"scrollTo\\", [y, animated]); + Renderer.dispatchCommand(ref, \\"scrollTo\\", [y, animated]); } };" `; @@ -156,13 +164,15 @@ interface NativeCommands { +hotspotUpdate: (viewRef: React.ElementRef, x: Int32, y: Int32) => void, +scrollTo: (viewRef: React.ElementRef, y: Int32, animated: boolean) => void, } -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); const { ConditionallyIgnoredEventHandlers -} = require('react-native/Libraries/NativeComponent/ViewConfigIgnore'); +} = require('react-native/unstable-internals-do-not-use'); +const { + NativeComponentRegistry +} = require('react-native'); const { - dispatchCommand -} = require(\\"react-native/Libraries/ReactNative/RendererProxy\\"); + Renderer +} = require(\\"react-native/unstable-internals-do-not-use\\"); let nativeComponentName = 'RCTModule'; export const __INTERNAL_VIEW_CONFIG = { uiViewClassName: \\"RCTModule\\", @@ -190,10 +200,10 @@ export const __INTERNAL_VIEW_CONFIG = { export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL_VIEW_CONFIG); export const Commands = { hotspotUpdate(ref, x, y) { - dispatchCommand(ref, \\"hotspotUpdate\\", [x, y]); + Renderer.dispatchCommand(ref, \\"hotspotUpdate\\", [x, y]); }, scrollTo(ref, y, animated) { - dispatchCommand(ref, \\"scrollTo\\", [y, animated]); + Renderer.dispatchCommand(ref, \\"scrollTo\\", [y, animated]); } };" `; diff --git a/packages/eslint-plugin-specs/__tests__/react-native-modules-test.js b/packages/eslint-plugin-specs/__tests__/react-native-modules-test.js index 7785db83139f..3235c1969427 100644 --- a/packages/eslint-plugin-specs/__tests__/react-native-modules-test.js +++ b/packages/eslint-plugin-specs/__tests__/react-native-modules-test.js @@ -20,11 +20,10 @@ const eslintTester = new ESLintTester(); const VALID_SPECS = [ { code: ` -import {TurboModuleRegistry, type TurboModule} from 'react-native'; -import type {UnsafeObject} from 'react-native/Libraries/Types/CodegenTypes'; +import {TurboModuleRegistry, type CodegenTypes, type TurboModule} from 'react-native'; export interface Spec extends TurboModule { - func1(a: string): UnsafeObject, + func1(a: string): CodegenTypes.UnsafeObject, } export default TurboModuleRegistry.get('XYZ'); `, diff --git a/packages/jest-preset/jest-preset.js b/packages/jest-preset/jest-preset.js index 720a73efdca4..81f226a8e43c 100644 --- a/packages/jest-preset/jest-preset.js +++ b/packages/jest-preset/jest-preset.js @@ -18,13 +18,13 @@ module.exports = { platforms: ['android', 'ios', 'native'], }, moduleNameMapper: { - // `setup-env` and `react-private-interface` are secondary entry points - // exposed via the package's `exports`, but `./jest/resolver.js` strips - // `exports` and the generic mapper below resolves subpaths as literal - // directory paths. Alias them explicitly so they resolve to their `src/` - // implementations. + // These secondary entry points are exposed via the package's `exports`, + // but `./jest/resolver.js` strips `exports` and the generic mapper below + // resolves subpaths as literal directory paths. Alias them explicitly so + // they resolve to their `src/` implementations. '^react-native/react-private-interface$': `${path.dirname(require.resolve('react-native'))}/src/react-private-interface.js`, '^react-native/setup-env$': `${path.dirname(require.resolve('react-native'))}/src/setup-env.js`, + '^react-native/unstable-internals-do-not-use$': `${path.dirname(require.resolve('react-native'))}/src/unstable-internals-do-not-use.js`, '^react-native($|/.*)': `${path.dirname(require.resolve('react-native'))}/$1`, }, resolver: require.resolve('./jest/resolver.js'), diff --git a/packages/jest-preset/jest/mocks/ActivityIndicator.js b/packages/jest-preset/jest/mocks/ActivityIndicator.js index 42b6075a5a51..71499a60a321 100644 --- a/packages/jest-preset/jest/mocks/ActivityIndicator.js +++ b/packages/jest-preset/jest/mocks/ActivityIndicator.js @@ -9,7 +9,7 @@ */ import typeof * as TmockComponent from '../mockComponent'; -import typeof TActivityIndicator from 'react-native/Libraries/Components/ActivityIndicator/ActivityIndicator'; +import typeof {ActivityIndicator as TActivityIndicator} from 'react-native'; const mockComponent = jest.requireActual('../mockComponent').default; diff --git a/packages/jest-preset/jest/mocks/Image.js b/packages/jest-preset/jest/mocks/Image.js index 8d65ba8a488a..39e335889979 100644 --- a/packages/jest-preset/jest/mocks/Image.js +++ b/packages/jest-preset/jest/mocks/Image.js @@ -9,7 +9,7 @@ */ import typeof * as TmockComponent from '../mockComponent'; -import typeof TImage from 'react-native/Libraries/Image/Image'; +import typeof {Image as TImage} from 'react-native'; const mockComponent = jest.requireActual('../mockComponent').default; diff --git a/packages/jest-preset/jest/mocks/Modal.js b/packages/jest-preset/jest/mocks/Modal.js index d8514d27a44c..e099887ded47 100644 --- a/packages/jest-preset/jest/mocks/Modal.js +++ b/packages/jest-preset/jest/mocks/Modal.js @@ -9,7 +9,7 @@ */ import typeof * as TmockComponent from '../mockComponent'; -import type {ModalProps} from 'react-native/Libraries/Modal/Modal'; +import type {ModalProps} from 'react-native'; const mockComponent = jest.requireActual('../mockComponent').default; diff --git a/packages/jest-preset/jest/mocks/RefreshControl.js b/packages/jest-preset/jest/mocks/RefreshControl.js index cb9800dbbb75..d7a1c072660d 100644 --- a/packages/jest-preset/jest/mocks/RefreshControl.js +++ b/packages/jest-preset/jest/mocks/RefreshControl.js @@ -8,7 +8,7 @@ * @format */ -import type {RefreshControlProps} from 'react-native/Libraries/Components/RefreshControl/RefreshControl'; +import type {RefreshControlProps} from 'react-native'; import type {HostComponent} from 'react-native/src/private/types/HostComponent'; import * as React from 'react'; diff --git a/packages/jest-preset/jest/mocks/ScrollView.js b/packages/jest-preset/jest/mocks/ScrollView.js index 39d8f69af9d1..06a1bf85e4dc 100644 --- a/packages/jest-preset/jest/mocks/ScrollView.js +++ b/packages/jest-preset/jest/mocks/ScrollView.js @@ -10,7 +10,7 @@ import typeof * as TmockComponent from '../mockComponent'; import typeof * as TMockNativeMethods from '../MockNativeMethods'; -import typeof TScrollView from 'react-native/Libraries/Components/ScrollView/ScrollView'; +import typeof {ScrollView as TScrollView} from 'react-native'; import type {ScrollViewNativeProps} from 'react-native/Libraries/Components/ScrollView/ScrollViewNativeComponentType'; import * as React from 'react'; diff --git a/packages/jest-preset/jest/mocks/Text.js b/packages/jest-preset/jest/mocks/Text.js index da56850e8a30..89f33c0b35e0 100644 --- a/packages/jest-preset/jest/mocks/Text.js +++ b/packages/jest-preset/jest/mocks/Text.js @@ -10,7 +10,7 @@ import typeof * as TmockComponent from '../mockComponent'; import typeof * as TMockNativeMethods from '../MockNativeMethods'; -import typeof TText from 'react-native/Libraries/Text/Text'; +import typeof {Text as TText} from 'react-native'; const mockComponent = jest.requireActual('../mockComponent').default; diff --git a/packages/jest-preset/jest/mocks/TextInput.js b/packages/jest-preset/jest/mocks/TextInput.js index fc34a8b65dcf..b74e7ab8a926 100644 --- a/packages/jest-preset/jest/mocks/TextInput.js +++ b/packages/jest-preset/jest/mocks/TextInput.js @@ -10,7 +10,7 @@ import typeof * as TmockComponent from '../mockComponent'; import typeof * as TMockNativeMethods from '../MockNativeMethods'; -import typeof TTextInput from 'react-native/Libraries/Components/TextInput/TextInput'; +import typeof {TextInput as TTextInput} from 'react-native'; const mockComponent = jest.requireActual('../mockComponent').default; diff --git a/packages/jest-preset/jest/mocks/View.js b/packages/jest-preset/jest/mocks/View.js index dca384233d21..fce3ca9fca0c 100644 --- a/packages/jest-preset/jest/mocks/View.js +++ b/packages/jest-preset/jest/mocks/View.js @@ -10,7 +10,7 @@ import typeof * as TmockComponent from '../mockComponent'; import typeof * as TMockNativeMethods from '../MockNativeMethods'; -import typeof TView from 'react-native/Libraries/Components/View/View'; +import typeof {View as TView} from 'react-native'; const mockComponent = jest.requireActual('../mockComponent').default; diff --git a/packages/jest-preset/jest/mocks/ViewNativeComponent.js b/packages/jest-preset/jest/mocks/ViewNativeComponent.js index 716bd4c89a3c..4f6ca6f36eae 100644 --- a/packages/jest-preset/jest/mocks/ViewNativeComponent.js +++ b/packages/jest-preset/jest/mocks/ViewNativeComponent.js @@ -8,7 +8,7 @@ * @format */ -import type {ViewProps} from 'react-native/Libraries/Components/View/ViewPropTypes'; +import type {ViewProps} from 'react-native'; import * as React from 'react'; import {createElement} from 'react'; diff --git a/packages/new-app-screen/src/NewAppScreen.js b/packages/new-app-screen/src/NewAppScreen.js index 379bfe8d62f1..21319a89de0b 100644 --- a/packages/new-app-screen/src/NewAppScreen.js +++ b/packages/new-app-screen/src/NewAppScreen.js @@ -22,7 +22,19 @@ import { useColorScheme, useWindowDimensions, } from 'react-native'; -import openURLInBrowser from 'react-native/Libraries/Core/Devtools/openURLInBrowser'; +import {getDevServer} from 'react-native/unstable-internals-do-not-use'; + +function openURLInBrowser(url: string): void { + fetch(getDevServer().url + 'open-url', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({url}), + }).catch(error => { + console.error('Failed to open URL in browser:', error); + }); +} export type NewAppScreenProps = Readonly<{ templateFileName?: string, diff --git a/packages/react-native-babel-preset/src/__tests__/transform-snapshot-test.js b/packages/react-native-babel-preset/src/__tests__/transform-snapshot-test.js index fb50cec1c5f4..55390bcabf23 100644 --- a/packages/react-native-babel-preset/src/__tests__/transform-snapshot-test.js +++ b/packages/react-native-babel-preset/src/__tests__/transform-snapshot-test.js @@ -316,9 +316,11 @@ describe('react-native-babel-preset transform snapshots', () => { it('runs codegen when the type arguments are separated by trivia', () => { const code = ` // @flow strict-local - import type {ViewProps} from 'react-native'; - import type {HostComponent} from 'react-native'; - import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; + import { + codegenNativeComponent, + type HostComponent, + type ViewProps, + } from 'react-native'; type NativeProps = Readonly<{ ...ViewProps, diff --git a/packages/react-native-codegen/e2e/deep_imports/__tests__/components/__snapshots__/GenerateViewConfigJs-test.js.snap b/packages/react-native-codegen/e2e/deep_imports/__tests__/components/__snapshots__/GenerateViewConfigJs-test.js.snap index bb0a9098fc04..7eb32dcd4bc1 100644 --- a/packages/react-native-codegen/e2e/deep_imports/__tests__/components/__snapshots__/GenerateViewConfigJs-test.js.snap +++ b/packages/react-native-codegen/e2e/deep_imports/__tests__/components/__snapshots__/GenerateViewConfigJs-test.js.snap @@ -16,7 +16,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'ArrayPropsNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { @@ -27,7 +27,7 @@ export const __INTERNAL_VIEW_CONFIG = { progress: true, radii: true, colors: { - process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/StyleSheet/processColorArray')) + process: require('react-native/unstable-internals-do-not-use').processColorArray }, srcs: true, points: true, @@ -60,7 +60,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'BooleanPropNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { @@ -91,13 +91,13 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'ColorPropNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { uiViewClassName: \\"ColorPropNativeComponentView\\", validAttributes: { - tintColor: require('react-native/Libraries/Components/View/ReactNativeStyleAttributes').colorAttribute + tintColor: require('react-native/unstable-internals-do-not-use').colorAttribute } }; export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL_VIEW_CONFIG); @@ -121,7 +121,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'DimensionPropNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { @@ -151,7 +151,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'EdgeInsetsPropNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { @@ -179,7 +179,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'EnumPropNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { @@ -210,8 +210,8 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); -const {ConditionallyIgnoredEventHandlers} = require('react-native/Libraries/NativeComponent/ViewConfigIgnore'); +const {ConditionallyIgnoredEventHandlers} = require('react-native/unstable-internals-do-not-use'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'EventNestedObjectPropsNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { @@ -252,8 +252,8 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); -const {ConditionallyIgnoredEventHandlers} = require('react-native/Libraries/NativeComponent/ViewConfigIgnore'); +const {ConditionallyIgnoredEventHandlers} = require('react-native/unstable-internals-do-not-use'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'EventPropsNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { @@ -322,7 +322,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'FloatPropsNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { @@ -358,14 +358,14 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'ImagePropNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { uiViewClassName: \\"ImagePropNativeComponentView\\", validAttributes: { thumbImage: { - process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Image/resolveAssetSource')) + process: require('react-native').Image.resolveAssetSource } } }; @@ -390,7 +390,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'IntegerPropNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { @@ -422,8 +422,8 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); -const {ConditionallyIgnoredEventHandlers} = require('react-native/Libraries/NativeComponent/ViewConfigIgnore'); +const {ConditionallyIgnoredEventHandlers} = require('react-native/unstable-internals-do-not-use'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'RCTInterfaceOnlyComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -464,7 +464,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'MixedPropNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { @@ -494,19 +494,19 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'MultiNativePropNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { uiViewClassName: \\"MultiNativePropNativeComponentView\\", validAttributes: { thumbImage: { - process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Image/resolveAssetSource')) + process: require('react-native').Image.resolveAssetSource }, - color: require('react-native/Libraries/Components/View/ReactNativeStyleAttributes').colorAttribute, - thumbTintColor: require('react-native/Libraries/Components/View/ReactNativeStyleAttributes').colorAttribute, + color: require('react-native/unstable-internals-do-not-use').colorAttribute, + thumbTintColor: require('react-native/unstable-internals-do-not-use').colorAttribute, point: { - diff: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Utilities/differ/pointsDiffer')) + diff: require('react-native/unstable-internals-do-not-use').pointsDiffer } } }; @@ -531,7 +531,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'NoPropsNoEventsNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { @@ -559,7 +559,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'ObjectPropsNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -591,14 +591,14 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'PointPropNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { uiViewClassName: \\"PointPropNativeComponentView\\", validAttributes: { startPoint: { - diff: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Utilities/differ/pointsDiffer')) + diff: require('react-native/unstable-internals-do-not-use').pointsDiffer } } }; @@ -623,7 +623,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'StringPropNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { diff --git a/packages/react-native-codegen/e2e/namespaced/__tests__/components/__snapshots__/GenerateViewConfigJs-test.js.snap b/packages/react-native-codegen/e2e/namespaced/__tests__/components/__snapshots__/GenerateViewConfigJs-test.js.snap index 054bd1a003bf..4864828d5d67 100644 --- a/packages/react-native-codegen/e2e/namespaced/__tests__/components/__snapshots__/GenerateViewConfigJs-test.js.snap +++ b/packages/react-native-codegen/e2e/namespaced/__tests__/components/__snapshots__/GenerateViewConfigJs-test.js.snap @@ -16,7 +16,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'ArrayPropsNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { @@ -27,7 +27,7 @@ export const __INTERNAL_VIEW_CONFIG = { progress: true, radii: true, colors: { - process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/StyleSheet/processColorArray')) + process: require('react-native/unstable-internals-do-not-use').processColorArray }, srcs: true, points: true, @@ -60,7 +60,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'BooleanPropNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { @@ -91,13 +91,13 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'ColorPropNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { uiViewClassName: \\"ColorPropNativeComponentView\\", validAttributes: { - tintColor: require('react-native/Libraries/Components/View/ReactNativeStyleAttributes').colorAttribute + tintColor: require('react-native/unstable-internals-do-not-use').colorAttribute } }; export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL_VIEW_CONFIG); @@ -121,7 +121,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'DimensionPropNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { @@ -151,7 +151,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'EdgeInsetsPropNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { @@ -179,7 +179,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'EnumPropNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { @@ -210,8 +210,8 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); -const {ConditionallyIgnoredEventHandlers} = require('react-native/Libraries/NativeComponent/ViewConfigIgnore'); +const {ConditionallyIgnoredEventHandlers} = require('react-native/unstable-internals-do-not-use'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'EventNestedObjectPropsNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { @@ -252,8 +252,8 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); -const {ConditionallyIgnoredEventHandlers} = require('react-native/Libraries/NativeComponent/ViewConfigIgnore'); +const {ConditionallyIgnoredEventHandlers} = require('react-native/unstable-internals-do-not-use'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'EventPropsNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { @@ -322,7 +322,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'FloatPropsNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { @@ -358,14 +358,14 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'ImagePropNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { uiViewClassName: \\"ImagePropNativeComponentView\\", validAttributes: { thumbImage: { - process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Image/resolveAssetSource')) + process: require('react-native').Image.resolveAssetSource } } }; @@ -390,7 +390,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'IntegerPropNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { @@ -422,8 +422,8 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); -const {ConditionallyIgnoredEventHandlers} = require('react-native/Libraries/NativeComponent/ViewConfigIgnore'); +const {ConditionallyIgnoredEventHandlers} = require('react-native/unstable-internals-do-not-use'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'RCTInterfaceOnlyComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -464,7 +464,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'MixedPropNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { @@ -494,19 +494,19 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'MultiNativePropNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { uiViewClassName: \\"MultiNativePropNativeComponentView\\", validAttributes: { thumbImage: { - process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Image/resolveAssetSource')) + process: require('react-native').Image.resolveAssetSource }, - color: require('react-native/Libraries/Components/View/ReactNativeStyleAttributes').colorAttribute, - thumbTintColor: require('react-native/Libraries/Components/View/ReactNativeStyleAttributes').colorAttribute, + color: require('react-native/unstable-internals-do-not-use').colorAttribute, + thumbTintColor: require('react-native/unstable-internals-do-not-use').colorAttribute, point: { - diff: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Utilities/differ/pointsDiffer')) + diff: require('react-native/unstable-internals-do-not-use').pointsDiffer } } }; @@ -531,7 +531,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'NoPropsNoEventsNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { @@ -559,7 +559,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'ObjectPropsNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -591,14 +591,14 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'PointPropNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { uiViewClassName: \\"PointPropNativeComponentView\\", validAttributes: { startPoint: { - diff: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Utilities/differ/pointsDiffer')) + diff: require('react-native/unstable-internals-do-not-use').pointsDiffer } } }; @@ -623,7 +623,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'StringPropNativeComponentView'; export const __INTERNAL_VIEW_CONFIG = { diff --git a/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js b/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js index 50d8d53b0f9c..d9e4de50bf98 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js +++ b/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js @@ -55,7 +55,9 @@ ${componentConfig} // We use this to add to a set. Need to make sure we aren't importing // this multiple times. -const UIMANAGER_IMPORT = 'const {UIManager} = require("react-native")'; +const UIMANAGER_IMPORT = 'const {UIManager} = require("react-native");'; +const RENDERER_IMPORT = + 'const {Renderer} = require("react-native/unstable-internals-do-not-use");'; function expression(input: string) { return core.template.expression(input)(); @@ -77,21 +79,21 @@ function getReactDiffProcessValue(typeAnnotation: PropTypeAnnotation) { switch (typeAnnotation.name) { case 'ColorPrimitive': return expression( - "require('react-native/Libraries/Components/View/ReactNativeStyleAttributes').colorAttribute", + "require('react-native/unstable-internals-do-not-use').colorAttribute", ); case 'ImageSourcePrimitive': return expression( - "{ process: ((req) => 'default' in req ? req.default : req)(require('react-native/Libraries/Image/resolveAssetSource')) }", + "{ process: require('react-native').Image.resolveAssetSource }", ); case 'ImageRequestPrimitive': throw new Error('ImageRequest should not be used in props'); case 'PointPrimitive': return expression( - "{ diff: ((req) => 'default' in req ? req.default : req)(require('react-native/Libraries/Utilities/differ/pointsDiffer')) }", + "{ diff: require('react-native/unstable-internals-do-not-use').pointsDiffer }", ); case 'EdgeInsetsPrimitive': return expression( - "{ diff: ((req) => 'default' in req ? req.default : req)(require('react-native/Libraries/Utilities/differ/insetsDiffer')) }", + "{ diff: require('react-native/unstable-internals-do-not-use').insetsDiffer }", ); case 'DimensionPrimitive': return t.booleanLiteral(true); @@ -106,7 +108,7 @@ function getReactDiffProcessValue(typeAnnotation: PropTypeAnnotation) { switch (typeAnnotation.elementType.name) { case 'ColorPrimitive': return expression( - "{ process: ((req) => 'default' in req ? req.default : req)(require('react-native/Libraries/StyleSheet/processColorArray')) }", + "{ process: require('react-native/unstable-internals-do-not-use').processColorArray }", ); case 'ImageSourcePrimitive': case 'PointPrimitive': @@ -192,8 +194,10 @@ function getValidAttributesForEvents( events: ReadonlyArray, imports: Set, ) { + // Generated files can live outside the React Native package, so they cannot + // use a relative import for this implementation detail. imports.add( - "const {ConditionallyIgnoredEventHandlers} = require('react-native/Libraries/NativeComponent/ViewConfigIgnore');", + "const {ConditionallyIgnoredEventHandlers} = require('react-native/unstable-internals-do-not-use');", ); const validAttributes = t.objectExpression( @@ -264,7 +268,7 @@ function buildViewConfig( switch (extendProps.knownTypeName) { case 'ReactNativeCoreViewProps': imports.add( - "const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry');", + "const {NativeComponentRegistry} = require('react-native');", ); return; @@ -366,9 +370,7 @@ function buildCommands( return null; } - imports.add( - 'const {dispatchCommand} = require("react-native/Libraries/ReactNative/RendererProxy");', - ); + imports.add(RENDERER_IMPORT); const commandsObject = t.objectExpression( commands.map(command => { @@ -376,7 +378,10 @@ function buildCommands( const params = command.typeAnnotation.params; const dispatchCommandCall = t.callExpression( - t.identifier('dispatchCommand'), + t.memberExpression( + t.identifier('Renderer'), + t.identifier('dispatchCommand'), + ), [ t.identifier('ref'), t.stringLiteral(commandName), diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap index 7b3d95c37134..2e366a12f550 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap @@ -16,7 +16,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'AllProp'; export const __INTERNAL_VIEW_CONFIG = { @@ -62,7 +62,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'AllPropWithOptionalGen'; export const __INTERNAL_VIEW_CONFIG = { @@ -108,7 +108,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'AllPropWithOptionalObjectGen'; export const __INTERNAL_VIEW_CONFIG = { @@ -154,7 +154,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'ArrayPropsNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -165,7 +165,7 @@ export const __INTERNAL_VIEW_CONFIG = { progress: true, radii: true, colors: { - process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/StyleSheet/processColorArray')) + process: require('react-native/unstable-internals-do-not-use').processColorArray }, srcs: true, points: true, @@ -198,7 +198,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'ArrayPropsNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -228,7 +228,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'ArrayPropsOptionalGenNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -258,7 +258,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'ArrayPropsOptionalObjectGenNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -288,7 +288,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'ArrayPropsWithOptionalGenNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -299,7 +299,7 @@ export const __INTERNAL_VIEW_CONFIG = { progress: true, radii: true, colors: { - process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/StyleSheet/processColorArray')) + process: require('react-native/unstable-internals-do-not-use').processColorArray }, srcs: true, points: true, @@ -332,7 +332,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'ArrayPropsWithOptionalObjectGenNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -343,7 +343,7 @@ export const __INTERNAL_VIEW_CONFIG = { progress: true, radii: true, colors: { - process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/StyleSheet/processColorArray')) + process: require('react-native/unstable-internals-do-not-use').processColorArray }, srcs: true, points: true, @@ -376,7 +376,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'BooleanPropNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -406,13 +406,13 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'ColorPropNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { uiViewClassName: \\"ColorPropNativeComponent\\", validAttributes: { - tintColor: require('react-native/Libraries/Components/View/ReactNativeStyleAttributes').colorAttribute + tintColor: require('react-native/unstable-internals-do-not-use').colorAttribute } }; export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL_VIEW_CONFIG); @@ -436,8 +436,8 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); -const {dispatchCommand} = require(\\"react-native/Libraries/ReactNative/RendererProxy\\"); +const {NativeComponentRegistry} = require('react-native'); +const {Renderer} = require(\\"react-native/unstable-internals-do-not-use\\"); let nativeComponentName = 'CommandNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -447,10 +447,10 @@ export const __INTERNAL_VIEW_CONFIG = { export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL_VIEW_CONFIG); export const Commands = { flashScrollIndicators(ref) { - dispatchCommand(ref, \\"flashScrollIndicators\\", []); + Renderer.dispatchCommand(ref, \\"flashScrollIndicators\\", []); }, allTypes(ref, x, y, z, message, animated, locations) { - dispatchCommand(ref, \\"allTypes\\", [x, y, z, message, animated, locations]); + Renderer.dispatchCommand(ref, \\"allTypes\\", [x, y, z, message, animated, locations]); } }; ", @@ -473,8 +473,8 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); -const {dispatchCommand} = require(\\"react-native/Libraries/ReactNative/RendererProxy\\"); +const {NativeComponentRegistry} = require('react-native'); +const {Renderer} = require(\\"react-native/unstable-internals-do-not-use\\"); let nativeComponentName = 'CommandNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -486,13 +486,13 @@ export const __INTERNAL_VIEW_CONFIG = { export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL_VIEW_CONFIG); export const Commands = { handleRootTag(ref, rootTag) { - dispatchCommand(ref, \\"handleRootTag\\", [rootTag]); + Renderer.dispatchCommand(ref, \\"handleRootTag\\", [rootTag]); }, hotspotUpdate(ref, x, y) { - dispatchCommand(ref, \\"hotspotUpdate\\", [x, y]); + Renderer.dispatchCommand(ref, \\"hotspotUpdate\\", [x, y]); }, addItems(ref, items) { - dispatchCommand(ref, \\"addItems\\", [items]); + Renderer.dispatchCommand(ref, \\"addItems\\", [items]); } }; ", @@ -515,7 +515,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'DimensionPropNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -545,7 +545,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'DoublePropNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -580,8 +580,8 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); -const {ConditionallyIgnoredEventHandlers} = require('react-native/Libraries/NativeComponent/ViewConfigIgnore'); +const {ConditionallyIgnoredEventHandlers} = require('react-native/unstable-internals-do-not-use'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'EventsNestedObjectNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -622,8 +622,8 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); -const {ConditionallyIgnoredEventHandlers} = require('react-native/Libraries/NativeComponent/ViewConfigIgnore'); +const {ConditionallyIgnoredEventHandlers} = require('react-native/unstable-internals-do-not-use'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'EventsNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -692,8 +692,8 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); -const {ConditionallyIgnoredEventHandlers} = require('react-native/Libraries/NativeComponent/ViewConfigIgnore'); +const {ConditionallyIgnoredEventHandlers} = require('react-native/unstable-internals-do-not-use'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'RCTInterfaceOnlyComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -739,7 +739,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'ExcludedAndroidComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -767,7 +767,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'ExcludedAndroidIosComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -795,7 +795,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'ExcludedIosComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -832,7 +832,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'FloatPropNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -867,14 +867,14 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'ImagePropNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { uiViewClassName: \\"ImagePropNativeComponent\\", validAttributes: { thumbImage: { - process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Image/resolveAssetSource')) + process: require('react-native').Image.resolveAssetSource } } }; @@ -899,14 +899,14 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'InsetsPropNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { uiViewClassName: \\"InsetsPropNativeComponent\\", validAttributes: { contentInset: { - diff: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Utilities/differ/insetsDiffer')) + diff: require('react-native/unstable-internals-do-not-use').insetsDiffer } } }; @@ -931,7 +931,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'Int32EnumPropsNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -961,7 +961,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'IntegerPropNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -993,8 +993,8 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); -const {ConditionallyIgnoredEventHandlers} = require('react-native/Libraries/NativeComponent/ViewConfigIgnore'); +const {ConditionallyIgnoredEventHandlers} = require('react-native/unstable-internals-do-not-use'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'RCTInterfaceOnlyComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -1035,7 +1035,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'MixedPropNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -1065,19 +1065,19 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'ImageColorPropNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { uiViewClassName: \\"ImageColorPropNativeComponent\\", validAttributes: { thumbImage: { - process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Image/resolveAssetSource')) + process: require('react-native').Image.resolveAssetSource }, - color: require('react-native/Libraries/Components/View/ReactNativeStyleAttributes').colorAttribute, - thumbTintColor: require('react-native/Libraries/Components/View/ReactNativeStyleAttributes').colorAttribute, + color: require('react-native/unstable-internals-do-not-use').colorAttribute, + thumbTintColor: require('react-native/unstable-internals-do-not-use').colorAttribute, point: { - diff: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Utilities/differ/pointsDiffer')) + diff: require('react-native/unstable-internals-do-not-use').pointsDiffer } } }; @@ -1102,7 +1102,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'NoPropsNoEventsComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -1130,7 +1130,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'ObjectProps'; export const __INTERNAL_VIEW_CONFIG = { @@ -1160,7 +1160,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'ObjectPropsWithOptionalGen'; export const __INTERNAL_VIEW_CONFIG = { @@ -1190,7 +1190,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'ObjectPropsWithOptionalObjectGen'; export const __INTERNAL_VIEW_CONFIG = { @@ -1220,14 +1220,14 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'PointPropNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { uiViewClassName: \\"PointPropNativeComponent\\", validAttributes: { startPoint: { - diff: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Utilities/differ/pointsDiffer')) + diff: require('react-native/unstable-internals-do-not-use').pointsDiffer } } }; @@ -1252,7 +1252,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'StringEnumPropsNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -1282,7 +1282,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'StringPropComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -1313,7 +1313,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'MultiFile1NativeComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -1352,7 +1352,7 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); +const {NativeComponentRegistry} = require('react-native'); let nativeComponentName = 'MultiComponent1NativeComponent'; export const __INTERNAL_VIEW_CONFIG = { @@ -1391,8 +1391,8 @@ Map { 'use strict'; -const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); -const {UIManager} = require(\\"react-native\\") +const {NativeComponentRegistry} = require('react-native'); +const {UIManager} = require(\\"react-native\\"); let nativeComponentName = 'NativeComponentName'; if (UIManager.hasViewManagerConfig('NativeComponentName')) { diff --git a/packages/react-native-codegen/src/parsers/__tests__/parsers-commons-test.js b/packages/react-native-codegen/src/parsers/__tests__/parsers-commons-test.js index 34d76c575a37..dad048f3be18 100644 --- a/packages/react-native-codegen/src/parsers/__tests__/parsers-commons-test.js +++ b/packages/react-native-codegen/src/parsers/__tests__/parsers-commons-test.js @@ -801,8 +801,7 @@ describe('buildSchema', () => { describe('when there is a TurboModule', () => { const contents = ` - import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport'; - import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry'; + import {TurboModuleRegistry, type TurboModule} from 'react-native'; export interface Spec extends TurboModule { +getArray: (a: Array) => Array; @@ -1094,8 +1093,7 @@ describe('buildModuleSchema', () => { const [, tryParse] = createParserErrorCapturer(); const language = flowParser.language(); const NATIVE_MODULE = ` - import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport'; - import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry'; + import {TurboModuleRegistry, type TurboModule} from 'react-native'; export interface Spec extends TurboModule { +getArray: (a: Array) => Array; @@ -1144,8 +1142,7 @@ describe('buildModuleSchema', () => { describe('throwIfMoreThanOneModuleInterfaceParser', () => { it('should throw an error if mulitple module interfaces are found', () => { const contents = ` - import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport'; - import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry'; + import {TurboModuleRegistry, type TurboModule} from 'react-native'; export interface Spec extends TurboModule { +getBool: (arg: boolean) => boolean; } @@ -1194,8 +1191,7 @@ describe('buildModuleSchema', () => { describe('throwIfModuleInterfaceIsMisnamed', () => { it('should throw an error if module interface is misnamed', () => { const contents = ` - import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport'; - import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry'; + import {TurboModuleRegistry, type TurboModule} from 'react-native'; export interface MisnamedSpec extends TurboModule { +getArray: (a: Array) => Array; diff --git a/packages/react-native-popup-menu-android/js/PopupMenuAndroid.android.js b/packages/react-native-popup-menu-android/js/PopupMenuAndroid.android.js index 379448c3650e..ceebecbe1b23 100644 --- a/packages/react-native-popup-menu-android/js/PopupMenuAndroid.android.js +++ b/packages/react-native-popup-menu-android/js/PopupMenuAndroid.android.js @@ -9,8 +9,7 @@ */ import type {RefObject} from 'react'; -import type {HostInstance} from 'react-native'; -import type {NativeSyntheticEvent} from 'react-native/Libraries/Types/CoreEventTypes'; +import type {HostInstance, NativeSyntheticEvent} from 'react-native'; import PopupMenuAndroidNativeComponent, { Commands, diff --git a/packages/react-native-popup-menu-android/js/PopupMenuAndroidNativeComponent.android.js b/packages/react-native-popup-menu-android/js/PopupMenuAndroidNativeComponent.android.js index 76eaae6edace..a9bba9b495ad 100644 --- a/packages/react-native-popup-menu-android/js/PopupMenuAndroidNativeComponent.android.js +++ b/packages/react-native-popup-menu-android/js/PopupMenuAndroidNativeComponent.android.js @@ -8,19 +8,13 @@ * @format */ -import type {HostComponent} from 'react-native'; -import type {ViewProps} from 'react-native/Libraries/Components/View/ViewPropTypes'; -import type { - DirectEventHandler, - Int32, -} from 'react-native/Libraries/Types/CodegenTypes'; +import type {CodegenTypes, HostComponent, ViewProps} from 'react-native'; import * as React from 'react'; -import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands'; -import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; +import {codegenNativeCommands, codegenNativeComponent} from 'react-native'; type PopupMenuSelectionEvent = Readonly<{ - item: Int32, + item: CodegenTypes.Int32, }>; type PopupMenuDismissEvent = Readonly<{}>; @@ -31,8 +25,8 @@ type NativeProps = Readonly<{ //Props menuItems?: ?ReadonlyArray, - onPopupMenuSelectionChange?: DirectEventHandler, - onPopupMenuDismiss?: DirectEventHandler, + onPopupMenuSelectionChange?: CodegenTypes.DirectEventHandler, + onPopupMenuDismiss?: CodegenTypes.DirectEventHandler, }>; type ComponentType = HostComponent; diff --git a/packages/react-native/Libraries/Components/Touchable/__tests__/TouchableOpacity-itest.js b/packages/react-native/Libraries/Components/Touchable/__tests__/TouchableOpacity-itest.js index 0bfba7aa9868..2e7b6367e806 100644 --- a/packages/react-native/Libraries/Components/Touchable/__tests__/TouchableOpacity-itest.js +++ b/packages/react-native/Libraries/Components/Touchable/__tests__/TouchableOpacity-itest.js @@ -189,7 +189,7 @@ describe('', () => { }); const element = nullthrows( - root.document.documentElement.firstElementChild, + nullthrows(root.document.documentElement).firstElementChild, ); expect(element.childNodes.length).toBe(1); diff --git a/packages/react-native/Libraries/Components/Touchable/__tests__/TouchableWithoutFeedback-itest.js b/packages/react-native/Libraries/Components/Touchable/__tests__/TouchableWithoutFeedback-itest.js index f49793c9d438..f01cd2d7326e 100644 --- a/packages/react-native/Libraries/Components/Touchable/__tests__/TouchableWithoutFeedback-itest.js +++ b/packages/react-native/Libraries/Components/Touchable/__tests__/TouchableWithoutFeedback-itest.js @@ -141,7 +141,9 @@ describe('', () => { }); expect( - nullthrows(root.document.documentElement.firstElementChild).tagName, + nullthrows( + nullthrows(root.document.documentElement).firstElementChild, + ).tagName, ).toBe('RN:Paragraph'); Fantom.runTask(() => { @@ -155,7 +157,9 @@ describe('', () => { }); expect( - nullthrows(root.document.documentElement.firstElementChild).tagName, + nullthrows( + nullthrows(root.document.documentElement).firstElementChild, + ).tagName, ).toBe('RN:View'); }); }); diff --git a/packages/react-native/Libraries/Components/__tests__/Button-itest.js b/packages/react-native/Libraries/Components/__tests__/Button-itest.js index 5ff8d88e138f..67285d757d40 100644 --- a/packages/react-native/Libraries/Components/__tests__/Button-itest.js +++ b/packages/react-native/Libraries/Components/__tests__/Button-itest.js @@ -77,7 +77,7 @@ describe('