{"action":"opened","issue":{"url":"https://api.github.com/repos/gbenvenuti/cordova-plugin-screen-orientation/issues/121","repository_url":"https://api.github.com/repos/gbenvenuti/cordova-plugin-screen-orientation","labels_url":"https://api.github.com/repos/gbenvenuti/cordova-plugin-screen-orientation/issues/121/labels{/name}","comments_url":"https://api.github.com/repos/gbenvenuti/cordova-plugin-screen-orientation/issues/121/comments","events_url":"https://api.github.com/repos/gbenvenuti/cordova-plugin-screen-orientation/issues/121/events","html_url":"https://github.com/gbenvenuti/cordova-plugin-screen-orientation/issues/121","id":178023771,"number":121,"title":"lockOrientation + unlockOrientation called synchronously breaks rotation","user":{"login":"jrencz","id":948356,"avatar_url":"https://avatars.githubusercontent.com/u/948356?v=3","gravatar_id":"","url":"https://api.github.com/users/jrencz","html_url":"https://github.com/jrencz","followers_url":"https://api.github.com/users/jrencz/followers","following_url":"https://api.github.com/users/jrencz/following{/other_user}","gists_url":"https://api.github.com/users/jrencz/gists{/gist_id}","starred_url":"https://api.github.com/users/jrencz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrencz/subscriptions","organizations_url":"https://api.github.com/users/jrencz/orgs","repos_url":"https://api.github.com/users/jrencz/repos","events_url":"https://api.github.com/users/jrencz/events{/privacy}","received_events_url":"https://api.github.com/users/jrencz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-20T10:31:46Z","updated_at":"2016-09-20T10:31:46Z","closed_at":null,"body":"Background:\r\nIn my app I'm using portrait lock for pretty much every view but I allow user to rotate on one view.\r\nThen after user goes away from that one special view I'd like to enforce portrait back. That works.\r\n\r\nI was playing around with the plugin and I found out that calling \r\n\r\n```js\r\nwindow.screen.lockOrientation('portrait');\r\nwindow.screen.unlockOrientation();\r\n```\r\n\r\n(just to enforce portrait but without preserving the lock) does not work.\r\nIt enforces portrait but rotation becomes permanently locked. Even when I call `window.screen.unlockOrientation();` long after that the orientation becomes locked.\r\n\r\nOn the other hand calling\r\n\r\n```js\r\n\r\nwindow.screen.lockOrientation('portrait');\r\nwindow.setTimeout(function () {\r\n  window.screen.unlockOrientation();\r\n} );\r\n```\r\n\r\nworks as expected: it enforces portrait and unlock rotation.\r\n\r\nBest (and most meaningful) helper I came up with was:\r\n\r\n```js\r\nfunction rotateTo(orientation) {\r\n  window.screen.lockOrientation(orientation); \r\n  window.addEventListener('orientationchange', function unlockOnOrientationChange(){\r\n    window.screen.unlockOrientation();\r\n    window.removeEventListener('orientationchange', unlockOnOrientationChange);\r\n  });\r\n}\r\n```\r\n\r\n(it waits until orientation change takes place and then it unlocks).\r\n\r\nI was testing on ios 10.0.1\r\nI presume the `window.screen.unlockOrientation` was dropped for some reason (maybe because previous action was taking place at the moment) but I can't explain myself why rotation becomes permanently broken.\r\n\r\nI suggest that apart from fixing the permanent lock issue you may extend the `lockOrientation`: It may return a promise resolved after `orientationchange` event is fired (or it should take a callback)."}}
{"actor":{"display_login":"jrencz"}}