diff --git a/Demo/Screens/Home/HomeScreen.swift b/Demo/Screens/Home/HomeScreen.swift index a39d60f..b7dda98 100644 --- a/Demo/Screens/Home/HomeScreen.swift +++ b/Demo/Screens/Home/HomeScreen.swift @@ -75,6 +75,7 @@ struct HomeScreen: View { dismissButton: .cancel()) } } + } private func presentDialog() { navigator.presentDialog(dismissOnTouchOutside: true) { diff --git a/README.md b/README.md index f6c36c5..6582869 100644 --- a/README.md +++ b/README.md @@ -12,15 +12,55 @@ The logo is contributed with ❤️ by [Mahmoud Hussein](https://github.com/Mhmo   -**SwiftUINavigator** is a lightweight, flexible, and super easy library which makes `SwiftUI` navigation a trivial task. +**SwiftUINavigator** is on-the-fly approach for handling SwiftUI navigation. **SwiftUINavigator** is a backtrack to +the traditional approach of **UIKit** where you can push or present a controller on the fly without declaring links or local state variables. +The approach is as simple as the following: + +```swift +@EnvironmentObject private var navigator: Navigator + +// Navigate to HomeScreen +navigator.navigate { HomeScreen() } + +// Show sheet +navigator.navigate(type: .sheet(type: .normal)) { + SheetView() +} +navigator.navigate(type: .sheet(type: .full)) { + SheetView() +} +navigator.navigate(type: .sheet(type: .fixedHeight(200))) { + SheetView() +} + +// Show dialog +navigator.navigate(type: .dialog) { + DialogView() +} + +// Show action sheet +navigator.presentActionSheet { + ActionSheetView() +} + +// Show confirmation dialog (Like action sheet starting from iOS 15) +navigator.presentConfirmationDialog(titleKey: "Color", titleVisibility: .visible) { + ConfirmationDialogView() +} + +// Show Alert +navigator.presentAlert { + AlertView() +} +```
# Table of contents @@ -56,6 +96,8 @@ Let's first explore the limitations of SwiftUI then explore the awesome features In SwiftUI, there are a lot of limitations: +- [ ] Passing parameters to the view is not easy because you have to declare parameters locally and pass them to the view inside `NavigationLink`. + - [ ] Can not navigate programmatically. You always have to declare the navigation links. - [ ] Inconsistent navigation when use `NavigationLink`, `.sheet` and `.fullScreenCover` @@ -76,6 +118,8 @@ In SwiftUI, there are a lot of limitations: - [X] Consistent navigation with screens, sheets, action sheets, dialogs, confirmation dialogs, and alerts. +- [X] You are free to pass parameters on the fly and no need to declare the parameters outside the navigation site. +- - [X] Custom navigation transitions - [X] Navigate to a view without adding it to the back stack. @@ -243,12 +287,12 @@ navigator.presentConfirmationDialog(titleKey: "Color", titleVisibility: .visible ## Alert ```swift - navigator.presentAlert { - Alert( - title: Text("Alert"), - message: Text("Presented on the fly with SwiftUINavigator"), - dismissButton: .cancel()) - } +navigator.presentAlert { + Alert( + title: Text("Alert"), + message: Text("Presented on the fly with SwiftUINavigator"), + dismissButton: .cancel()) +} ``` ## Dialog @@ -343,15 +387,15 @@ navigator.navigate(type: .push()) { ```swift navigator.navigate(type: .sheet(type: .normal)) { - ProductDetailScreen(item: item) + SheetView() } // OR navigator.navigate(type: .sheet(type: .full)) { - ProductDetailScreen(item: item) + SheetView() } // OR navigator.navigate(type: .sheet(type: .fixedHeight(200))) { - ProductDetailScreen(item: item) + SheetView() } ```