-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tabbed example with nested navigations
- Loading branch information
Showing
10 changed files
with
171 additions
and
98 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
31 changes: 31 additions & 0 deletions
31
Example/Example/Features/SecondTab/SecondDetailModalDetailView.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,31 @@ | ||
// | ||
// SecondDetailModalDetailView.swift | ||
// Example | ||
// | ||
// Created by David Chavez on 31.08.21. | ||
// | ||
|
||
import SwiftUI | ||
import XNavigation | ||
|
||
struct SecondDetailModalDetailView: View, DestinationView { | ||
@EnvironmentObject var navigation: Navigation | ||
|
||
var navigationBarTitleConfiguration = NavigationBarTitleConfiguration(title: "Second Detail Detail", displayMode: .inline) | ||
|
||
var body: some View { | ||
VStack { | ||
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) | ||
Button(action: { | ||
navigation.pop(animated: true) | ||
}) { Text("Press to pop!") } | ||
} | ||
.navigationBarTitle(configuration: navigationBarTitleConfiguration) | ||
} | ||
} | ||
|
||
struct SecondDetailModalDetailView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
SecondDetailModalDetailView() | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
Example/Example/Features/SecondTab/SecondDetailModalView.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,35 @@ | ||
// | ||
// SecondDetailModalView.swift | ||
// Example | ||
// | ||
// Created by David Chavez on 31.08.21. | ||
// | ||
|
||
import SwiftUI | ||
import XNavigation | ||
|
||
struct SecondDetailModalView: View { | ||
@EnvironmentObject var navigation: Navigation | ||
|
||
var body: some View { | ||
NavigationView { | ||
VStack { | ||
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) | ||
Button(action: { | ||
navigation.dismiss(animated: true) | ||
}) { Text("Press to dismiss!") } | ||
Button(action: { | ||
navigation.pushView(SecondDetailModalDetailView()) | ||
}) { Text("Press to push unto this modal!") } | ||
.padding(.top, 40) | ||
} | ||
.navigationBarTitle("Second Detail", displayMode: .inline) | ||
} | ||
} | ||
} | ||
|
||
struct SecondDetailModalView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
SecondDetailModalView() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
37 changes: 37 additions & 0 deletions
37
Sources/XNavigation/Extensions/UIViewController+Hierarchy.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,37 @@ | ||
// | ||
// UIViewController+Hierarchy.swift | ||
// XNavigation | ||
// | ||
// Created by David Chavez on 31.08.21. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UIViewController { | ||
func findLastPresentedViewController() -> UIViewController? { | ||
if let presentedViewController = presentedViewController?.presentedViewController { | ||
return presentedViewController.findLastPresentedViewController() | ||
} else { | ||
return presentedViewController | ||
} | ||
} | ||
|
||
func findNestedUINavigationController() -> UINavigationController? { | ||
// presented modals should take precedence, as they're | ||
// currently on-screen and likely where you tried to push/present. | ||
if let lastPresentedViewController = findLastPresentedViewController() { | ||
return lastPresentedViewController.findNestedUINavigationController() | ||
} | ||
|
||
if let nvc = self as? UINavigationController { return nvc } | ||
else if let tbc = self as? UITabBarController { | ||
return tbc.selectedViewController?.findNestedUINavigationController() | ||
} | ||
|
||
for child in children { | ||
return child.findNestedUINavigationController() | ||
} | ||
|
||
return nil | ||
} | ||
} |
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