Files
flipper/desktop/plugins/public/ui-debugger/components/main.tsx
Luke De Feo f3b7552338 2D wire frame highlight from tree, select from wireframe
Summary:
Introduced some basic bidirectional link between tree and wireframe, the specific interaction will need some tweaking but this should get us started.

When hovering over the tree we halt the rendering of the wireframe up to that point, this allows us to explore parent views that layout child views.

When clicking a view in the wireframe it is 'seleceted' as if it was clicked in the tree. This set the tree selection so you can identify it in the tree as well as opens the side bar

Reviewed By: lblasa

Differential Revision: D39539277

fbshipit-source-id: 3beb1ad4cb56b398c640ac3e7fac2cc97f3f1a18
2022-09-21 07:02:48 -07:00

83 lines
2.2 KiB
TypeScript

/**
* 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.
*
* @format
*/
import React, {useState} from 'react';
import {plugin} from '../index';
import {
DataInspector,
DetailSidebar,
Layout,
usePlugin,
useValue,
} from 'flipper-plugin';
import {Typography} from 'antd';
import {useHotkeys} from 'react-hotkeys-hook';
import {Id, UINode} from '../types';
import {PerfStats} from './PerfStats';
import {Tree} from './Tree';
import {Visualization2D} from './Visualization2D';
export function Component() {
const instance = usePlugin(plugin);
const rootId = useValue(instance.rootId);
const nodes: Map<Id, UINode> = useValue(instance.nodes);
const [showPerfStats, setShowPerfStats] = useState(false);
const [selectedNode, setSelectedNode] = useState<Id | undefined>(undefined);
const [hoveredNode, setHoveredNode] = useState<Id | undefined>(undefined);
useHotkeys('ctrl+i', () => setShowPerfStats((show) => !show));
function renderAttributesInspector(node: UINode | undefined) {
if (!node) {
return;
}
return (
<>
<DetailSidebar>
<Layout.Container gap pad>
<Typography.Title level={2}>Attributes Inspector</Typography.Title>
<DataInspector data={node} expandRoot />
</Layout.Container>
</DetailSidebar>
</>
);
}
if (showPerfStats) return <PerfStats events={instance.perfEvents} />;
if (rootId) {
return (
<>
<Layout.ScrollContainer>
<Layout.Horizontal>
<Tree
selectedNode={selectedNode}
onSelectNode={setSelectedNode}
onHoveredNode={setHoveredNode}
nodes={nodes}
rootId={rootId}
/>
<Visualization2D
root={rootId}
nodes={nodes}
hoveredNode={hoveredNode}
onSelectNode={setSelectedNode}
/>
</Layout.Horizontal>
</Layout.ScrollContainer>
{selectedNode && renderAttributesInspector(nodes.get(selectedNode))}
</>
);
}
return <div>Nothing yet</div>;
}