-
-
Notifications
You must be signed in to change notification settings - Fork 776
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5121 from wikimedia/prototype/system-nav-bar
Remove custom navigation bar
- Loading branch information
Showing
322 changed files
with
5,342 additions
and
7,177 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
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 was deleted.
Oops, something went wrong.
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
127 changes: 127 additions & 0 deletions
127
.../Sources/WMFComponents/Base/Component Base Classes/WMFComponentNavigationController.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,127 @@ | ||
import UIKit | ||
import Combine | ||
|
||
open class WMFComponentNavigationController: UINavigationController { | ||
|
||
// MARK: - Private Properties | ||
|
||
private var cancellables = Set<AnyCancellable>() | ||
|
||
// MARK: - Public Properties | ||
|
||
var appEnvironment: WMFAppEnvironment { | ||
return WMFAppEnvironment.current | ||
} | ||
|
||
var theme: WMFTheme { | ||
return WMFAppEnvironment.current.theme | ||
} | ||
|
||
var forcePortrait = false | ||
|
||
// MARK: - Public | ||
|
||
@objc public convenience init(rootViewController: UIViewController, modalPresentationStyle: UIModalPresentationStyle) { | ||
self.init(rootViewController: rootViewController) | ||
self.modalPresentationStyle = modalPresentationStyle | ||
} | ||
|
||
public override init(rootViewController: UIViewController) { | ||
super.init(rootViewController: rootViewController) | ||
subscribeToAppEnvironmentChanges() | ||
setup() | ||
} | ||
|
||
open override func viewWillAppear(_ animated: Bool) { | ||
super.viewWillAppear(animated) | ||
|
||
setBarAppearance() | ||
} | ||
|
||
required public init?(coder aDecoder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
open override var supportedInterfaceOrientations: UIInterfaceOrientationMask { | ||
return forcePortrait ? .portrait : topViewController?.supportedInterfaceOrientations ?? .all | ||
} | ||
|
||
open override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation { | ||
return topViewController?.preferredInterfaceOrientationForPresentation ?? .portrait | ||
} | ||
|
||
public func turnOnForcePortrait() { | ||
forcePortrait = true | ||
} | ||
|
||
public func turnOffForcePortrait() { | ||
forcePortrait = false | ||
} | ||
|
||
// MARK: - AppEnvironment Subscription | ||
|
||
private func subscribeToAppEnvironmentChanges() { | ||
WMFAppEnvironment.publisher | ||
.sink(receiveValue: { [weak self] _ in self?.appEnvironmentDidChange() }) | ||
.store(in: &cancellables) | ||
} | ||
|
||
// MARK: - Subclass Overrides | ||
|
||
public func appEnvironmentDidChange() { | ||
overrideUserInterfaceStyle = theme.userInterfaceStyle | ||
setNeedsStatusBarAppearanceUpdate() | ||
|
||
setBarAppearance() | ||
} | ||
|
||
private func setBarAppearance() { | ||
|
||
let barAppearance = UINavigationBarAppearance() | ||
barAppearance.configureWithOpaqueBackground() | ||
barAppearance.largeTitleTextAttributes = [.font: WMFFont.navigationBarLeadingLargeTitleFont] | ||
|
||
if modalPresentationStyle == .pageSheet { | ||
barAppearance.backgroundColor = theme.midBackground | ||
let backgroundImage = UIImage.roundedRectImage(with: theme.midBackground, cornerRadius: 1) | ||
barAppearance.backgroundImage = backgroundImage | ||
} else { | ||
barAppearance.backgroundColor = theme.paperBackground | ||
let backgroundImage = UIImage.roundedRectImage(with: theme.paperBackground, cornerRadius: 1) | ||
barAppearance.backgroundImage = backgroundImage | ||
} | ||
|
||
barAppearance.shadowImage = UIImage() | ||
barAppearance.shadowColor = .clear | ||
|
||
navigationBar.tintColor = theme.navigationBarTintColor | ||
navigationBar.standardAppearance = barAppearance | ||
navigationBar.scrollEdgeAppearance = barAppearance | ||
navigationBar.compactAppearance = barAppearance | ||
} | ||
|
||
open override var preferredStatusBarStyle: UIStatusBarStyle { | ||
return theme.preferredStatusBarStyle | ||
} | ||
|
||
// MARK: - Private | ||
|
||
private func setup() { | ||
interactivePopGestureRecognizer?.delegate = self | ||
} | ||
|
||
} | ||
|
||
extension WMFComponentNavigationController: UIGestureRecognizerDelegate { | ||
public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { | ||
return viewControllers.count > 0 | ||
} | ||
|
||
public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { | ||
if gestureRecognizer is UIScreenEdgePanGestureRecognizer { | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
} |
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.