Move Metro control buttons to titlebar

Summary:
The Metro control buttons are now in the titlebar. This has a few benefits:
- the buttons are accessible if you are inspecting other metro plugins
- the buttons are even usuable if you selected an app on the actual device. This should help with reducing the cognitive dissonance of having apps both as 'android' app and metro device
- killed the Metro plugin again :)

Reviewed By: nikoant

Differential Revision: D19789455

fbshipit-source-id: 476fd0af1d3fc7b51a33f1af6d3fc3578aeeefae
This commit is contained in:
Michel Weststrate
2020-02-11 07:27:00 -08:00
committed by Facebook Github Bot
parent 182b2a629d
commit 3dcfe9f3ae
4 changed files with 65 additions and 80 deletions

View File

@@ -7,16 +7,9 @@
* @format * @format
*/ */
import React from 'react'; import React, {useCallback} from 'react';
import { import {Button, ButtonGroup, MetroDevice, connect} from 'flipper';
FlipperDevicePlugin, import {State} from '../reducers';
Device,
View,
Button,
Toolbar,
ButtonGroup,
MetroDevice,
} from 'flipper';
type LogEntry = {}; type LogEntry = {};
@@ -24,8 +17,6 @@ export type PersistedState = {
logs: LogEntry[]; logs: LogEntry[];
}; };
type State = {};
/* /*
Flow types for events Flow types for events
@@ -120,22 +111,15 @@ export type ReportableEvent =
}; };
*/ */
export default class MetroPlugin extends FlipperDevicePlugin< type Props = {
State, device: MetroDevice;
any, };
PersistedState
> {
static supportsDevice(device: Device) {
return device.os === 'Metro';
}
get ws(): WebSocket { function MetroButton({device}: Props) {
return (this.device as MetroDevice).ws; const sendCommand = useCallback(
} (command: string) => {
if (device.ws) {
sendCommand(command: string) { device.ws.send(
if (this.ws) {
this.ws.send(
JSON.stringify({ JSON.stringify({
version: 2, version: 2,
type: 'command', type: 'command',
@@ -143,29 +127,34 @@ export default class MetroPlugin extends FlipperDevicePlugin<
}), }),
); );
} }
} },
[device],
render() { );
return (
<View> return (
<Toolbar> <ButtonGroup>
<ButtonGroup> <Button
Work-in-progress title="Reload React Native App"
<Button icon="arrows-circle"
onClick={() => { compact
this.sendCommand('reload'); onClick={() => {
}}> sendCommand('reload');
Reload RN }}
</Button> />
<Button <Button
onClick={() => { title="Open the React Native Dev Menu on the device"
this.sendCommand('devMenu'); icon="navicon"
}}> compact
Dev Menu onClick={() => {
</Button> sendCommand('devMenu');
</ButtonGroup> }}
</Toolbar> />
</View> </ButtonGroup>
); );
}
} }
export default connect<Props, {}, {}, State>(({connections: {devices}}) => ({
device: devices.find(
device => device.os === 'Metro' && !device.isArchived,
) as MetroDevice,
}))(MetroButton);

View File

@@ -42,9 +42,10 @@ import {isAutoUpdaterEnabled} from '../utils/argvUtils';
import isProduction from '../utils/isProduction'; import isProduction from '../utils/isProduction';
import {clipboard} from 'electron'; import {clipboard} from 'electron';
import React from 'react'; import React from 'react';
import {State} from 'src/reducers'; import {State} from '../reducers';
import {reportUsage} from '../utils/metrics'; import {reportUsage} from '../utils/metrics';
import FpsGraph from './FpsGraph'; import FpsGraph from './FpsGraph';
import MetroButton from './MetroButton';
const AppTitleBar = styled(FlexRow)<{focused?: boolean}>(({focused}) => ({ const AppTitleBar = styled(FlexRow)<{focused?: boolean}>(({focused}) => ({
background: focused background: focused
@@ -83,6 +84,7 @@ type StateFromProps = {
launcherMsg: LauncherMsg; launcherMsg: LauncherMsg;
share: ShareType | null | undefined; share: ShareType | null | undefined;
navPluginIsActive: boolean; navPluginIsActive: boolean;
isMetroActive: boolean;
}; };
const VersionText = styled(Text)({ const VersionText = styled(Text)({
@@ -144,7 +146,7 @@ function statusMessageComponent(
type Props = OwnProps & DispatchFromProps & StateFromProps; type Props = OwnProps & DispatchFromProps & StateFromProps;
class TitleBar extends React.Component<Props, StateFromProps> { class TitleBar extends React.Component<Props, StateFromProps> {
render() { render() {
const {navPluginIsActive, share} = this.props; const {navPluginIsActive, share, isMetroActive} = this.props;
return ( return (
<AppTitleBar focused={this.props.windowIsFocused} className="toolbar"> <AppTitleBar focused={this.props.windowIsFocused} className="toolbar">
{navPluginIsActive ? ( {navPluginIsActive ? (
@@ -156,6 +158,8 @@ class TitleBar extends React.Component<Props, StateFromProps> {
<DevicesButton /> <DevicesButton />
)} )}
{isMetroActive ? <MetroButton /> : null}
<ScreenCaptureButtons /> <ScreenCaptureButtons />
{statusMessageComponent( {statusMessageComponent(
this.props.downloadingImportData, this.props.downloadingImportData,
@@ -238,7 +242,7 @@ export default connect<StateFromProps, DispatchFromProps, OwnProps, State>(
launcherMsg, launcherMsg,
share, share,
}, },
connections: {selectedDevice, selectedApp}, connections: {selectedDevice, selectedApp, devices},
pluginStates, pluginStates,
}) => { }) => {
const navigationPluginKey = getPluginKey( const navigationPluginKey = getPluginKey(
@@ -247,6 +251,9 @@ export default connect<StateFromProps, DispatchFromProps, OwnProps, State>(
'Navigation', 'Navigation',
); );
const navPluginIsActive = !!pluginStates[navigationPluginKey]; const navPluginIsActive = !!pluginStates[navigationPluginKey];
const isMetroActive = !!devices.find(
device => device.os === 'Metro' && !device.isArchived,
);
return { return {
windowIsFocused, windowIsFocused,
@@ -257,6 +264,7 @@ export default connect<StateFromProps, DispatchFromProps, OwnProps, State>(
launcherMsg, launcherMsg,
share, share,
navPluginIsActive, navPluginIsActive,
isMetroActive,
}; };
}, },
{ {

View File

@@ -1,18 +0,0 @@
{
"name": "Metro",
"version": "0.1.0",
"description": "A plugin to manage React Native applications served trough Metro",
"main": "index.tsx",
"repository": "https://github.com/facebook/flipper",
"license": "MIT",
"keywords": [
"flipper-plugin",
"react-native",
"metro"
],
"title": "Metro Bundler",
"bugs": {
"email": "mweststrate@fb.com"
},
"dependencies": {}
}

View File

@@ -365,5 +365,11 @@
], ],
"plus-circle-outline": [ "plus-circle-outline": [
16 16
],
"arrows-circle": [
12
],
"navicon": [
12
] ]
} }