mirror of
https://github.com/lunaisnotaboy/mastodon.git
synced 2024-11-20 05:44:01 +00:00
Allow the media modal to be closed by pressing back (#7934)
This commit is contained in:
parent
6d45f768a6
commit
bbbe3ed6ba
|
@ -16,6 +16,8 @@ const messages = defineMessages({
|
||||||
next: { id: 'lightbox.next', defaultMessage: 'Next' },
|
next: { id: 'lightbox.next', defaultMessage: 'Next' },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const previewState = 'previewMediaModal';
|
||||||
|
|
||||||
@injectIntl
|
@injectIntl
|
||||||
export default class MediaModal extends ImmutablePureComponent {
|
export default class MediaModal extends ImmutablePureComponent {
|
||||||
|
|
||||||
|
@ -26,6 +28,10 @@ export default class MediaModal extends ImmutablePureComponent {
|
||||||
intl: PropTypes.object.isRequired,
|
intl: PropTypes.object.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static contextTypes = {
|
||||||
|
router: PropTypes.object,
|
||||||
|
};
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
index: null,
|
index: null,
|
||||||
navigationHidden: false,
|
navigationHidden: false,
|
||||||
|
@ -61,10 +67,20 @@ export default class MediaModal extends ImmutablePureComponent {
|
||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
window.addEventListener('keyup', this.handleKeyUp, false);
|
window.addEventListener('keyup', this.handleKeyUp, false);
|
||||||
|
const history = this.context.router.history;
|
||||||
|
history.push(history.location.pathname, previewState);
|
||||||
|
this.unlistenHistory = history.listen(() => {
|
||||||
|
this.props.onClose();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount () {
|
componentWillUnmount () {
|
||||||
window.removeEventListener('keyup', this.handleKeyUp);
|
window.removeEventListener('keyup', this.handleKeyUp);
|
||||||
|
this.unlistenHistory();
|
||||||
|
|
||||||
|
if (this.context.router.history.location.state === previewState) {
|
||||||
|
this.context.router.history.goBack();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getIndex () {
|
getIndex () {
|
||||||
|
|
Loading…
Reference in a new issue