-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Intercept back button when leaving an unsaved custom list
Jon Petersson
committed
Apr 11, 2024
1 parent
b2c94cc
commit a895d07
Showing
15 changed files
with
243 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
ios/MullvadVPN/Classes/InterceptibleNavigationController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// InterceptibleNavigationController.swift | ||
// MullvadVPN | ||
// | ||
// Created by Jon Petersson on 2024-04-05. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class InterceptibleNavigationController: CustomNavigationController { | ||
var shouldPopViewController: ((UIViewController) -> Bool)? | ||
var shouldPopToViewController: ((UIViewController) -> Bool)? | ||
|
||
// Called when popping the topmost view controller in the stack, eg. by pressing a navigation | ||
// bar back button. | ||
override func popViewController(animated: Bool) -> UIViewController? { | ||
guard let viewController = viewControllers.last else { return nil } | ||
|
||
if shouldPopViewController?(viewController) ?? true { | ||
return super.popViewController(animated: animated) | ||
} else { | ||
return nil | ||
} | ||
} | ||
|
||
// Called when popping to a specific view controller, eg. by long pressing a navigation bar | ||
// back button (revealing a navigation menu) and selecting a destination view controller. | ||
override func popToViewController(_ viewController: UIViewController, animated: Bool) -> [UIViewController]? { | ||
if shouldPopToViewController?(viewController) ?? true { | ||
return super.popToViewController(viewController, animated: animated) | ||
} else { | ||
return nil | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.