From 68cd6344c5a4ab3fafc22d45506477d1d1ed1b35 Mon Sep 17 00:00:00 2001 From: adri567 Date: Tue, 18 Apr 2023 13:30:42 +0200 Subject: [PATCH 01/11] Update README.md --- README.md | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 83 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0ca5b5e..9bd9b86 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,89 @@ Navify is a SwiftUI package that simplifies navigation in your app by using a ro ## 🛠 Installation -Navify requires iOS 16 and Xcode 13. +Navify requires iOS 16 and Xcode 14. -1️⃣ In Xcode go to `File` ➤ `Add Packages...` +1. In Xcode go to `File` ➤ `Add Packages...` -2️⃣ In the top right corner, paste `https://github.com/username/Navify.git` and press Enter. +2. In the top right corner, paste `https://github.com/username/Navify.git` and press Enter. -3️⃣ Choose `Navify` from the list ➤ `Add Package` +3. Choose `Navify` from the list ➤ `Add Package` + +## ⌨️ How to use + +1. In order to use Navify correctly you need to import Navify in every File where you use Navify content. +```swift +import Navify +``` + +2. Next, you need a Router enum and a Coordinator class. + +```swift +import SwiftUI +import Navify + +enum HomeRouter: Router { + + var id: String { UUID().uuidString } + + // MARK: - Views + case feed + case settings + + // MARK: - Methods + func viewForDestination() -> some View { + switch self { + case .feed: + Feed() + case .settings: + Settings() + } +} +``` +> When you confirm to Router, make sure, that you implement the id and viewForDestination(). The cases indicate where you want to navigate. + +```swift +import SwiftUI +import Navify + +class HomeCoordinator: ObservableObject, Coordinator { + + // MARK: - Properties + @Published var screens: [Screen] = [] + + @Published var alert: NavifyAlert = .init(title: "") + + // MARK: - Methods + func popToRoot() { + screens = [] + } + + func navigateTo(_ view: R, style: Types) { + screens.append(Screen(style: style, view: view)) + } + + func presentAlert(with alert: NavifyAlert) { + self.alert = alert + } +} +``` +> The coordinator class must be a generic of type Router and needs to conform to the Coordinator Protocol. You need to implement the screens property, popToRoot() and func navigateTo(_ view: R, style: Types) methods like in the example above. If you want to use an alert in your app, you can implement the alert property and method too. + +3. Afterwards you need the NavifyStack which is similar like the NavigationStack. + +```swift +import SwiftUI +import Navify + +struct ContentView: View { + + @EnvironmentObject private var coordinator: HomeCoordinator + + var body: some View { + NavifyStack(screens: $coordinator.screens, alert: $coordinator.alert) { + HomeView() + } + } +} +``` +> The alert parameter is optional. If you don't want to use alerts in your app, you can just use the screens parameter. From 7df0e8c4f3ad927913d17067f7832096250f4c63 Mon Sep 17 00:00:00 2001 From: adri567 Date: Tue, 18 Apr 2023 13:31:29 +0200 Subject: [PATCH 02/11] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9bd9b86..395b3d5 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Navify requires iOS 16 and Xcode 14. import Navify ``` + 2. Next, you need a Router enum and a Coordinator class. ```swift @@ -82,6 +83,7 @@ class HomeCoordinator: ObservableObject, Coordinator { ``` > The coordinator class must be a generic of type Router and needs to conform to the Coordinator Protocol. You need to implement the screens property, popToRoot() and func navigateTo(_ view: R, style: Types) methods like in the example above. If you want to use an alert in your app, you can implement the alert property and method too. + 3. Afterwards you need the NavifyStack which is similar like the NavigationStack. ```swift From 61fc4f4fadddb1099080ecfb9730a5fb20652cea Mon Sep 17 00:00:00 2001 From: adri567 Date: Tue, 18 Apr 2023 14:19:33 +0200 Subject: [PATCH 03/11] Update README.md --- README.md | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 127 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 395b3d5..46636ec 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,11 @@ Navify requires iOS 16 and Xcode 14. ## ⌨️ How to use -1. In order to use Navify correctly you need to import Navify in every File where you use Navify content. +1. To use Navify correctly, you must import it in every file that contains Navify content. ```swift import Navify ``` - 2. Next, you need a Router enum and a Coordinator class. ```swift @@ -54,7 +53,7 @@ enum HomeRouter: Router { } } ``` -> When you confirm to Router, make sure, that you implement the id and viewForDestination(). The cases indicate where you want to navigate. +> When confirming with the Router, make sure to implement the id and viewForDestination() functions. The cases indicate the destination you wish to navigate to. ```swift import SwiftUI @@ -81,8 +80,7 @@ class HomeCoordinator: ObservableObject, Coordinator { } } ``` -> The coordinator class must be a generic of type Router and needs to conform to the Coordinator Protocol. You need to implement the screens property, popToRoot() and func navigateTo(_ view: R, style: Types) methods like in the example above. If you want to use an alert in your app, you can implement the alert property and method too. - +> The Coordinator class must be a generic of type Router and conform to the Coordinator Protocol. You must implement the screens property, popToRoot(), and navigateTo(_ view: R, style: Types) methods as shown in the example above. If you want to use an alert in your app, you can also implement the alert property and method. 3. Afterwards you need the NavifyStack which is similar like the NavigationStack. @@ -90,10 +88,27 @@ class HomeCoordinator: ObservableObject, Coordinator { import SwiftUI import Navify +@main +struct NavifyTestApp: App { + + // MARK: - Properties + @StateObject private var homeCoordinator: HomeCoordinator = HomeCoordinator() + + // MARK: - Body + var body: some Scene { + WindowGroup { + ContentView() + .environmentObject(homeCoordinator) + } + } +} + struct ContentView: View { + // MARK: - Properties @EnvironmentObject private var coordinator: HomeCoordinator + // MARK: - Body var body: some View { NavifyStack(screens: $coordinator.screens, alert: $coordinator.alert) { HomeView() @@ -101,4 +116,110 @@ struct ContentView: View { } } ``` -> The alert parameter is optional. If you don't want to use alerts in your app, you can just use the screens parameter. +> The alert parameter is optional. If you choose not to use alerts in your app, you can simply use the screens parameter instead. + +4. To navigate between views, you can use the methods provided by the coordinator. + +```swift +struct HomeView: View { + + // MARK: - Properties + @EnvironmentObject private var coordinator: HomeCoordinator + + // MARK: - Body + var body: some View { + VStack { + /// Push and present + Button("Push") { + coordinator.navigateTo(.feed, style: .init(segue: .push)) + } + Button("Present") { + coordinator.navigateTo(.feed, style: .init(segue: .present)) + } + Button("Present with Detents") { + coordinator.navigateTo(.settings, style: .init(segue: .present, detents: Detents(presentationDetents: [.medium]))) + } + Button("PresentFullScreen") { + coordinator.navigateTo(.feed, style: .init(segue: .presentFullScreen)) + } + + /// Alert and confirmationDialog + Button("Present Alert") { + coordinator.presentAlert(with: + NavifyAlert( + isPresenting: true, + option: .alert, + title: "My Alert", + message: "Alert 2", + content: { + buttons + }) + ) + } + Button("Present Confirmation Dialog 1") { + coordinator.presentAlert(with: + NavifyAlert( + isPresenting: true, + option: .confirmationDialog, + title: "My ConfirmationDialog 1", + message: "", + content: { + confirm1 + }) + ) + } + Button("Present Confirmation Dialog 1") { + coordinator.presentAlert(with: + NavifyAlert( + isPresenting: true, + option: .confirmationDialog, + title: "My ConfirmationDialog 2", + message: "Confirmation 2", + content: { + confirm1 + }) + ) + } + } + } + + // MARK: - Views + @ViewBuilder private var confirm1: some View { + Button("Button1") {} + } + + @ViewBuilder private var buttons: some View { + /// You can also use TextField with Buttons + Button("Button1") {} + Button("Button2") {} + } +} +``` +> If you leave the message parameter empty, the confirmation dialog will be displayed without a message. + +5. To dismiss a view, you can use the default environment property that is provided with SwiftUI. + +```swift +struct Feed: View { + + // MARK: - Properties + @EnvironmentObject private var coordinator: HomeCoordinator + @Environment(\.dismiss) private var dismiss + + // MARK: - Body + var body: some View { + VStack { + Text("Feed") + Button("To Root") { + coordinator.popToRoot() + } + Button("dismiss") { + dismiss() + } + } + .sheet(isPresented: $preseting) { + Text("test") + } + } +} +``` From d6e7b4a8e5177c42be46c6a5f5d78380a6dceb28 Mon Sep 17 00:00:00 2001 From: adri567 Date: Tue, 18 Apr 2023 14:20:47 +0200 Subject: [PATCH 04/11] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 46636ec..08b0f10 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ struct HomeView: View { } @ViewBuilder private var buttons: some View { - /// You can also use TextField with Buttons + /// You can also use TextField with Buttons Button("Button1") {} Button("Button2") {} } @@ -202,7 +202,7 @@ struct HomeView: View { ```swift struct Feed: View { - // MARK: - Properties + // MARK: - Properties @EnvironmentObject private var coordinator: HomeCoordinator @Environment(\.dismiss) private var dismiss From 65ecd539b63d3b5e7f0d71c5770440ad350bf0dc Mon Sep 17 00:00:00 2001 From: adri567 Date: Tue, 18 Apr 2023 14:29:54 +0200 Subject: [PATCH 05/11] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 08b0f10..638a19f 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ struct HomeView: View { } @ViewBuilder private var buttons: some View { - /// You can also use TextField with Buttons + /// You can also use TextField with Buttons Button("Button1") {} Button("Button2") {} } @@ -202,7 +202,7 @@ struct HomeView: View { ```swift struct Feed: View { - // MARK: - Properties + // MARK: - Properties @EnvironmentObject private var coordinator: HomeCoordinator @Environment(\.dismiss) private var dismiss @@ -223,3 +223,4 @@ struct Feed: View { } } ``` + From 6928b47f47310f08853160e4eae5c448c770043b Mon Sep 17 00:00:00 2001 From: adri567 Date: Tue, 18 Apr 2023 14:30:52 +0200 Subject: [PATCH 06/11] Update README.md --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 638a19f..cf4b1f9 100644 --- a/README.md +++ b/README.md @@ -105,15 +105,15 @@ struct NavifyTestApp: App { struct ContentView: View { - // MARK: - Properties + // MARK: - Properties @EnvironmentObject private var coordinator: HomeCoordinator - // MARK: - Body + // MARK: - Body var body: some View { - NavifyStack(screens: $coordinator.screens, alert: $coordinator.alert) { - HomeView() - } - } + NavifyStack(screens: $coordinator.screens, alert: $coordinator.alert) { + HomeView() + } + } } ``` > The alert parameter is optional. If you choose not to use alerts in your app, you can simply use the screens parameter instead. @@ -189,7 +189,7 @@ struct HomeView: View { } @ViewBuilder private var buttons: some View { - /// You can also use TextField with Buttons + /// You can also use TextField with Buttons Button("Button1") {} Button("Button2") {} } @@ -202,7 +202,7 @@ struct HomeView: View { ```swift struct Feed: View { - // MARK: - Properties + // MARK: - Properties @EnvironmentObject private var coordinator: HomeCoordinator @Environment(\.dismiss) private var dismiss From 48a5d65e8b5fa90706ce0164234e1f0cff46c2e2 Mon Sep 17 00:00:00 2001 From: adri567 Date: Tue, 18 Apr 2023 14:54:21 +0200 Subject: [PATCH 07/11] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cf4b1f9..d6f3ca5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -# 🔰 Navify +
+ +
Navify is a SwiftUI package that simplifies navigation in your app by using a router and coordinator pattern. It provides a clean and organized way to handle navigation, presentation, and alerts. From addc18c3cace536ded54b9d7316f5cfc01655bb8 Mon Sep 17 00:00:00 2001 From: adri567 Date: Tue, 18 Apr 2023 14:55:02 +0200 Subject: [PATCH 08/11] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d6f3ca5..4b42a35 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ + + Navify is a SwiftUI package that simplifies navigation in your app by using a router and coordinator pattern. It provides a clean and organized way to handle navigation, presentation, and alerts. ## ⛓️ Features From b104bcc38534ac872b7cb46a9eba35daf1d85c96 Mon Sep 17 00:00:00 2001 From: adri567 Date: Tue, 18 Apr 2023 14:55:27 +0200 Subject: [PATCH 09/11] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4b42a35..1de4855 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ - +
+
Navify is a SwiftUI package that simplifies navigation in your app by using a router and coordinator pattern. It provides a clean and organized way to handle navigation, presentation, and alerts. From 52091529598f29c89f599d6b62073e5189234300 Mon Sep 17 00:00:00 2001 From: adri567 Date: Tue, 18 Apr 2023 14:55:36 +0200 Subject: [PATCH 10/11] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 1de4855..1a26444 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,7 @@ -
-
+-------- Navify is a SwiftUI package that simplifies navigation in your app by using a router and coordinator pattern. It provides a clean and organized way to handle navigation, presentation, and alerts. From 6bfd21a7d1913fc18857f8d93f69fdce9e6d85d3 Mon Sep 17 00:00:00 2001 From: adri567 Date: Tue, 18 Apr 2023 15:51:58 +0200 Subject: [PATCH 11/11] Update README.md --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 1a26444..2642c20 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ struct HomeView: View { coordinator.navigateTo(.feed, style: .init(segue: .present)) } Button("Present with Detents") { - coordinator.navigateTo(.settings, style: .init(segue: .present, detents: Detents(presentationDetents: [.medium]))) + coordinator.navigateTo(.feed, style: .init(segue: .present, detents: Detents(presentationDetents: [.medium]))) } Button("PresentFullScreen") { coordinator.navigateTo(.feed, style: .init(segue: .presentFullScreen)) @@ -221,9 +221,6 @@ struct Feed: View { dismiss() } } - .sheet(isPresented: $preseting) { - Text("test") - } } } ```