Forked from michaelhenry/HasRootNavigationController.swift
Created
June 7, 2025 07:12
-
-
Save balitax/b1a43b0b5e87630d61a5296a7577d778 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