Skip to content

Commit

Permalink
Fix intel#66 - reset orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
kenchris committed Sep 21, 2018
1 parent 64c8821 commit f52d7fd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
12 changes: 8 additions & 4 deletions sensor-tester/src/orientation-changer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@ export class OrientationChanger extends LitElement {
|| docEl.mozRequestFullScreen || docEl.msRequestFullscreen;
this._cancelFullScreen = document.exitFullscreen || document.webkitExitFullscreen
|| document.mozCancelFullScreen || document.msExitFullscreen;
this._orientation = screen.msOrientation || (screen.orientation || screen.mozOrientation || {});
screen.orientation.addEventListener('change', () => {
this._cancelFullScreen.call(document);
this.shadowRoot.querySelector('#one').checked = true;
});
}

async lock(orientation) {
this._requestFullScreen.call(document.documentElement);
try {
await this._orientation.lock(orientation);
await screen.orientation.lock(orientation);
} catch(err) {
console.log("screen.orientation.lock() is not available on this device.");
console.log("Cannot lock to the requested orientation.");
this._cancelFullScreen.call(document);
this.shadowRoot.querySelector('#one').checked = true;
};
}

unlock() {
this._orientation.unlock();
screen.orientation.unlock();
this._cancelFullScreen.call(document);
this.shadowRoot.querySelector('#one').checked = true;
}
Expand Down
3 changes: 3 additions & 0 deletions sensor-tester/src/sensor-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class SensorTester extends LitElement {

const parts = pathname.slice(1).split('/');
this.page = parts[parts.length - 1] || 'accelerometer';
if (screen.orientation) {
screen.orientation.unlock();
}
if (this.drawer && !this.drawer.persistent) {
this.drawer.close();
}
Expand Down
2 changes: 1 addition & 1 deletion sensor-tester/src/sensor-tests-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class SensorTestsPage extends LitElement {
<div class="${classMap({'hidden': this.isSupported})}">Sensor is not supported by the browser or the device.</div>
<div class="${classMap({'hidden': !this.isSupported})}">
<div class="${this.referenceFrame}">
<div class="${classMap({'hidden': this.referenceFrame === 'device' || !screen.orientation})}">
<orientation-changer></orientation-changer>
</div>
Expand Down

0 comments on commit f52d7fd

Please sign in to comment.