Fix HMR again

This commit is contained in:
naturecodevoid
2023-02-17 18:20:56 -08:00
parent 40f4c94f4d
commit 3605ca6422
2 changed files with 6 additions and 2 deletions

View File

@@ -45,8 +45,8 @@ final class LaunchViewController: RSTLaunchViewController, UIDocumentPickerDeleg
// self.destinationViewController = self.storyboard!.instantiateViewController(withIdentifier: "tabBarController") as! TabBarController // self.destinationViewController = self.storyboard!.instantiateViewController(withIdentifier: "tabBarController") as! TabBarController
let rootView = RootView() let rootView = RootView()
.environment(\.managedObjectContext, DatabaseManager.shared.viewContext) .environment(\.managedObjectContext, DatabaseManager.shared.viewContext)
// NOTE: Injection/HMR can be done directly from the SwiftUI side of things, however, it crashes the app when editing a view inside another view (such as the dev mode menu) // NOTE: Injection/HMR can be done solely from the SwiftUI side of things, however, it crashes the app when editing a view inside another view (such as the dev mode menu). For some reason, injecting in UIKit *and* SwiftUI at the same time fixes this.
// A major downside to doing it from UIKit is that if we do it this way, the whole UI will reload when you make a change. If we do it from SwiftUI, it won't reload the entire UI. // However, it has one downside: if we inject in UIKit, the whole UI will reload whenever we save a change.
self.destinationViewController = Inject.ViewControllerHost(UIHostingController(rootView: rootView)) self.destinationViewController = Inject.ViewControllerHost(UIHostingController(rootView: rootView))
} }
super.viewDidLoad() super.viewDidLoad()

View File

@@ -8,8 +8,11 @@
import SwiftUI import SwiftUI
import SFSafeSymbols import SFSafeSymbols
import Inject
struct RootView: View { struct RootView: View {
@ObservedObject private var iO = Inject.observer
@State var selectedTab: Tab = .defaultTab @State var selectedTab: Tab = .defaultTab
var body: some View { var body: some View {
@@ -26,6 +29,7 @@ struct RootView: View {
} }
} }
.overlay(self.notificationsOverlay) .overlay(self.notificationsOverlay)
.enableInjection()
} }
@ViewBuilder @ViewBuilder