Skip to content
Snippets Groups Projects
Commit 3625c3a8 authored by Josiah Neuberger's avatar Josiah Neuberger
Browse files

added hitting escape button exits fullscreen mode

parent 79d97a31
No related branches found
No related tags found
No related merge requests found
......@@ -42,6 +42,7 @@ const messages = defineMessages({
const StageHeaderComponent = function (props) {
const {
isFullScreen,
onKeyPress,
onSetStageLarge,
onSetStageFull,
onSetStageUnFull,
......@@ -58,6 +59,7 @@ const StageHeaderComponent = function (props) {
<Button
className={styles.stageButton}
onClick={onSetStageUnFull}
onKeyPress={onKeyPress}
>
<img
alt={props.intl.formatMessage(messages.unFullStageSizeMessage)}
......@@ -138,6 +140,7 @@ const StageHeaderComponent = function (props) {
StageHeaderComponent.propTypes = {
intl: intlShape,
isFullScreen: PropTypes.bool.isRequired,
onKeyPress: PropTypes.func.isRequired,
onSetStageFull: PropTypes.func.isRequired,
onSetStageLarge: PropTypes.func.isRequired,
onSetStageUnFull: PropTypes.func.isRequired,
......
import PropTypes from 'prop-types';
import React from 'react';
import bindAll from 'lodash.bindall';
import VM from 'scratch-vm';
import {setStageSize, setFullScreen, STAGE_SIZES} from '../reducers/stage-size';
......@@ -9,6 +10,23 @@ import StageHeaderComponent from '../components/stage-header/stage-header.jsx';
// eslint-disable-next-line react/prefer-stateless-function
class StageHeader extends React.Component {
constructor (props) {
super(props);
bindAll(this, [
'handleKeyPress'
]);
}
componentDidMount () {
document.addEventListener('keydown', this.handleKeyPress);
}
componentWillUnmount () {
document.removeEventListener('keydown', this.handleKeyPress);
}
handleKeyPress (event) {
if (event.key === 'Escape' && this.props.isFullScreen) {
this.props.onSetStageUnFull(false);
}
}
render () {
const {
...props
......@@ -16,12 +34,15 @@ class StageHeader extends React.Component {
return (
<StageHeaderComponent
{...props}
onKeyPress={this.handleKeyPress}
/>
);
}
}
StageHeader.propTypes = {
isFullScreen: PropTypes.bool.isRequired,
onSetStageUnFull: PropTypes.func.isRequired,
stageSize: PropTypes.oneOf(Object.keys(STAGE_SIZES)),
vm: PropTypes.instanceOf(VM).isRequired
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment