-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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 (#41743)
Summary: Pull Request resolved: #41743 Changelog: [Internal] There will be a single DebuggingRegistry instance per runtime, which will be responsible for finding lowest AppContainer ancestor for highlighted 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. Reviewed By: rshest Differential Revision: D51536787 fbshipit-source-id: e89f9d466a7e7833733981ff0d3ce2dbe349aaaa
- Loading branch information
1 parent
c989f63
commit f8a1818
Showing
6 changed files
with
115 additions
and
9 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
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