Open Mteixeira88 opened 5 years ago
I likely won't have time to look into SwiftUI anytime soon.
I likely won't have time to look into SwiftUI anytime soon.
Thanks for answering
That would be great because than we can use it in SPM
@Jasperav huh?
Swift Package Manager supports SwiftUI, not UIKit. We can get rid of Cocoapods/Cartage and use a native dependency manager instead.
@Jasperav I view this as a compatibility ticket. It's not about converting the library to SwiftUI.
For anyone looking to use this library in their SwiftUI projects, technically all UIKit code works with SwiftUI. You have to use the UIViewControllerRepresentable
protocol to achieve this. I just implemented the Bottom Message Segue in this library using pretty much the same setup in Storyboard as shown in the Demo. Then implement code like this to use it from SwiftUI
struct BottomMessageSegue: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> some UIViewController {
let storyboard = UIStoryboard(name: "Storyboard", bundle: Bundle.main)
let vc = storyboard.instantiateViewController(identifier: "InitialVC")
return vc
}
func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {
}
}
Replace identifier with your own. Create a View Controller and assign it to the root View Controller Scene in the Storyboard Again pretty much the same code as shown in the Demo
import UIKit
import SwiftMessages
class ViewControllersViewController: UIViewController {
@objc @IBAction private func dismissPresented(segue: UIStoryboardSegue) {
dismiss(animated: true, completion: nil)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
performSegue(withIdentifier: "showTools", sender: nil)
}
}
class SwiftMessagesBottomSegue: SwiftMessagesSegue {
override public init(identifier: String?, source: UIViewController, destination: UIViewController) {
super.init(identifier: identifier, source: source, destination: destination)
configure(layout: .bottomMessage)
}
}
with the addition of performSegue()
in the viewDidAppear()
, replace the segue identifier with your own and you are done.
Use BottomMessageSegue()
as you would use any other SwiftUI view and it will just work without any problems.
Have fun!
So this issue can actually be closed with a README update, right?
Hi there,
I'm trying to use Swift Messages on Swift UI and for some reason it's not showing
This is the code I'm trying to use:
I already tried to use in a button click and it didn't work. Can you help? Thanks