mirror of
https://github.com/apache/cordova-plugin-screen-orientation.git
synced 2025-05-05 01:32:59 +08:00
Added fix for ios so device returns to current orientation when unlocked
This commit is contained in:
parent
ad5a2134e8
commit
efe1edede3
@ -30,9 +30,8 @@ SOFTWARE.
|
|||||||
// this method does not control the orientation, it is set in the .js file.
|
// this method does not control the orientation, it is set in the .js file.
|
||||||
|
|
||||||
// SEE https://github.com/Adlotto/cordova-plugin-recheck-screen-orientation
|
// SEE https://github.com/Adlotto/cordova-plugin-recheck-screen-orientation
|
||||||
// ------------------
|
|
||||||
|
|
||||||
// HACK: Force rotate by changing the view hierarchy. Present modal view then dismiss it immediately.
|
// HACK: Force rotate by changing the view hierarchy. Present modal view then dismiss it immediately.
|
||||||
|
|
||||||
UIViewController *vc = [[UIViewController alloc] init];
|
UIViewController *vc = [[UIViewController alloc] init];
|
||||||
vc.view.alpha = 0;
|
vc.view.alpha = 0;
|
||||||
|
|
||||||
@ -43,10 +42,29 @@ SOFTWARE.
|
|||||||
});
|
});
|
||||||
}];
|
}];
|
||||||
|
|
||||||
// Assume everything went ok
|
// grab the device orientation so we can pass it back to the js side.
|
||||||
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
NSString *orientation;
|
||||||
|
switch ([[UIDevice currentDevice] orientation]) {
|
||||||
|
case UIDeviceOrientationLandscapeLeft:
|
||||||
|
orientation = @"landscape-secondary";
|
||||||
|
break;
|
||||||
|
case UIDeviceOrientationLandscapeRight:
|
||||||
|
orientation = @"landscape-primary";
|
||||||
|
break;
|
||||||
|
case UIDeviceOrientationPortrait:
|
||||||
|
orientation = @"portrait-primary";
|
||||||
|
break;
|
||||||
|
case UIDeviceOrientationPortraitUpsideDown:
|
||||||
|
orientation = @"portrait-secondary";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
orientation = @"portait";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
|
||||||
|
messageAsDictionary:@{@"device":orientation}];
|
||||||
|
|
||||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||||
// ------------------
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
@ -1,5 +1,6 @@
|
|||||||
var exec = require('cordova/exec'),
|
var exec = require('cordova/exec'),
|
||||||
screenOrientation = {},
|
screenOrientation = {},
|
||||||
|
iosOrientation = 'unlocked',
|
||||||
orientationMap = {
|
orientationMap = {
|
||||||
'portrait': [0,180],
|
'portrait': [0,180],
|
||||||
'portrait-primary': [0],
|
'portrait-primary': [0],
|
||||||
@ -11,14 +12,26 @@ var exec = require('cordova/exec'),
|
|||||||
};
|
};
|
||||||
|
|
||||||
screenOrientation.setOrientation = function(orientation) {
|
screenOrientation.setOrientation = function(orientation) {
|
||||||
exec(null, null, "YoikScreenOrientation", "screenOrientation", ['set', orientation]);
|
iosOrientation = orientation;
|
||||||
|
|
||||||
|
var success = function(res) {
|
||||||
|
if (orientation === 'unlocked' && res.device) {
|
||||||
|
iosOrientation = res.device;
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
iosOrientation = 'unlocked';
|
||||||
|
},0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
exec(success, null, "YoikScreenOrientation", "screenOrientation", ['set', orientation]);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = screenOrientation;
|
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 = iosOrientation,
|
||||||
map = orientationMap[currOrientation] || orientationMap['default'];
|
map = orientationMap[currOrientation] || orientationMap['default'];
|
||||||
return map.indexOf(orientation) >= 0;
|
return map.indexOf(orientation) >= 0;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user