Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(annotations): Exit annotations mode when enter fullscreen #1196

Merged
merged 2 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does passing nothing here work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does passing nothing here work?

No, it won't work because it sets state to undefined instead of '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