cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michal Mocny <mmo...@google.com>
Subject iOS: shouldRotateToOrientation javascript handler
Date Fri, 05 Jul 2013 14:18:51 GMT
iOS seems to have an undocumented "feature" to call into javascript before
every device orientation change (pasted below for your viewing pleasure).

I can't find any such similar functionality on other platforms, should it
be removed?  Likely we will want to write a screen orientation (
http://www.w3.org/TR/screen-orientation/) plugin instead (eventually).


-
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // First, ask the webview via JS if it supports the new orientation
    NSString* jsCall = [NSString stringWithFormat:
        @"window.shouldRotateToOrientation &&
window.shouldRotateToOrientation(%d);"
        , [self mapIosOrientationToJsOrientation:interfaceOrientation]];
    NSString* res = [webView stringByEvaluatingJavaScriptFromString:jsCall];

    if ([res length] > 0) {
        return [res boolValue];
    }

    // if js did not handle the new orientation (no return value), use
values from the plist (via supportedOrientations)
    return [self supportsOrientation:interfaceOrientation];
}

-Michal

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message