Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move ReactNativeTester to react-native repo #47515

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
46 changes: 46 additions & 0 deletions packages/react-native/src/private/__tests__/ReactNativeTester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/

import type {MixedElement} from 'react';

import ReactFabric from '../../../Libraries/Renderer/shims/ReactFabric';

let globalSurfaceIdCounter = 1;

class Root {
#surfaceId: number;
#hasRendered: boolean = false;

constructor() {
this.#surfaceId = globalSurfaceIdCounter;
globalSurfaceIdCounter += 10;
}

render(element: MixedElement) {
if (!this.#hasRendered) {
global.$$JSTesterModuleName$$.startSurface(this.#surfaceId);
this.#hasRendered = true;
}
ReactFabric.render(element, this.#surfaceId);
}

destroy() {
// TODO: check for leaks.
global.$$JSTesterModuleName$$.stopSurface(this.#surfaceId);
}

// TODO: add an API to check if all surfaces were deallocated when tests are finished.
}

// TODO: Add option to define surface props and pass it to startSurface
// Surfacep rops: concurrentRoot, surfaceWidth, surfaceHeight, layoutDirection, pointScaleFactor.
export function createRoot(): Root {
return new Root();
}
Loading