Skip to content

Commit

Permalink
delay
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeloper committed Jan 11, 2021
1 parent a76df45 commit 9fa53f8
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions Sources/NavigationKit/Navigation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,29 @@ public class Navigation: ObservableObject {
/// - Parameters:
/// - element: The destination view.
/// - identifier: The ID of the destination view (used to easily come back to it if needed).
public func push<Element: View>(_ element: Element, withId identifier: String? = nil) {
withAnimation(easing) {
navigationType = .push
viewStack.push(ViewElement(id: identifier == nil ? UUID().uuidString : identifier!, wrappedElement: AnyView(element)))
public func push<Element: View>(_ element: Element, withId identifier: String? = nil, delay: TimeInterval = 0.0) {
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
withAnimation(self.easing) {
self.navigationType = .push
self.viewStack.push(ViewElement(id: identifier == nil ? UUID().uuidString : identifier!, wrappedElement: AnyView(element)))
}
}
}

/// Navigates back to a previous view.
/// - Parameter to: The destination type of the transition operation.
public func pop(to: PopDestination = .previous) {
withAnimation(easing) {
navigationType = .pop
switch to {
case .root:
viewStack.popToRoot()
case .view(let viewId):
viewStack.popToView(withId: viewId)
default:
viewStack.popToPrevious()
public func pop(to: PopDestination = .previous, delay: TimeInterval = 0.0) {
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
withAnimation(self.easing) {
self.navigationType = .pop
switch to {
case .root:
self.viewStack.popToRoot()
case .view(let viewId):
self.viewStack.popToView(withId: viewId)
default:
self.viewStack.popToPrevious()
}
}
}
}
Expand Down

0 comments on commit 9fa53f8

Please sign in to comment.