SwiftKickMobile / SwiftMessages

A very flexible message bar for UIKit and SwiftUI.
MIT License
7.3k stars 742 forks source link

iOS 13 Multiple Window support? #366

Closed klaas closed 4 years ago

klaas commented 4 years ago

I couldn't find anything regarding support for multiple windows in iOS 13 (see https://developer.apple.com/videos/play/wwdc2019/212/), am I right?

Would be great to see another SwiftMessages.PresentationContext case to specify the scene window. In the meantime I'll try to hack something or use the viewController context.

BTW: Really loving Swift Message! Great work!

wtmoose commented 4 years ago

That is a good suggestion. A potentially workaround is to have SwiftMessages.PresentationContext target a view or view controller in the desired scene.

Is this what you had in mind?

enum PresentationContext {
    windowScene(_: UIWindowScene, windowLevel: UIWindow.Level)
}
klaas commented 4 years ago

This would be great! 😃

wtmoose commented 4 years ago

@klaas can you try this out on the head of master and let me know if it works for you?

klaas commented 4 years ago

@wtmoose Just gave it a brief try. The API is fine 😃, but the message view will be centered between my two scenes:

Untitled

I guess it might relate to having the window as big a the screen?

PassthroughWindow(hitTestView: view, frame: UIScreen.main.bounds)

I can take a deeper look into it tomorrow.

Thank you very much for implementing it!

wtmoose commented 4 years ago

Yeah, I’m just telling the window to become visible. I haven’t done much with multi-window, so if you’ve got any pointers for how the window should be installed, I’ll take a look.

klaas commented 4 years ago

Using the bounds of the first window of the scene, solves the layout issues:

var windowBounds: CGRect

switch config.presentationContext {
case let .windowScene(scene, _):
    windowBounds = scene.windows.first!.bounds
default:
    windowBounds = UIScreen.main.bounds
}

But essentially every app can now have multiple "main" windows. Each scene has it's own window and would be in the need of an independent queue for displaying messages.

🥺 Uh, this seems to be more work than expected.

wtmoose commented 4 years ago

How about when the bounds change, such as if you rotate or resize the split screen?

Independent queues should be a problem. You can use as many instances of SwiftMessages as you want:

let mainWindowMessenger = SwiftMessages()
mainWindowMessenger.show(...)
wtmoose commented 4 years ago

Should work correctly now if you'd like to check out the head of master.

wtmoose commented 4 years ago

Included in 8.0.0 release