EddyVerbruggen / SocialSharing-PhoneGap-Plugin

👨‍❤️‍💋‍👨 Cordova plugin to share text, a file (image/PDF/..), or a URL (or all three) via the native sharing widget
MIT License
1.78k stars 909 forks source link

Share sheet does not respect orientation of App #376

Closed CookieCookson closed 4 years ago

CookieCookson commented 9 years ago

If you share while the device is in landscape on a portrait only iOS app, the app orientates into landscape, the share dialog comes up in landscape and the keyboard comes up in portrait.

share-bug

From this point I can rotate the device back to portrait then it locks back to portrait as originally intended (the rendered UI is still the landscape ui sizings but the width adjusts to fit). I cannot reproduce this with a native App so it must be an issue with the iOS version of the plugin. Any thoughts?

CookieCookson commented 9 years ago

Made some progress with this, quick way to get around this issue is to change your MainViewController.m with the following code:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown && interfaceOrientation == UIInterfaceOrientationPortrait);
}

I haven't found a way of modifying the plugin to get around this issue yet.

CookieCookson commented 9 years ago

Progress report: The above fix actually breaks a few other plugins (keyboard disappears on iPhone 4, InAppBrowser forgets there is a status bar). Use the new following code in your MainViewController.m to have the fix without breaking other plugins!

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if(interfaceOrientation == UIInterfaceOrientationPortrait)
        return YES;
    return NO;
}
EddyVerbruggen commented 9 years ago

Hi, I was playing with this a little and got a consistently rotating keyboard when using the code below:

// the default implementation:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return [super shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

// changed only this: YES --> NO
- (BOOL)shouldAutorotate
{
    return NO;
}

With your latest code I'm seeing the behaviour of the first screenshot when rotating my portrait-only app, pressing 'share' and picking Twitter.

Not sure if my code breaks anything with other plugins though (didn't test it).

CookieCookson commented 9 years ago

Cool thanks, I'll give it a go. What OS version were you testing on?

EddyVerbruggen commented 9 years ago

iPhone 6 / iOS 8.4.1.

CookieCookson commented 9 years ago

That fix doesn't work for me unfortunately. It does the same issue I was having originally, except it keeps the app and the share dialog fixed in landscape while present and only the keyboard will rotate between portrait/landscape.

I'm quite happy with the code I am using mentioned above for now, I think you would have to modify the plugin's way of handling interface orientation through a custom view or something for a committable fix.

EDIT: since trying out your fix and reverting to my code the above no longer seems to work. :disappointed:

EDIT2: Managed to get it working again. This time I changed the supportedInterfaceOrientationsForWindow (stripped out landscape)

- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
    // iPhone doesn't support upside down by default, while the iPad does.  Override to allow all orientations always, and let the root view controller decide what's allowed (the supported orientations mask gets intersected).
    NSUInteger supportedInterfaceOrientations = (1 << UIInterfaceOrientationPortrait);

    return supportedInterfaceOrientations;
}

He's hiding right at the bottom of AppDelegate.m

revolunet commented 9 years ago

On the same topic, we have a landscape only iPad app, and when we open the socialshare window (ex: twitter) while the ipad is in physically in portrait, the apps goes to portrait mode and we have now way to restore it correctly (iPad/iOS 8.4)

revolunet commented 9 years ago

this bug is quite nasty because it definitely breaks the app, not sure Apple like that :)

EddyVerbruggen commented 9 years ago

@revolunet Is this new behaviour in some way? Perhaps due to a change in a recent iOS version? As this plugin hasn't been touched in that respect recently..

CookieCookson commented 9 years ago

@revolunet If you require a temporary fix, see my last comment. A quick change to your App's AppDelegate.m on supportedInterfaceOrientationsForWindow will solve the issue for now.

@EddyVerbruggen I think he is referring to the same issue, but on iPad with an App which is locked to Landscape is showing a Portrait share sheet (opposite of my issue in terms of orientation)

revolunet commented 9 years ago

@EddyVerbruggen i dont think its a new behaviour. I think i have to test with/without other plugins like splashscreen which may impact it. Will report results here very soon.

In my case, both the app and the share sheet gets rotated to portrait, despite my app is defined as landscape only

@CookieCookson tried your fix without luck yet but will dig into this soon, thank you.

revolunet commented 9 years ago

tried with removing all the other plugins and same problem; landscape app gets rotated when you open the share sheet. the problem is a little less bad with UIwebview instead of wkWebView because the orientation gets restored when you close the share sheet. but still, your app rotates and its not expected.

editing AppDelegate.m like below for landscape, as @CookieCookson suggested, finally fixed it for me, even with all plugins restored... THANK YOU :+1:

- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
    // iPhone doesn't support upside down by default, while the iPad does.  Override to allow all orientations always, and let the root view controller decide what's allowed (the supported orientations mask gets intersected).
   NSUInteger supportedInterfaceOrientations = (1 << UIInterfaceOrientationLandscapeLeft) | (1 << UIInterfaceOrientationLandscapeRight);
   return supportedInterfaceOrientations;
}

BTW, this file is cordova-specific and i dont have any idea what is causing that...

There's been a change in iOS 8 about orientation, which impacted the splashscreen plugin orientation too : http://stackoverflow.com/questions/24150359/is-uiscreen-mainscreen-bounds-size-becoming-orientation-dependent-in-ios8

Any ideas where this should be fixed ?

EddyVerbruggen commented 9 years ago

@revolunet Thanks for that link to that SO issue, really helpful!

I'll investigate a clean solution, should be possible to integrate it in the plugin.

revolunet commented 9 years ago

:+1: awesome :)

maybe totally unrelated but i had to patch the splash screen plugin with this ugly hack to prevent a similar bug : https://github.com/EducationPerfect/cordova-plugin-splashscreen/commit/49bee9f86623361ef84415025ea08ea38835f387#commitcomment-13121280