SwiftKickMobile / SwiftMessages

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

Use separated controller ('aka' segue) in a stand alone window instead of presenting it on a source controller. #447

Closed MojtabaHs closed 3 years ago

MojtabaHs commented 3 years ago

Hey, Since we should use segues to have a standalone view controller inside the swift message, we always need a source view controller to pass it as the source of this function:

        BottomCardSheetSegue(identifier: id, source: source, destination: controller).perform()

Imagine we have a controller that should be on top of the entire window (like the sheets that iOS is using)

68747470733a2f2f692e737461636b2e696d6775722e636f6d2f6d4b5a32502e6a7067

This kind of message should not be coupled with the source view controller underneath them.

So how can we present a controller in a separate window like the presentation of the basic views of the Swift messages? Is it possible now?

wtmoose commented 3 years ago

Hi. I hadn't thought of doing that before, but it was relatively straightforward. Could you install the head of master and try the following and let me know if it works for you?

let sourceVC = WindowViewController()
let segue = SwiftMessagesSegue(identifier: nil, source: windowVC, destination: destinationVC)
segue.perform()

You can optionally specify window level and window scene by providing an instance of SwiftMessages.Config to the window view controller's initializer where the desired values are specified in the SwiftMessages.Config.presentationContext property.

MojtabaHs commented 3 years ago

Works at the first look. This method should be mentioned in the documentation. I've done that in this PR

BUT! it will crash if you try to present another one while the previous is already presenting:

Thread 1: "Application tried to present modally a view controller <UIViewController: 0x7fb420c27300> that is already being presented by <SwiftMessages.WindowViewController: 0x7fb42105b000>."

Also, I don't know why but it shows nothing in another app and that is not expected.

wtmoose commented 3 years ago

9.0.0