-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move ReactNativeTester to react-native repo (#47515)
Summary: Pull Request resolved: #47515 Changelog: [internal] Reviewed By: sammy-SC Differential Revision: D65661699
- Loading branch information
1 parent
6295b81
commit e913a07
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
packages/react-native/src/private/__tests__/ReactNativeTester.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |