Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ module.exports = {
'<rootDir>/packages/react-native/src/react-private-interface.js',
'^react-native/setup-env$':
'<rootDir>/packages/react-native/src/setup-env.js',
'^react-native/unstable-internals-do-not-use$':
'<rootDir>/packages/react-native/src/unstable-internals-do-not-use.js',
},
setupFiles: ['./packages/jest-preset/jest/local-setup.js'],
fakeTimers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ interface NativeCommands {
+seek: (viewRef: React.ElementRef<NativeType>, position: number) => void,
+stop: (viewRef: React.ElementRef<NativeType>) => void,
}
const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry');
const {
NativeComponentRegistry
} = require('react-native');
let nativeComponentName = 'Module';
export const __INTERNAL_VIEW_CONFIG = {
uiViewClassName: \\"Module\\",
Expand All @@ -39,7 +41,9 @@ interface NativeCommands {
+pause: (viewRef: React.ElementRef<NativeType>) => void,
+play: (viewRef: React.ElementRef<NativeType>) => void,
}
const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry');
const {
NativeComponentRegistry
} = require('react-native');
let nativeComponentName = 'Module';
export const __INTERNAL_VIEW_CONFIG = {
uiViewClassName: \\"Module\\",
Expand All @@ -63,7 +67,9 @@ interface NativeCommands {
+mute: (viewRef: React.ElementRef<NativeType>) => void,
+unmute: (viewRef: React.ElementRef<NativeType>) => void,
}
const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry');
const {
NativeComponentRegistry
} = require('react-native');
let nativeComponentName = 'Module';
export const __INTERNAL_VIEW_CONFIG = {
uiViewClassName: \\"Module\\",
Expand Down Expand Up @@ -93,13 +99,15 @@ interface NativeCommands {
+hotspotUpdate: (viewRef: React.ElementRef<NativeType>, x: Int32, y: Int32) => void,
+scrollTo: (viewRef: React.ElementRef<NativeType>, 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\\",
Expand Down Expand Up @@ -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]);
}
};"
`;
Expand All @@ -156,13 +164,15 @@ interface NativeCommands {
+hotspotUpdate: (viewRef: React.ElementRef<NativeType>, x: Int32, y: Int32) => void,
+scrollTo: (viewRef: React.ElementRef<NativeType>, 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\\",
Expand Down Expand Up @@ -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]);
}
};"
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Spec>('XYZ');
`,
Expand Down
10 changes: 5 additions & 5 deletions packages/jest-preset/jest-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-preset/jest/mocks/ActivityIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<TmockComponent>('../mockComponent').default;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-preset/jest/mocks/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<TmockComponent>('../mockComponent').default;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-preset/jest/mocks/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<TmockComponent>('../mockComponent').default;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-preset/jest/mocks/RefreshControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-preset/jest/mocks/ScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-preset/jest/mocks/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<TmockComponent>('../mockComponent').default;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-preset/jest/mocks/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<TmockComponent>('../mockComponent').default;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-preset/jest/mocks/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<TmockComponent>('../mockComponent').default;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-preset/jest/mocks/ViewNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
14 changes: 13 additions & 1 deletion packages/new-app-screen/src/NewAppScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading
Loading