-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ Implement Navigation in SwiftUI with iOS 17+ and Navigation Stack. (#9
- Loading branch information
Showing
11 changed files
with
185 additions
and
71 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// BaseNavigationView.swift | ||
// | ||
// | ||
// Created by iletai on 20/12/2023. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
import Combine | ||
|
||
public struct BaseNavigationView<RootView: View, ScreenView>: View where ScreenView: BaseViewProtocol { | ||
public typealias BaseNavigation = BaseNavigationStack<ScreenView> | ||
/// Base Navigation Stack Root View | ||
public let rootView: RootView | ||
|
||
@State | ||
private var navigationRouter = BaseNavigation(isPresented: .constant(nil)) | ||
|
||
public init(@ViewBuilder rootView: @escaping () -> RootView) { | ||
self.rootView = rootView() | ||
} | ||
|
||
public var body: some View { | ||
NavigationStack(path: navigationRouter.navigationPath) { | ||
rootView | ||
.navigationDestination(for: ScreenView.self) { screen in | ||
screen.withNavigationDestination() | ||
} | ||
.sheet(item: navigationRouter.presentingSheet) { item in | ||
item.withSheetDestination() | ||
} | ||
.fullScreenCover(item: navigationRouter.presentingFullScreen, content: { fullScreen in | ||
fullScreen.withFullScreenDestination() | ||
}) | ||
.environment(\.openURL, OpenURLAction { | ||
navigationRouter.handleOpenURL(url: $0) | ||
}) | ||
} | ||
.environment(navigationRouter) | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Sources/BaseNavigationStack/Interface/BaseViewProtocol.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// PresentViewProtocol.swift | ||
// | ||
// | ||
// Created by iletai on 18/12/2023. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
public protocol BaseViewProtocol: Identifiable, Hashable { | ||
associatedtype PresentSheetScreenView: View | ||
associatedtype DestinationView: View | ||
associatedtype PresentFullScreenView: View | ||
|
||
@MainActor | ||
@ViewBuilder | ||
func withSheetDestination() -> PresentSheetScreenView | ||
|
||
@ViewBuilder | ||
func withFullScreenDestination() -> PresentFullScreenView | ||
|
||
@MainActor | ||
@ViewBuilder | ||
func withNavigationDestination() -> DestinationView | ||
} |
Oops, something went wrong.