Skip to content

Commit

Permalink
feat(annotations): Exit annotations mode when enter fullscreen (#1196)
Browse files Browse the repository at this point in the history
* feat(annotations): Exit annotations mode when enter fullscreen

* feat(annotations): Address comments
  • Loading branch information
Mingze committed Apr 14, 2020
1 parent 72471f6 commit c689e42
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/lib/viewers/BaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
} from '../constants';
import { getIconFromExtension, getIconFromName } from '../icons/icons';
import { VIEWER_EVENT, ERROR_CODE, LOAD_METRIC, DOWNLOAD_REACHABILITY_METRICS } from '../events';
import { AnnotationMode } from '../AnnotationControls';
import PreviewError from '../PreviewError';
import Timer from '../Timer';

Expand Down Expand Up @@ -545,8 +546,12 @@ class BaseViewer extends EventEmitter {
*/
handleFullscreenEnter() {
this.resize();
if (this.annotator) {

if (this.annotator && this.options.showAnnotationsControls && this.annotationControls) {
this.annotator.emit(ANNOTATOR_EVENT.setVisibility, false);

this.annotator.toggleAnnotationMode(AnnotationMode.NONE);
this.annotationControls.resetControls();
}
}

Expand All @@ -557,7 +562,7 @@ class BaseViewer extends EventEmitter {
*/
handleFullscreenExit() {
this.resize();
if (this.annotator) {
if (this.annotator && this.options.showAnnotationsControls) {
this.annotator.emit(ANNOTATOR_EVENT.setVisibility, true);
}
}
Expand Down
17 changes: 16 additions & 1 deletion src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as util from '../../util';
import * as icons from '../../icons/icons';
import * as constants from '../../constants';
import { VIEWER_EVENT, LOAD_METRIC, ERROR_CODE } from '../../events';
import { AnnotationMode } from '../../AnnotationControls';
import Timer from '../../Timer';
import Api from '../../api';

Expand Down Expand Up @@ -526,14 +527,27 @@ describe('lib/viewers/BaseViewer', () => {
describe('handleFullscreenEnter()', () => {
it('should resize the viewer', () => {
sandbox.stub(base, 'resize');

base.handleFullscreenEnter();

expect(base.resize).to.be.called;
});

it('should hide annotations and toggle annotations mode', () => {
base.annotator = {
emit: sandbox.mock(),
toggleAnnotationMode: sandbox.mock(),
};
base.annotationControls = {
resetControls: sandbox.mock(),
};
base.options.showAnnotationsControls = true;

base.handleFullscreenEnter();

expect(base.resize).to.be.called;
expect(base.annotator.emit).to.be.calledWith(ANNOTATOR_EVENT.setVisibility, false);
expect(base.annotator.toggleAnnotationMode).to.be.calledWith(AnnotationMode.NONE);
expect(base.annotationControls.resetControls).to.be.called;
});
});

Expand All @@ -543,6 +557,7 @@ describe('lib/viewers/BaseViewer', () => {
base.annotator = {
emit: sandbox.mock(),
};
base.options.showAnnotationsControls = true;

base.handleFullscreenExit();

Expand Down

0 comments on commit c689e42

Please sign in to comment.