NicholasSheehan / Unity-Native-Sharing

A Unity plugin to open native sharing dialogs on iOS and Android, primarily for text and files
MIT License
446 stars 119 forks source link

Visual issues in Landscape mode when sharing on iOS #72

Open acgourley opened 3 years ago

acgourley commented 3 years ago

All tests on Unity 2020.3f15 / Xcode 12.5

Building the example out to an iPhone 6S on iOS 14 we can see the Instagram share has no keyboard:

Screen Shot 2021-09-08 at 2 06 53 PM

Similar for building to an iPad Pro on iOS 14 (external keyboard works, but no on screen keyboard will appear)

Screen Shot 2021-09-08 at 2 08 31 PM

On these devices, sharing images to instagram from the Photos app does bring up the keyboard, so it's likely something about the unity root view controller.

Oddly, in my own unity app when embedding this plugin, things are a bit worse. This is a screenshot of trying to share from the same iPhone 6S:

Screen Shot 2021-09-08 at 1 54 27 PM

I've closely compared the build settings in both projects and I can't figure out why the share window would be smaller and off the screen in my app and not the example project in this repo, but I do wonder if they might have the same root cause.

I'd either be happy to see the landscape share view work as well as it does in Apple Photos or have a strategy for selectively turning on portrait mode when launching this sharing dialog to sidestep the issue.

acgourley commented 3 years ago

It does appear possible to tell unity to change the auto rotation settings to portrait, wait a frame, then invoke this plugin and this will fix the issues. Of course you also need to know when you can change your view back to landscape, and as of now this plugin doesn't furnish a callback.

I tested it, and if we add this to the activity before showing the share dialog, it does invoke when the controller is dismissed.

[activity setCompletionHandler:^(NSString *activityType, BOOL completed) {
        NSLog(@"UIActivityViewController dismissed");
        //TODO: tell unity
    }];

So maybe a good fix is to have an optional delegate arg from ShareScreenshotAndText and ShareText which will be invoked on completion, see "Using Delegates" on https://docs.unity3d.com/Manual/PluginsForIOS.html

NicholasSheehan commented 3 years ago

https://github.com/NicholasSheehan/Unity-Native-Sharing/blob/5fd626d0871d3a2511b6a221d0dd1c108cbb5330/Plugins/iOS/UnityNative_Sharing.mm#L55

I started looking at Unity callbacks a while ago, the issue is I need to write a wrapper that allows Actions to be passed into Obj-C in a friendly way. The link you provided touches on how I'll do it, which is to create some typedefs like typedef void(*TYPEDEF_NAME)(void)

I'd also need to write the Android version at the same time in order to make it consistent across platforms

acgourley commented 3 years ago

I might be able to help, depending on timing as I think I need this in a little over a week. On the other hand, I don't want to get in your way and I also don't want to figure out android as that currently works fine in landscape. If you think you won't be doing it this week just give this post a thumbs up and I'll try doing at least iOS in a fork.

NicholasSheehan commented 3 years ago

Feel free to add and patch what you like and submit it as a pull request

NicholasSheehan commented 3 years ago

I'll try and get my Mac environment setup again for the weekend

Some of the calls need a refactor, I'd rather pass around 1 object with all the variables needed for sharing rather than passing through each variable as optional parameters. But I'll do that after this as it'll be a breaking API change so I'll need to bump the version to v1.1.0 when I do