From 3605ca64224e81c09a803fae7f45a384feb5df6a Mon Sep 17 00:00:00 2001 From: naturecodevoid <44983869+naturecodevoid@users.noreply.github.com> Date: Fri, 17 Feb 2023 18:20:56 -0800 Subject: [PATCH] Fix HMR again --- AltStore/LaunchViewController.swift | 4 ++-- AltStore/Views/RootView.swift | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/AltStore/LaunchViewController.swift b/AltStore/LaunchViewController.swift index 3e23189b..2ce33093 100644 --- a/AltStore/LaunchViewController.swift +++ b/AltStore/LaunchViewController.swift @@ -45,8 +45,8 @@ final class LaunchViewController: RSTLaunchViewController, UIDocumentPickerDeleg // self.destinationViewController = self.storyboard!.instantiateViewController(withIdentifier: "tabBarController") as! TabBarController let rootView = RootView() .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) - // 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. + // 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. + // 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)) } super.viewDidLoad() diff --git a/AltStore/Views/RootView.swift b/AltStore/Views/RootView.swift index e96f0b3d..b59ec4e3 100644 --- a/AltStore/Views/RootView.swift +++ b/AltStore/Views/RootView.swift @@ -8,8 +8,11 @@ import SwiftUI import SFSafeSymbols +import Inject struct RootView: View { + @ObservedObject private var iO = Inject.observer + @State var selectedTab: Tab = .defaultTab var body: some View { @@ -26,6 +29,7 @@ struct RootView: View { } } .overlay(self.notificationsOverlay) + .enableInjection() } @ViewBuilder