Skip to content

Commit

Permalink
Merge pull request #23 from canopas/fix-uipilot-pop-issue
Browse files Browse the repository at this point in the history
Fix - UIPilot multiple pop issue
  • Loading branch information
jimmy0251 authored Jun 7, 2022
2 parents 3bb4989 + 262d134 commit 8a451c5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Once you have your Swift package set up, adding UIPilot as a dependency is as ea

```swift
dependencies: [
.package(url: "https://github.com/canopas/UIPilot.git", .upToNextMajor(from: "1.2.0"))
.package(url: "https://github.com/canopas/UIPilot.git", .upToNextMajor(from: "1.2.1"))
]
```

Expand All @@ -47,7 +47,7 @@ dependencies: [
[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:

target 'YourAppName' do
pod 'UIPilot', '~> 1.2.0'
pod 'UIPilot', '~> 1.2.1'
end

[CocoaPods]: https://cocoapods.org
Expand Down
14 changes: 8 additions & 6 deletions Sources/UIPilot/UIPilot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ public class UIPilot<T: Equatable>: ObservableObject {
logger = debug ? DebugLog() : EmptyLog()
logger.log("UIPilot - Pilot Initialized.")

viewGenerator.onPop = { [weak self] in
self?.pop()
viewGenerator.onPop = { [weak self] path in
if let self = self, self.paths.count > 1
&& path.id == self.paths[self.paths.count - 2].id {
self.pop()
}
}

push(initial)
Expand Down Expand Up @@ -124,7 +127,7 @@ class PathViewState: ObservableObject {

class PathViewGenerator<T: Equatable> {

var onPop: (() -> Void)?
var onPop: ((UIPilotPath<T>) -> Void)?

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

content?.state.next = current
content?.state.onPop = current == nil ? {} : { [weak self] in
if let self = self, !paths.isEmpty,
paths.last != path {
self.onPop?()
if let self = self {
self.onPop?(path)
}
}
current = content
Expand Down
2 changes: 1 addition & 1 deletion UIPilot.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "UIPilot"
s.version = "1.2.0"
s.version = "1.2.1"
s.summary = "The missing type-safe, SwiftUI navigation library."

s.description = <<-DESC
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ Once you have your Swift package set up, adding UIPilot as a dependency is as ea

```swift
dependencies: [
.package(url: "https://github.com/canopas/UIPilot.git", .upToNextMajor(from: "1.2.0"))
.package(url: "https://github.com/canopas/UIPilot.git", .upToNextMajor(from: "1.2.1"))
]
```

Expand All @@ -332,7 +332,7 @@ dependencies: [
[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:

target 'YourAppName' do
pod 'UIPilot', '~> 1.2.0'
pod 'UIPilot', '~> 1.2.1'
end

[CocoaPods]: https://cocoapods.org
Expand Down

0 comments on commit 8a451c5

Please sign in to comment.