Skip to content

Commit 8a451c5

Browse files
authored
Merge pull request #23 from canopas/fix-uipilot-pop-issue
Fix - UIPilot multiple pop issue
2 parents 3bb4989 + 262d134 commit 8a451c5

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Once you have your Swift package set up, adding UIPilot as a dependency is as ea
3838

3939
```swift
4040
dependencies: [
41-
.package(url: "https://github.com/canopas/UIPilot.git", .upToNextMajor(from: "1.2.0"))
41+
.package(url: "https://github.com/canopas/UIPilot.git", .upToNextMajor(from: "1.2.1"))
4242
]
4343
```
4444

@@ -47,7 +47,7 @@ dependencies: [
4747
[CocoaPods][] is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate UIPilot into your Xcode project using CocoaPods, specify it in your Podfile:
4848

4949
target 'YourAppName' do
50-
pod 'UIPilot', '~> 1.2.0'
50+
pod 'UIPilot', '~> 1.2.1'
5151
end
5252

5353
[CocoaPods]: https://cocoapods.org

Sources/UIPilot/UIPilot.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ public class UIPilot<T: Equatable>: ObservableObject {
1616
logger = debug ? DebugLog() : EmptyLog()
1717
logger.log("UIPilot - Pilot Initialized.")
1818

19-
viewGenerator.onPop = { [weak self] in
20-
self?.pop()
19+
viewGenerator.onPop = { [weak self] path in
20+
if let self = self, self.paths.count > 1
21+
&& path.id == self.paths[self.paths.count - 2].id {
22+
self.pop()
23+
}
2124
}
2225

2326
push(initial)
@@ -124,7 +127,7 @@ class PathViewState: ObservableObject {
124127

125128
class PathViewGenerator<T: Equatable> {
126129

127-
var onPop: (() -> Void)?
130+
var onPop: ((UIPilotPath<T>) -> Void)?
128131

129132
func generate(_ paths: [UIPilotPath<T>], _ routeMap: RouteMap<T>, _ pathViews: [UIPilotPath<T>: PathView]) -> (PathView?, [UIPilotPath<T>: PathView]) {
130133
var pathViews = recycleViews(paths, pathViews: pathViews)
@@ -140,9 +143,8 @@ class PathViewGenerator<T: Equatable> {
140143

141144
content?.state.next = current
142145
content?.state.onPop = current == nil ? {} : { [weak self] in
143-
if let self = self, !paths.isEmpty,
144-
paths.last != path {
145-
self.onPop?()
146+
if let self = self {
147+
self.onPop?(path)
146148
}
147149
}
148150
current = content

UIPilot.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "UIPilot"
3-
s.version = "1.2.0"
3+
s.version = "1.2.1"
44
s.summary = "The missing type-safe, SwiftUI navigation library."
55

66
s.description = <<-DESC

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ Once you have your Swift package set up, adding UIPilot as a dependency is as ea
323323

324324
```swift
325325
dependencies: [
326-
.package(url: "https://github.com/canopas/UIPilot.git", .upToNextMajor(from: "1.2.0"))
326+
.package(url: "https://github.com/canopas/UIPilot.git", .upToNextMajor(from: "1.2.1"))
327327
]
328328
```
329329

@@ -332,7 +332,7 @@ dependencies: [
332332
[CocoaPods][] is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate UIPilot into your Xcode project using CocoaPods, specify it in your Podfile:
333333

334334
target 'YourAppName' do
335-
pod 'UIPilot', '~> 1.2.0'
335+
pod 'UIPilot', '~> 1.2.1'
336336
end
337337

338338
[CocoaPods]: https://cocoapods.org

0 commit comments

Comments
 (0)