-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Snapshot and deactivate Visitable during it's lifecycle #181
Changes from all commits
a63f658
1390d04
661b3a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ public class Session: NSObject { | |
|
||
private var currentVisit: Visit? | ||
private var topmostVisit: Visit? | ||
private var disappearingVisitForSnapshotting: Visit? | ||
|
||
/// The topmost visitable is the visitable that has most recently completed a visit | ||
public var topmostVisitable: Visitable? { | ||
|
@@ -213,6 +214,9 @@ extension Session: VisitDelegate { | |
|
||
extension Session: VisitableDelegate { | ||
public func visitableViewWillAppear(_ visitable: Visitable) { | ||
let lastDisappearingVisit = self.disappearingVisitForSnapshotting | ||
self.disappearingVisitForSnapshotting = nil | ||
|
||
guard let topmostVisit = self.topmostVisit, let currentVisit = self.currentVisit else { return } | ||
|
||
if visitable === topmostVisit.visitable && visitable.visitableViewController.isMovingToParent { | ||
|
@@ -225,7 +229,7 @@ extension Session: VisitableDelegate { | |
} else if visitable === currentVisit.visitable && currentVisit.state == .started { | ||
// Navigating forward - complete navigation early | ||
completeNavigationForCurrentVisit() | ||
} else if visitable !== topmostVisit.visitable { | ||
} else if visitable !== topmostVisit.visitable || visitable === lastDisappearingVisit?.visitable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This covers the case of restoring from native screen back to web, which previously wasn't considered a restore. The web view would both topmost and current visit, even when navigating back. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works as expected. |
||
// Navigating backward | ||
visit(visitable, action: .restore) | ||
} | ||
|
@@ -244,6 +248,15 @@ extension Session: VisitableDelegate { | |
} | ||
} | ||
|
||
public func visitableViewWillDisappear(_ visitable: Visitable) { | ||
self.disappearingVisitForSnapshotting = topmostVisit | ||
} | ||
|
||
public func visitableViewDidDisappear(_ visitable: Visitable) { | ||
disappearingVisitForSnapshotting?.cacheSnapshot() | ||
deactivateVisitable(visitable) | ||
} | ||
|
||
public func visitableDidRequestReload(_ visitable: Visitable) { | ||
guard visitable === topmostVisitable else { return } | ||
reload() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've renamed
disappearingVisitForSnapshotting
topreviousVisit
in the feedback PR #189.cc @jayohms @joemasilotti What do you think about the name?