Skip to content

Commit

Permalink
Merge pull request #5121 from wikimedia/prototype/system-nav-bar
Browse files Browse the repository at this point in the history
Remove custom navigation bar
  • Loading branch information
tonisevener authored Jan 17, 2025
2 parents 470ae59 + 0b3e909 commit 16c3601
Show file tree
Hide file tree
Showing 322 changed files with 5,342 additions and 7,177 deletions.
2 changes: 1 addition & 1 deletion WMF Framework/CollectionViewEditController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ public class CollectionViewEditController: NSObject, UIGestureRecognizerDelegate
rightButton?.tag = editingState.tag
rightButton?.isEnabled = isRightBarButtonEnabled

let font = WMFFont.for(.boldHeadline)
let font = WMFFont.for(.body)
let attributes = [NSAttributedString.Key.font: font]
rightButton?.setTitleTextAttributes(attributes, for: .normal)
leftButton?.setTitleTextAttributes(attributes, for: .normal)
Expand Down
4 changes: 3 additions & 1 deletion WMF Framework/CommonStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public class CommonStrings: NSObject {
@objc public static let userTitle = WMFLocalizedString("user-title", value: "User", comment: "Text that refers to a user in the app")


@objc public static let doneTitle = WMFLocalizedString("description-published-button-title", value: "Done", comment: "Title for description panel done button.")
@objc public static let doneTitle = WMFLocalizedString("description-published-button-title", value: "Done", comment: "Title for done button.")
public static let goBackTitle = WMFLocalizedString("button-go-back", value: "Go back", comment: "Button text for Go back button used in various places")
public static let publishAnywayTitle = WMFLocalizedString("button-publish-anyway", value: "Publish anyway", comment: "Button text for publish button used when first warned against publishing.")

Expand Down Expand Up @@ -647,6 +647,8 @@ public class CommonStrings: NSObject {

public static let editContextMenuTitle = WMFLocalizedString("edit-menu-item", value: "Edit", comment: "Button label for 'Edit' context menu item")

public static let editorTitle = WMFLocalizedString("editor-title", value: "Editor", comment: "Title of editor view.")

public static let editSource = WMFLocalizedString("editor-edit-source", value: "Edit source", comment: "Title for menu option to edit the source of a page.")

public static let editPublishedToastTitle = WMFLocalizedString("editor-edit-published", value: "Your edit was published.", comment: "Title for alert informing that the user's new edit was successfully published.")
Expand Down
894 changes: 0 additions & 894 deletions WMF Framework/NavigationBar.swift

This file was deleted.

5 changes: 1 addition & 4 deletions WMF Framework/NavigationState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ public struct NavigationState: Codable {
public var readingListURIString: String?

public var searchTerm: String?

public var shouldShowNavigationBar: Bool?

public var contentGroupIDURIString: String?

Expand All @@ -86,7 +84,7 @@ public struct NavigationState: Codable {

// TODO: Remove after moving to Swift 5.1 -
// https://github.com/apple/swift-evolution/blob/master/proposals/0242-default-values-memberwise.md
public init(url: URL? = nil, selectedIndex: Int? = nil, articleKey: String? = nil, articleSectionAnchor: String? = nil, talkPageSiteURLString: String? = nil, talkPageTitle: String? = nil, talkPageTypeRawValue: Int? = nil, currentSavedViewRawValue: Int? = nil, readingListURIString: String? = nil, searchTerm: String? = nil, shouldShowNavigationBar: Bool? = nil, contentGroupIDURIString: String? = nil, presentedContentGroupKey: String? = nil) {
public init(url: URL? = nil, selectedIndex: Int? = nil, articleKey: String? = nil, articleSectionAnchor: String? = nil, talkPageSiteURLString: String? = nil, talkPageTitle: String? = nil, talkPageTypeRawValue: Int? = nil, currentSavedViewRawValue: Int? = nil, readingListURIString: String? = nil, searchTerm: String? = nil, contentGroupIDURIString: String? = nil, presentedContentGroupKey: String? = nil) {
self.url = url
self.selectedIndex = selectedIndex
self.articleKey = articleKey
Expand All @@ -97,7 +95,6 @@ public struct NavigationState: Codable {
self.currentSavedViewRawValue = currentSavedViewRawValue
self.readingListURIString = readingListURIString
self.searchTerm = searchTerm
self.shouldShowNavigationBar = shouldShowNavigationBar
self.contentGroupIDURIString = contentGroupIDURIString
self.presentedContentGroupKey = presentedContentGroupKey
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,59 @@ import Combine
/// SwiftUI `View` via `UIHostingController` based Component
open class WMFComponentHostingController<HostedView: View>: UIHostingController<HostedView> {

// MARK: - Private Properties
// MARK: - Private Properties

private var cancellables = Set<AnyCancellable>()
private var cancellables = Set<AnyCancellable>()

// MARK: - Public Properties
// MARK: - Public Properties

var appEnvironment: WMFAppEnvironment {
return WMFAppEnvironment.current
}
var appEnvironment: WMFAppEnvironment {
return WMFAppEnvironment.current
}

var theme: WMFTheme {
return WMFAppEnvironment.current.theme
}
var theme: WMFTheme {
return WMFAppEnvironment.current.theme
}

// MARK: - Public
// MARK: - Public

public override init(rootView: HostedView) {
super.init(rootView: rootView)
subscribeToAppEnvironmentChanges()
}
public override init(rootView: HostedView) {
super.init(rootView: rootView)
subscribeToAppEnvironmentChanges()
setup()
}

public override init?(coder aDecoder: NSCoder, rootView: HostedView) {
super.init(coder: aDecoder, rootView: rootView)
subscribeToAppEnvironmentChanges()
}
public override init?(coder aDecoder: NSCoder, rootView: HostedView) {
super.init(coder: aDecoder, rootView: rootView)
subscribeToAppEnvironmentChanges()
setup()
}

public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
subscribeToAppEnvironmentChanges()
}
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
subscribeToAppEnvironmentChanges()
setup()
}

// MARK: - WMFAppEnvironment Subscription
// MARK: - Lifecycle

private func subscribeToAppEnvironmentChanges() {
WMFAppEnvironment.publisher
.sink(receiveValue: { [weak self] _ in self?.appEnvironmentDidChange() })
.store(in: &cancellables)
}
private func setup() {

}

// MARK: - Subclass Overrides
// MARK: - WMFAppEnvironment Subscription

public func appEnvironmentDidChange() {
// Subclasses should implement
}
private func subscribeToAppEnvironmentChanges() {
WMFAppEnvironment.publisher
.sink(receiveValue: { [weak self] _ in self?.appEnvironmentDidChange() })
.store(in: &cancellables)
}

// MARK: - Subclass Overrides

public func appEnvironmentDidChange() {
overrideUserInterfaceStyle = appEnvironment.theme.userInterfaceStyle
setNeedsStatusBarAppearanceUpdate()
}

}
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,47 @@ import Combine
/// UIKit `UIView` based Component
public class WMFComponentView: UIView {

// MARK: - Private Properties
// MARK: - Private Properties

private var cancellables = Set<AnyCancellable>()
private var cancellables = Set<AnyCancellable>()

// MARK: - Public Properties
// MARK: - Public Properties

var appEnvironment: WMFAppEnvironment {
return WMFAppEnvironment.current
}
var appEnvironment: WMFAppEnvironment {
return WMFAppEnvironment.current
}

var theme: WMFTheme {
return WMFAppEnvironment.current.theme
}
var theme: WMFTheme {
return WMFAppEnvironment.current.theme
}

// MARK: - Public
// MARK: - Public

public override init(frame: CGRect) {
super.init(frame: frame)
translatesAutoresizingMaskIntoConstraints = false
subscribeToAppEnvironmentChanges()
}
public override init(frame: CGRect) {
super.init(frame: frame)
translatesAutoresizingMaskIntoConstraints = false
subscribeToAppEnvironmentChanges()
}

public required init?(coder: NSCoder) {
super.init(coder: coder)
translatesAutoresizingMaskIntoConstraints = false
subscribeToAppEnvironmentChanges()
}
public required init?(coder: NSCoder) {
super.init(coder: coder)
translatesAutoresizingMaskIntoConstraints = false
subscribeToAppEnvironmentChanges()
}

// MARK: - AppEnvironment Subscription
// MARK: - AppEnvironment Subscription

private func subscribeToAppEnvironmentChanges() {
WMFAppEnvironment.publisher
.sink(receiveValue: { [weak self] _ in self?.appEnvironmentDidChange() })
.store(in: &cancellables)
}
private func subscribeToAppEnvironmentChanges() {
WMFAppEnvironment.publisher
.sink(receiveValue: { [weak self] _ in self?.appEnvironmentDidChange() })
.store(in: &cancellables)
}

// MARK: - Subclass Overrides
// MARK: - Subclass Overrides

public func appEnvironmentDidChange() {
overrideUserInterfaceStyle = appEnvironment.theme.userInterfaceStyle
// Subclasses should implement
}

public func appEnvironmentDidChange() {
// Subclasses should implement
}

}
Loading

0 comments on commit 16c3601

Please sign in to comment.