-
Notifications
You must be signed in to change notification settings - Fork 51k
Expand file tree
/
Copy pathindex.js
More file actions
68 lines (59 loc) · 1.95 KB
/
index.js
File metadata and controls
68 lines (59 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* 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
*/
import * as React from 'react';
import {useContext, useMemo} from 'react';
import {StoreContext} from 'react-devtools-shared/src/devtools/views/context';
import {useSubscription} from 'react-devtools-shared/src/devtools/views/hooks';
import {TreeStateContext} from 'react-devtools-shared/src/devtools/views/Components/TreeContext';
import {NativeStyleContext} from './context';
import LayoutViewer from './LayoutViewer';
import StyleEditor from './StyleEditor';
import styles from './index.css';
export default function NativeStyleEditorWrapper(): React.Node {
const store = useContext(StoreContext);
const subscription = useMemo(
() => ({
getCurrentValue: () => store.supportsNativeStyleEditor,
subscribe: (callback: Function) => {
store.addListener('supportsNativeStyleEditor', callback);
return () => {
store.removeListener('supportsNativeStyleEditor', callback);
};
},
}),
[store],
);
const supportsNativeStyleEditor = useSubscription<boolean>(subscription);
if (!supportsNativeStyleEditor) {
return null;
}
return <NativeStyleEditor />;
}
function NativeStyleEditor() {
const {inspectedElementID} = useContext(TreeStateContext);
const inspectedElementStyleAndLayout = useContext(NativeStyleContext);
if (inspectedElementID === null) {
return null;
}
if (inspectedElementStyleAndLayout === null) {
return null;
}
const {layout, style} = inspectedElementStyleAndLayout;
if (layout === null && style === null) {
return null;
}
return (
<div className={styles.Stack}>
{layout !== null && (
<LayoutViewer id={inspectedElementID} layout={layout} />
)}
{style !== null && <StyleEditor id={inspectedElementID} style={style} />}
</div>
);
}