From cf176bb071e7afcbedfad2caf1ca6a7da66a888a Mon Sep 17 00:00:00 2001 From: Luke De Feo Date: Wed, 21 Sep 2022 07:02:48 -0700 Subject: [PATCH] Basic 2D wireframe Summary: Basic visual wireframe for the purposes of verifying that our captured view hierachy is correct, the actual version we ship will hopefully be a lot better :) Reviewed By: lblasa Differential Revision: D39539278 fbshipit-source-id: 73d926ff1990f09ca9877430cb227f690d05d1d4 --- .../components/Visualization2D.tsx | 118 ++++++++++++++++++ .../public/ui-debugger/components/main.tsx | 14 ++- 2 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 desktop/plugins/public/ui-debugger/components/Visualization2D.tsx diff --git a/desktop/plugins/public/ui-debugger/components/Visualization2D.tsx b/desktop/plugins/public/ui-debugger/components/Visualization2D.tsx new file mode 100644 index 000000000..799265d14 --- /dev/null +++ b/desktop/plugins/public/ui-debugger/components/Visualization2D.tsx @@ -0,0 +1,118 @@ +/** + * 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 from 'react'; +import {Bounds, Id, Tag, UINode} from '../types'; +import {styled, Layout} from 'flipper-plugin'; +import {Typography} from 'antd'; + +export const Visualization2D: React.FC< + {root: Id; nodes: Map} & React.HTMLAttributes +> = ({root, nodes}) => { + // + const bounds = nodes.get(root)?.bounds; + const rootBorderStyle = bounds + ? { + borderWidth: '3px', + margin: '-3px', + borderStyle: 'solid', + borderColor: 'black', + width: bounds.width / 2, + height: bounds.height / 2, + } + : {}; + return ( + + Visualizer +
+ ; +
+
+ ); +}; + +function VisualizationNode({ + nodeId, + nodes, + isRoot, +}: { + isRoot: boolean; + nodeId: Id; + nodes: Map; +}) { + const node = nodes.get(nodeId); + + if (!node) { + return null; + } + + let childrenIds = node.children; + + //if there is an active child dont draw the other children + //this means we don't draw overlapping activities / tabs + if (node.activeChild) { + childrenIds = [node.activeChild]; + } + const children = childrenIds.map((childId) => ( + + )); + + const hasOverlappingChild = childrenIds + .map((id) => nodes.get(id)) + .find((child) => child?.bounds?.x === 0 || child?.bounds?.y === 0); + + const isZeroWidthOrHeight = + node.bounds?.height === 0 || node.bounds?.width === 0; + return ( + + {/* Dirty hack to avoid showing highly overlapping text */} + {!hasOverlappingChild && !isZeroWidthOrHeight && node.bounds + ? node.name + : null} + {children} + + ); +} + +const BoundsBox = styled.div<{ + bounds?: Bounds; + isRoot: boolean; + tags: Tag[]; +}>((props) => { + const bounds = props.bounds ?? {x: 0, y: 0, width: 0, height: 0}; + return { + // borderWidth: props.isRoot ? '5px' : '1px', + borderWidth: '1px', + //to offset the border + margin: '-1px', + borderColor: props.tags.includes('Declarative') + ? 'green' + : props.tags.includes('Native') + ? 'blue' + : 'black', + borderStyle: 'solid', + position: 'absolute', + //todo need to understand why its so big and needs halving + left: bounds.x / 2, + top: bounds.y / 2, + width: bounds.width / 2, + height: bounds.height / 2, + }; +}); diff --git a/desktop/plugins/public/ui-debugger/components/main.tsx b/desktop/plugins/public/ui-debugger/components/main.tsx index 4ad28e148..3000e5d7a 100644 --- a/desktop/plugins/public/ui-debugger/components/main.tsx +++ b/desktop/plugins/public/ui-debugger/components/main.tsx @@ -22,6 +22,7 @@ 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); @@ -55,11 +56,14 @@ export function Component() { return ( <> - + + + + {selectedNode && renderAttributesInspector(nodes.get(selectedNode))}