This is an automated email from the ASF dual-hosted git repository. jcesarmobile pushed a commit to branch use-clobbers in repository https://gitbox.apache.org/repos/asf/cordova-plugin-screen-orientation.git
commit f8479d5c7bc938edf782bf4ebcedc0cfa8ceb7e8 Author: jcesarmobile <[email protected]> AuthorDate: Fri Apr 21 01:47:22 2023 +0200 fix(ios): use clobbers to overwrite screen.orientation --- plugin.xml | 1 + www/screenorientation.js | 65 +++++++++++++++--------------------------------- 2 files changed, 21 insertions(+), 45 deletions(-) diff --git a/plugin.xml b/plugin.xml index 2bd62d7..fa04b9e 100644 --- a/plugin.xml +++ b/plugin.xml @@ -29,6 +29,7 @@ <js-module src="www/screenorientation.js" name="screenorientation"> <clobbers target="cordova.plugins.screenorientation" /> + <clobbers target="screen.orientation" /> </js-module> <platform name="ios"> diff --git a/www/screenorientation.js b/www/screenorientation.js index 4e98e9a..f8e3ce9 100644 --- a/www/screenorientation.js +++ b/www/screenorientation.js @@ -47,42 +47,19 @@ screenOrientation.setOrientation = function (orientation) { cordova.exec(null, null, 'CDVOrientation', 'screenOrientation', [orientationMask, orientation]); }; -if (!screen.orientation) { - screen.orientation = {}; +screenOrientation.lock = function (orientation) { + var p = new Promise(function (resolve, reject) { + resolveOrientation(orientation, resolve, reject); + }); + return p; } -setOrientationProperties(); - -function addScreenOrientationApi (screenObject) { - if (screenObject.unlock || screenObject.lock) { - screenObject.nativeLock = screenObject.lock; - } - - screenObject.lock = function (orientation) { - var promiseLock; - var p = new Promise(function (resolve, reject) { - if (screenObject.nativeLock) { - promiseLock = screenObject.nativeLock(orientation); - promiseLock.then( - function success (_) { - resolve(); - }, - function error (_) { - screenObject.nativeLock = null; - resolveOrientation(orientation, resolve, reject); - } - ); - } else { - resolveOrientation(orientation, resolve, reject); - } - }); - return p; - }; - screenObject.unlock = function () { - screenOrientation.setOrientation('any'); - }; +screenOrientation.unlock = function() { + screenOrientation.setOrientation('any'); } +setOrientationProperties(); + function resolveOrientation (orientation, resolve, reject) { if (!Object.prototype.hasOwnProperty.call(OrientationLockType, orientation)) { var err = new Error(); @@ -94,18 +71,16 @@ function resolveOrientation (orientation, resolve, reject) { } } -addScreenOrientationApi(screen.orientation); - var onChangeListener = null; -Object.defineProperty(screen.orientation, 'onchange', { +Object.defineProperty(screenOrientation, 'onchange', { set: function (listener) { if (onChangeListener) { - screen.orientation.removeEventListener('change', onChangeListener); + screenOrientation.removeEventListener('change', onChangeListener); } onChangeListener = listener; if (onChangeListener) { - screen.orientation.addEventListener('change', onChangeListener); + screenOrientation.addEventListener('change', onChangeListener); } }, get: function () { @@ -122,33 +97,33 @@ var orientationchange = function () { evtTarget.dispatchEvent(event); }; -screen.orientation.addEventListener = function (a, b, c) { +screenOrientation.addEventListener = function (a, b, c) { return evtTarget.addEventListener(a, b, c); }; -screen.orientation.removeEventListener = function (a, b, c) { +screenOrientation.removeEventListener = function (a, b, c) { return evtTarget.removeEventListener(a, b, c); }; function setOrientationProperties () { switch (window.orientation) { case 0: - screen.orientation.type = 'portrait-primary'; + screenOrientation.type = 'portrait-primary'; break; case 90: - screen.orientation.type = 'landscape-primary'; + screenOrientation.type = 'landscape-primary'; break; case 180: - screen.orientation.type = 'portrait-secondary'; + screenOrientation.type = 'portrait-secondary'; break; case -90: - screen.orientation.type = 'landscape-secondary'; + screenOrientation.type = 'landscape-secondary'; break; default: - screen.orientation.type = 'portrait-primary'; + screenOrientation.type = 'portrait-primary'; break; } - screen.orientation.angle = window.orientation || 0; + screenOrientation.angle = window.orientation || 0; } window.addEventListener('orientationchange', orientationchange, true); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
