forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat[DebuggingOverlayRegistry]: basic implementation (facebook#41743)
Summary: Pull Request resolved: facebook#41743 Changelog: [Internal] There will be a single DebuggingRegistry instance per runtime, which will be responsible for finding lowest AppContainer ancestor for highligthed component. It will receive refs to root views (ancestors, AppContainers) as subscriptions and later will call all necessary methods. In the next series of diffs, subscriber will also provide reference to the DebuggingOverlay, on which DebuggingRegistry can call all necessary methods to highlight elements. Differential Revision: D51536787 Reviewed By: rshest fbshipit-source-id: cf24bd0bdcd411e7529c591096cd3416ae07d95d
- Loading branch information
1 parent
9ba3bc9
commit 2201c2b
Showing
5 changed files
with
85 additions
and
5 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
packages/react-native/Libraries/Debugging/DebuggingOverlayRegistry.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,38 @@ | ||
/** | ||
* 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 | ||
* @oncall react_native | ||
*/ | ||
|
||
import type {AppContainerRootViewRef} from '../ReactNative/AppContainer-dev'; | ||
|
||
export type DebuggingOverlayRegistrySubscriberProtocol = { | ||
rootViewRef: AppContainerRootViewRef, | ||
}; | ||
|
||
class DebuggingOverlayRegistry { | ||
#registry: Set<DebuggingOverlayRegistrySubscriberProtocol> = new Set(); | ||
|
||
subscribe(subscriber: DebuggingOverlayRegistrySubscriberProtocol) { | ||
this.#registry.add(subscriber); | ||
} | ||
|
||
unsubscribe(subscriber: DebuggingOverlayRegistrySubscriberProtocol) { | ||
const wasPresent = this.#registry.delete(subscriber); | ||
if (!wasPresent) { | ||
console.error( | ||
'[DebuggingOverlayRegistry] Unexpected argument for unsubscription, which was not previously subscribed:', | ||
subscriber, | ||
); | ||
} | ||
} | ||
} | ||
|
||
const debuggingOverlayRegistryInstance: DebuggingOverlayRegistry = | ||
new DebuggingOverlayRegistry(); | ||
export default debuggingOverlayRegistryInstance; |
28 changes: 28 additions & 0 deletions
28
packages/react-native/Libraries/Debugging/useSubscribeToDebuggingOverlayRegistry.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,28 @@ | ||
/** | ||
* 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 | ||
* @oncall react_native | ||
*/ | ||
|
||
import type {AppContainerRootViewRef} from '../ReactNative/AppContainer-dev'; | ||
|
||
import DebuggingOverlayRegistry from './DebuggingOverlayRegistry'; | ||
import {useEffect} from 'react'; | ||
|
||
const useSubscribeToDebuggingOverlayRegistry = ( | ||
rootViewRef: AppContainerRootViewRef, | ||
) => { | ||
useEffect(() => { | ||
const subscriber = {rootViewRef}; | ||
|
||
DebuggingOverlayRegistry.subscribe(subscriber); | ||
return () => DebuggingOverlayRegistry.unsubscribe(subscriber); | ||
}, [rootViewRef]); | ||
}; | ||
|
||
export default useSubscribeToDebuggingOverlayRegistry; |
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
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
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