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.
refactor: DebuggingRegistry to handle trace updates (facebook#41744)
Summary: Changelog: [Internal] With these changes: - DebuggingRegitry is responsible for listening to the events from React DevTools and - AppContainer renders DebuggingOverlay component and subscribes with its reference to the DebuggingRegistry - [Improvement] Since DebuggingRegistry is a singleton, it will only subscribe to the React DevTools events once and not *number-of-rendered-AppContainers* times All required functionality for highlighting elements on a single AppContainer will be added in one of the next diffs of this stack, changes are incremental. Reviewed By: sammy-SC Differential Revision: D51603860
- Loading branch information
1 parent
98bc5dc
commit 85b04b7
Showing
5 changed files
with
206 additions
and
146 deletions.
There are no files selected for viewing
137 changes: 0 additions & 137 deletions
137
packages/react-native/Libraries/Components/TraceUpdateOverlay/TraceUpdateOverlay.js
This file was deleted.
Oops, something went wrong.
88 changes: 88 additions & 0 deletions
88
packages/react-native/Libraries/Debugging/DebuggingOverlay.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,88 @@ | ||
/** | ||
* 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 {Overlay} from './DebuggingOverlayNativeComponent'; | ||
|
||
import View from '../Components/View/View'; | ||
import UIManager from '../ReactNative/UIManager'; | ||
import StyleSheet from '../StyleSheet/StyleSheet'; | ||
import DebuggingOverlayNativeComponent, { | ||
Commands, | ||
} from './DebuggingOverlayNativeComponent'; | ||
import * as React from 'react'; | ||
|
||
const {useRef, useImperativeHandle} = React; | ||
const isNativeComponentReady = | ||
UIManager.hasViewManagerConfig('DebuggingOverlay'); | ||
|
||
type DebuggingOverlayHandle = { | ||
highlightTraceUpdates(updates: Overlay[]): void, | ||
}; | ||
|
||
function DebuggingOverlay( | ||
_props: {}, | ||
ref: React.RefSetter<DebuggingOverlayHandle>, | ||
): React.Node { | ||
useImperativeHandle( | ||
ref, | ||
() => ({ | ||
highlightTraceUpdates(updates) { | ||
if (!isNativeComponentReady) { | ||
return; | ||
} | ||
|
||
const nonEmptyRectangles = updates.filter( | ||
({rect, color}) => rect.width >= 0 && rect.height >= 0, | ||
); | ||
|
||
if (nativeComponentRef.current != null) { | ||
Commands.draw( | ||
nativeComponentRef.current, | ||
JSON.stringify(nonEmptyRectangles), | ||
); | ||
} | ||
}, | ||
}), | ||
[], | ||
); | ||
|
||
const nativeComponentRef = useRef<React.ElementRef< | ||
typeof DebuggingOverlayNativeComponent, | ||
> | null>(null); | ||
|
||
return ( | ||
isNativeComponentReady && ( | ||
<View pointerEvents="none" style={styles.overlay}> | ||
<DebuggingOverlayNativeComponent | ||
ref={nativeComponentRef} | ||
style={styles.overlay} | ||
/> | ||
</View> | ||
) | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
overlay: { | ||
position: 'absolute', | ||
top: 0, | ||
bottom: 0, | ||
left: 0, | ||
right: 0, | ||
}, | ||
}); | ||
|
||
const DebuggingOverlayWithForwardedRef: React.AbstractComponent< | ||
{}, | ||
DebuggingOverlayHandle, | ||
React.Node, | ||
> = React.forwardRef(DebuggingOverlay); | ||
|
||
export default DebuggingOverlayWithForwardedRef; |
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
Oops, something went wrong.