diff --git a/src/chrome/LocationsButton.js b/src/chrome/LocationsButton.js new file mode 100644 index 000000000..01a5a7d57 --- /dev/null +++ b/src/chrome/LocationsButton.js @@ -0,0 +1,60 @@ +/** + * Copyright 2018-present Facebook. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * @format + */ + +import {Button, Component, styled} from 'flipper'; +import {connect} from 'react-redux'; + +import type BaseDevice from '../devices/BaseDevice'; +import AndroidDevice from '../devices/AndroidDevice'; + +type OwnProps = {| + locations: Array, + selectedLocation?: string, +|}; + +type Props = {| + ...OwnProps, + selectedDevice?: BaseDevice, +|}; + +const DropdownButton = styled(Button)({ + fontSize: 11, +}); + +class LocationsButton extends Component { + goToLocation = (location: string) => { + const {selectedDevice} = this.props; + if (selectedDevice instanceof AndroidDevice) { + let shellCommand = `am start ${location}`; + selectedDevice.adb.shell(selectedDevice.serial, shellCommand); + } + }; + + render() { + const {locations, selectedLocation} = this.props; + return ( + { + return { + click: () => { + this.goToLocation(location); + }, + label: location, + }; + })}> + {selectedLocation || '(none)'} + + ); + } +} + +export default connect( + ({connections: {selectedDevice}}) => ({ + selectedDevice, + }), +)(LocationsButton);