Last active
October 12, 2024 02:04
-
-
Save michaelhenry/945fc63da49e960953b72bbc567458e6 to your computer and use it in GitHub Desktop.
UINavigationController in swiftUI.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
var window: UIWindow? | |
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { | |
UINavigationBar.appearance().tintColor = .black | |
let contentView = OnBoardingView() | |
if let windowScene = scene as? UIWindowScene { | |
let window = UIWindow(windowScene: windowScene) | |
let hostingVC = UIHostingController(rootView: contentView) | |
let mainNavVC = UINavigationController(rootViewController: hostingVC) | |
mainNavVC.navigationBar.isHidden = true | |
window.rootViewController = mainNavVC | |
self.window = window | |
window.makeKeyAndVisible() | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension YouSwiftUIView:HasRootNavigationController { | |
func switchToMainScreen() { | |
self.setRootNavigation(views: [MainView()]) | |
} | |
func pushToMainScreen() { | |
self.push(view: [MainView()]) | |
} | |
func goBack() { | |
self.pop() | |
} | |
func showTheInitialView() { | |
self.popToRoot() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now that SceneDelegate has been removed from SwiftUI apps, how would you initialize "HasRootNavigationController"? I really don't understand why Apple keeps making things harder and harder for us iOS devs.