-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Intercept back button when leaving an unsaved custom list
- Loading branch information
Jon Petersson
committed
Apr 7, 2024
1 parent
e859f00
commit 1aa98f0
Showing
11 changed files
with
159 additions
and
57 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
35 changes: 35 additions & 0 deletions
35
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,35 @@ | ||
// | ||
// InterceptibleNavigationController.swift | ||
// MullvadVPN | ||
// | ||
// Created by Jon Petersson on 2024-04-05. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class InterceptibleNavigationController: UINavigationController { | ||
var shouldPopViewController: ((UIViewController) -> Bool)? | ||
var shouldPopToViewController: ((UIViewController) -> Bool)? | ||
|
||
// Called when popping the last view controller, eg. by pressing a nacvigation 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 nacvigation 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
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.