blob: ad7b3f7b886d53c5b87162ab9d0f4fee81942544 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
//
// InterceptibleNavigationController.swift
// MullvadVPN
//
// Created by Jon Petersson on 2024-04-05.
// Copyright © 2025 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.
@discardableResult
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.
@discardableResult
override func popToViewController(_ viewController: UIViewController, animated: Bool) -> [UIViewController]? {
if shouldPopToViewController?(viewController) ?? true {
return super.popToViewController(viewController, animated: animated)
} else {
return nil
}
}
}
|