Skip to content

Commit

Permalink
Adds a utility function for dismissing all sheets and modals (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnpatrickmorgan committed Sep 30, 2022
1 parent 99b0c0d commit 9026a14
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Sources/FlowStacks/RoutableCollection+utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,25 @@ public extension RoutableCollection where Element: RouteProtocol {
var index = endIndex - 1
var dismissed = 0
while dismissed < count, indices.contains(index) {
assert(
index > 0,
"Can't dismiss\(count == 1 ? "" : " \(count) screens") - the number of presented screens is \(dismissed)"
)
guard index > 0 else { return }

if self[index].isPresented {
dismissed += 1
}
index -= 1
}
goBackTo(index: index)
}

/// Dismisses all presented sheets and modals, without popping any pushed screens in the bottommost
/// presentation layer.
mutating func dismissAll() {
let count = self.dropFirst().filter { $0.isPresented }.count
guard count > 0 else { return }
dismiss(count: count)
}
}

0 comments on commit 9026a14

Please sign in to comment.