ekazaev / route-composer

Protocol oriented, Cocoa UI abstractions based library that helps to handle view controllers composition, navigation and deep linking tasks in the iOS application. Can be used as the universal replacement for the Coordinator pattern.
MIT License
894 stars 63 forks source link

Assertion fires in UIKit app when built for previewing SwiftUI View #63

Closed Elaz-viz closed 3 years ago

Elaz-viz commented 3 years ago

When integrating a SwiftUI view in an existing UIKit app, the preview hangs and errors with timeout. The diagnostics point to this crash: https://github.com/ekazaev/route-composer/blob/8eeab58be64ef6d7a81f59b77f759a7618173df4/RouteComposer/Classes/Finders/Stack%20Iterator/KeyWindowProvider.swift#L29 Commenting out the assertion (and just returning nil) clears the issue and the preview works, but I'm not sure if that's a good solution...

ekazaev commented 3 years ago

@Elaz-viz Hmmm. I did not really use it with the SwiftUI. I just created some support as a proof of concept. How does window provider gets involved in the SwiftUI preview? Do you have some kind of a stack trace or an easy way how I can reproduce it in the Example app? In general I would prefer to keep that assertion, because saved me a lot of time debugging. Especially it is helpful when I start to cover with route composer some existing project.

ekazaev commented 3 years ago

@Elaz-viz Hi. Do you have any update on this issue?

josh150 commented 3 years ago

I'm using SwiftUI to add new views to a UIKit app and haven't experienced this problem. Launching a preview shouldn't have anything to do with Route Composer, perhaps you have logic running in your app/scene delegates which is being triggered? I had to setup my auto-logout session management so that it wasn't activated while in preview mode by checking for ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] != "1".

Elaz-viz commented 3 years ago

@josh150 Actually the app is still using app delegates and not scene delegates - which might be the issue. I haven't tried yet (@ekazaev) but I need to setup a sample project for this with an app delegate.

Elaz-viz commented 3 years ago

@josh150 also, This probably happens on app delegate lifecycle apps, where there's a call to routing on the didFinishLaunching... method, but setting up the project takes time...

ekazaev commented 3 years ago

@Elaz-viz Can you see some kind of stack trace during the preview? I dont fully understand who asks for the window from KeyWindowProvider during the preview.

ekazaev commented 3 years ago

@Elaz-viz @josh150 I wanted to add that thing long time ago. So probably it is the right moment. Here is the PR. https://github.com/ekazaev/route-composer/pull/64 In the new version it will be possible to provide default configuration at one place, so @Elaz-viz will be able to change KeyWindowProvider to the one that doesnt throw an assertion. It is still strange to me that it happens. But I think, that will be the best solution.

ekazaev commented 3 years ago

@Elaz-viz I released new version 2.7.0. You can write a WindowProvider that suits you and propagate it everywhere using RouteComposerDefaults. It should help you. On other hand - if you can provide more details, Ill try to investigate it better.