Cleaned up messy switch/if block in iOS js file.

This commit is contained in:
Grant Benvenuti 2014-09-02 18:30:58 +10:00
parent abc38a52cb
commit 7c86844895

View File

@ -9,29 +9,17 @@ module.exports = screenOrientation;
// ios orientation callback/hook // ios orientation callback/hook
window.shouldRotateToOrientation = function(orientation) { window.shouldRotateToOrientation = function(orientation) {
var currOrientation = cordova.plugins.screenorientation.currOrientation; var currOrientation = cordova.plugins.screenorientation.currOrientation,
switch (currOrientation) { orientationMap = {
case 'portrait': 'portrait': [0,180],
if (orientation === 0 || orientation === 180) return true; 'portrait-primary': [0],
break; 'portrait-secondary': [180],
case 'portrait-primary': 'landscape': [-90,90],
if (orientation === 0) return true; 'landscape-primary': [-90],
break; 'landscape-secondary': [90],
case 'portrait-secondary': 'default': [-90,90,0]
if (orientation === 180) return true; },
break; map = orientationMap[currOrientation] || orientationMap['default'];
case 'landscape':
if (orientation === -90 || orientation === 90) return true; return map.indexOf(orientation) >= 0;
break;
case 'landscape-primary':
if (orientation === -90) return true;
break;
case 'landscape-secondary':
if (orientation === 90) return true;
break;
default:
if (orientation === -90 || orientation === 90 || orientation === 0) return true;
break;
}
return false;
}; };