Skip to content

Commit a2f155f

Browse files
Xin Chenfacebook-github-bot
authored andcommitted
Enable TraceUpdateOverlay for android RN apps
Summary: This diff is a retry of shipping D43180893 (89ef5bd), which got backed out in D43350025 (1f151e0) due to issues in iOS RN apps. I've exclude iOS apps in this diff. I am planning to have the iOS implementation for the TraceUpdateOverlay native component to fill the gap with lower priority. Changelog: [Internal] Reviewed By: javache Differential Revision: D43409501 fbshipit-source-id: fe8bb5654862f0b5e9054a97ae1f4cde573bb3e0
1 parent 8cc733b commit a2f155f

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

Libraries/Components/TraceUpdateOverlay/TraceUpdateOverlay.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010

1111
import type {Overlay} from './TraceUpdateOverlayNativeComponent';
1212

13+
import UIManager from '../../ReactNative/UIManager';
1314
import processColor from '../../StyleSheet/processColor';
1415
import StyleSheet from '../../StyleSheet/StyleSheet';
16+
import Platform from '../../Utilities/Platform';
1517
import View from '../View/View';
1618
import TraceUpdateOverlayNativeComponent, {
1719
Commands,
@@ -53,13 +55,20 @@ type ReactDevToolsGlobalHook = {
5355

5456
const {useEffect, useRef, useState} = React;
5557
const hook: ReactDevToolsGlobalHook = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
58+
const isNativeComponentReady =
59+
Platform.OS === 'android' &&
60+
UIManager.hasViewManagerConfig('TraceUpdateOverlay');
5661
let devToolsAgent: ?Agent;
5762

5863
export default function TraceUpdateOverlay(): React.Node {
5964
const [overlayDisabled, setOverlayDisabled] = useState(false);
6065
// This effect is designed to be explictly shown here to avoid re-subscribe from the same
6166
// overlay component.
6267
useEffect(() => {
68+
if (!isNativeComponentReady) {
69+
return;
70+
}
71+
6372
function attachToDevtools(agent: Agent) {
6473
devToolsAgent = agent;
6574
agent.addListener('drawTraceUpdates', onAgentDrawTraceUpdates);
@@ -141,7 +150,8 @@ export default function TraceUpdateOverlay(): React.Node {
141150
useRef<?React.ElementRef<typeof TraceUpdateOverlayNativeComponent>>(null);
142151

143152
return (
144-
!overlayDisabled && (
153+
!overlayDisabled &&
154+
isNativeComponentReady && (
145155
<View pointerEvents="none" style={styles.overlay}>
146156
<TraceUpdateOverlayNativeComponent
147157
ref={nativeComponentRef}

Libraries/ReactNative/AppContainer.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Props = $ReadOnly<{|
3232
type State = {|
3333
inspector: ?React.Node,
3434
devtoolsOverlay: ?React.Node,
35+
traceUpdateOverlay: ?React.Node,
3536
mainKey: number,
3637
hasError: boolean,
3738
|};
@@ -40,6 +41,7 @@ class AppContainer extends React.Component<Props, State> {
4041
state: State = {
4142
inspector: null,
4243
devtoolsOverlay: null,
44+
traceUpdateOverlay: null,
4345
mainKey: 1,
4446
hasError: false,
4547
};
@@ -75,7 +77,10 @@ class AppContainer extends React.Component<Props, State> {
7577
const devtoolsOverlay = (
7678
<DevtoolsOverlay inspectedView={this._mainRef} />
7779
);
78-
this.setState({devtoolsOverlay});
80+
const TraceUpdateOverlay =
81+
require('../Components/TraceUpdateOverlay/TraceUpdateOverlay').default;
82+
const traceUpdateOverlay = <TraceUpdateOverlay />;
83+
this.setState({devtoolsOverlay, traceUpdateOverlay});
7984
}
8085
}
8186
}
@@ -127,6 +132,7 @@ class AppContainer extends React.Component<Props, State> {
127132
<RootTagContext.Provider value={createRootTag(this.props.rootTag)}>
128133
<View style={styles.appContainer} pointerEvents="box-none">
129134
{!this.state.hasError && innerView}
135+
{this.state.traceUpdateOverlay}
130136
{this.state.devtoolsOverlay}
131137
{this.state.inspector}
132138
{logBox}

0 commit comments

Comments
 (0)