Fix Height for Main Layout Inspector

Summary:
in Layout plugin, scrollbars where often not visible, for example to see the vertical scrollbar, one had to scroll to the horizontal end first.

Also introduced the `Scrollable` component to simplify this in the feature and separate the concepts of rendering something large and making it scrollable.

This diff cleans up the layout structure and fixes the problem

changelog: Fixed several minor layout issues in the Layout plugin

Reviewed By: cekkaewnumchai

Differential Revision: D21283157

fbshipit-source-id: 81849151475165796c65001616f038a9d6cbdfb2
This commit is contained in:
Michel Weststrate
2020-05-21 03:34:05 -07:00
committed by Facebook GitHub Bot
parent 22dfc33da0
commit b0ab9b9b98
5 changed files with 138 additions and 116 deletions

View File

@@ -0,0 +1,20 @@
/**
* Copyright (c) Facebook, Inc. and its 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 styled from '@emotion/styled';
const Scrollable: React.FC<{children: React.ReactNode}> = styled('div')({
width: '100%',
height: '100%',
overflow: 'auto',
});
Scrollable.displayName = 'Scrollable';
export default Scrollable;

View File

@@ -13,6 +13,7 @@ const VerticalRule = styled.div({
backgroundColor: '#c9ced4', backgroundColor: '#c9ced4',
width: 3, width: 3,
margin: '0', margin: '0',
flexShrink: 0,
}); });
VerticalRule.displayName = 'VerticalRule'; VerticalRule.displayName = 'VerticalRule';

View File

@@ -19,6 +19,7 @@ import Text from '../Text';
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import {clipboard, MenuItemConstructorOptions} from 'electron'; import {clipboard, MenuItemConstructorOptions} from 'electron';
import React, {MouseEvent, KeyboardEvent} from 'react'; import React, {MouseEvent, KeyboardEvent} from 'react';
import {Scrollable} from '../..';
export const ROW_HEIGHT = 23; export const ROW_HEIGHT = 23;
@@ -424,17 +425,9 @@ const ElementsContainer = styled(FlexColumn)({
backgroundColor: colors.white, backgroundColor: colors.white,
minHeight: '100%', minHeight: '100%',
minWidth: '100%', minWidth: '100%',
overflow: 'auto',
}); });
ElementsContainer.displayName = 'Elements:ElementsContainer'; ElementsContainer.displayName = 'Elements:ElementsContainer';
const ElementsBox = styled(FlexColumn)({
alignItems: 'flex-start',
flex: 1,
overflow: 'auto',
});
ElementsBox.displayName = 'Elements:ElementsBox';
export type DecorateRow = (e: Element) => ReactElement<any> | undefined | null; export type DecorateRow = (e: Element) => ReactElement<any> | undefined | null;
type ElementsProps = { type ElementsProps = {
@@ -710,14 +703,14 @@ export class Elements extends PureComponent<ElementsProps, ElementsState> {
render() { render() {
return ( return (
<ElementsBox> <Scrollable>
<ElementsContainer <ElementsContainer
onKeyDown={this.onKeyDown} onKeyDown={this.onKeyDown}
tabIndex={0} tabIndex={0}
ref={this._outerRef}> ref={this._outerRef}>
{this.state.flatElements.map(this.buildRow)} {this.state.flatElements.map(this.buildRow)}
</ElementsContainer> </ElementsContainer>
</ElementsBox> </Scrollable>
); );
} }
} }

View File

@@ -176,4 +176,5 @@ export {default as Info} from './components/Info';
export {default as Bordered} from './components/Bordered'; export {default as Bordered} from './components/Bordered';
export {default as AlternatingRows} from './components/AlternatingRows'; export {default as AlternatingRows} from './components/AlternatingRows';
export {default as Layout} from './components/Layout'; export {default as Layout} from './components/Layout';
export {default as Scrollable} from './components/Scrollable';
export * from './components/Highlight'; export * from './components/Highlight';

View File

@@ -12,7 +12,6 @@ import {
Element, Element,
ElementSearchResultSet, ElementSearchResultSet,
PluginClient, PluginClient,
FlexColumn,
FlexRow, FlexRow,
FlipperPlugin, FlipperPlugin,
Toolbar, Toolbar,
@@ -29,6 +28,7 @@ import {
ReduxState, ReduxState,
ArchivedDevice, ArchivedDevice,
ToolbarIcon, ToolbarIcon,
Layout,
} from 'flipper'; } from 'flipper';
import Inspector from './Inspector'; import Inspector from './Inspector';
import InspectorSidebar from './InspectorSidebar'; import InspectorSidebar from './InspectorSidebar';
@@ -80,7 +80,11 @@ const FlipperADButton = styled(Button)({
type ClientGetNodesCalls = 'getNodes' | 'getAXNodes'; type ClientGetNodesCalls = 'getNodes' | 'getAXNodes';
type ClientMethodCalls = 'getRoot' | 'getAXRoot' | ClientGetNodesCalls; type ClientMethodCalls = 'getRoot' | 'getAXRoot' | ClientGetNodesCalls;
export default class Layout extends FlipperPlugin<State, any, PersistedState> { export default class LayoutPlugin extends FlipperPlugin<
State,
any,
PersistedState
> {
FlipperADBar() { FlipperADBar() {
return ( return (
<FlipperADBarContainer> <FlipperADBarContainer>
@@ -122,7 +126,7 @@ export default class Layout extends FlipperPlugin<State, any, PersistedState> {
if (rootElement) { if (rootElement) {
statusUpdate && statusUpdate('Fetching Child Nodes...'); statusUpdate && statusUpdate('Fetching Child Nodes...');
await Layout.getAllNodes( await LayoutPlugin.getAllNodes(
rootElement, rootElement,
elements, elements,
callClient, callClient,
@@ -133,7 +137,7 @@ export default class Layout extends FlipperPlugin<State, any, PersistedState> {
const AXelements: ElementMap = {}; const AXelements: ElementMap = {};
if (rootAXElement) { if (rootAXElement) {
statusUpdate && statusUpdate('Fetching Child AX Nodes...'); statusUpdate && statusUpdate('Fetching Child AX Nodes...');
await Layout.getAllNodes( await LayoutPlugin.getAllNodes(
rootAXElement, rootAXElement,
AXelements, AXelements,
callClient, callClient,
@@ -167,7 +171,7 @@ export default class Layout extends FlipperPlugin<State, any, PersistedState> {
async ({elements}: {elements: Array<Element>}) => { async ({elements}: {elements: Array<Element>}) => {
await Promise.all( await Promise.all(
elements.map(async (elem) => { elements.map(async (elem) => {
await Layout.getAllNodes( await LayoutPlugin.getAllNodes(
elem, elem,
nodeMap, nodeMap,
callClient, callClient,
@@ -333,7 +337,7 @@ export default class Layout extends FlipperPlugin<State, any, PersistedState> {
ax: this.state.inAXMode, ax: this.state.inAXMode,
}); });
}; };
showFlipperADBar: boolean = false; showFlipperADBar: boolean = true;
getScreenDimensions(): {width: number; height: number} | null { getScreenDimensions(): {width: number; height: number} | null {
if (this.state.screenDimensions) { if (this.state.screenDimensions) {
@@ -405,25 +409,28 @@ export default class Layout extends FlipperPlugin<State, any, PersistedState> {
/> />
); );
const axInspector = this.state.inAXMode && ( const axInspector = this.state.inAXMode ? (
<FlexRow>
<VerticalRule />
<Inspector <Inspector
{...inspectorProps} {...inspectorProps}
onSelect={(selectedAXElement) => this.setState({selectedAXElement})} onSelect={(selectedAXElement) => this.setState({selectedAXElement})}
showsSidebar={true} showsSidebar={true}
ax ax
/> />
); </FlexRow>
) : null;
const divider = this.state.inAXMode && <VerticalRule />;
const showAnalyzeYogaPerformanceButton = GK.get('flipper_yogaperformance'); const showAnalyzeYogaPerformanceButton = GK.get('flipper_yogaperformance');
const screenDimensions = this.getScreenDimensions(); const screenDimensions = this.getScreenDimensions();
if (!this.state.init) {
return null;
}
return ( return (
<FlexColumn grow={true}>
{this.state.init && (
<> <>
<Layout.Top>
<Toolbar> <Toolbar>
{!this.props.isArchivedDevice && ( {!this.props.isArchivedDevice && (
<ToolbarIcon <ToolbarIcon
@@ -449,8 +456,7 @@ export default class Layout extends FlipperPlugin<State, any, PersistedState> {
active={this.state.inAlignmentMode} active={this.state.inAlignmentMode}
/> />
)} )}
{this.props.isArchivedDevice && {this.props.isArchivedDevice && this.state.visualizerScreenshot && (
this.state.visualizerScreenshot && (
<ToolbarIcon <ToolbarIcon
onClick={this.onToggleVisualizer} onClick={this.onToggleVisualizer}
title="Toggle visual recreation of layout" title="Toggle visual recreation of layout"
@@ -470,12 +476,15 @@ export default class Layout extends FlipperPlugin<State, any, PersistedState> {
initialQuery={this.props.deepLinkPayload} initialQuery={this.props.deepLinkPayload}
/> />
</Toolbar> </Toolbar>
<FlexRow grow={true}> <Layout.Bottom>
<Layout.Right>
{inspector} {inspector}
{divider}
{axInspector} {axInspector}
</FlexRow> </Layout.Right>
{this.showFlipperADBar && this.FlipperADBar()} {this.showFlipperADBar ? this.FlipperADBar() : null}
</Layout.Bottom>
</Layout.Top>
<DetailSidebar> <DetailSidebar>
<InspectorSidebar <InspectorSidebar
client={this.getClient()} client={this.getClient()}
@@ -512,8 +521,6 @@ export default class Layout extends FlipperPlugin<State, any, PersistedState> {
'Loading...' 'Loading...'
))} ))}
</> </>
)}
</FlexColumn>
); );
} }
} }