Forked from michaelhenry/HasRootNavigationController.swift
Created
November 20, 2021 16:13
-
-
Save codeactual/e17ff82c73e503eeefa3438a37d565b5 to your computer and use it in GitHub Desktop.
UINavigationController in swiftUI.
This file contains hidden or 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 hidden or 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