Skip to content

Commit

Permalink
feat: Add reset and reload button to UserInterfaceToogleableNavigatio…
Browse files Browse the repository at this point in the history
…nAppController
  • Loading branch information
antranapp committed Nov 14, 2021
1 parent 9ef3b55 commit f2ddb60
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class TypographyScenario: AudienceTargetableScenario {
public static let kind = ScenarioKind.designSystem

public static var rootViewProvider: RootViewProviding {
UserInterfaceToogleableNavigationAppController { _ in
UserInterfaceToogleableNavigationAppController(withResetButton: true) { _ in
ReloadableHostingViewController(rootView: ContentView())
}
}
Expand Down
25 changes: 15 additions & 10 deletions Sources/Scenarios/AppController/NavigationAppController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@ import UIKit
public class NavigationAppController: RootViewProviding {
public var rootViewController: UIViewController

public init(
public convenience init(
withResetButton: Bool = false,
withRefreshButton: Bool = false,
makeChild: (UINavigationController) -> UIViewController
) {
var navigationController: UINavigationController
if withResetButton || withRefreshButton {
navigationController = ResetableRefreshableNavigationController(
hasResetButton: withResetButton,
hasRefreshButton: withRefreshButton
)
} else {
navigationController = UINavigationController()
}
let navigationController = ResetableRefreshableNavigationController(
hasResetButton: withResetButton,
hasRefreshButton: withRefreshButton
)
self.init(
navigationController: navigationController,
makeChild: makeChild
)
}

public init(
navigationController: UINavigationController,
makeChild: (UINavigationController) -> UIViewController
) {
navigationController.pushViewController(makeChild(navigationController), animated: false)
rootViewController = navigationController
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,41 @@ import UIKit

// swiftlint:disable type_name
@available(iOS 13.0, *)
public struct UserInterfaceToogleableNavigationAppController: RootViewProviding {
public var rootViewController: UIViewController
public class UserInterfaceToogleableNavigationAppController: NavigationAppController {

public init(
withResetButton: Bool = false,
withRefreshButton: Bool = false,
makeChild: (UINavigationController) -> ReloadableViewController
) {
let navigationController = UserInterfaceToogleableNavigationController()
navigationController.pushViewController(makeChild(navigationController), animated: false)
rootViewController = navigationController
let navigationController = UserInterfaceToogleableNavigationController(
hasResetButton: withResetButton,
hasRefreshButton: withResetButton
)
super.init(
navigationController: navigationController,
makeChild: makeChild
)
}
}

@available(iOS 13.0, *)
class UserInterfaceToogleableNavigationController: UINavigationController, UINavigationControllerDelegate {
class UserInterfaceToogleableNavigationController: ResetableRefreshableNavigationController {

private lazy var toggleInterfaceStyleButton: UIBarButtonItem = {
UIBarButtonItem(
image: UIImage(systemName: "sun.max"),
style: .plain, target: self, action: #selector(self.didToggleAppearanceMode)
)
}()

init() {
super.init(nibName: nil, bundle: nil)

override init(
hasResetButton: Bool = false,
hasRefreshButton: Bool = false
) {
super.init(hasResetButton: hasResetButton, hasRefreshButton: hasRefreshButton)
}

@available(*, unavailable)
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
Expand All @@ -43,7 +52,12 @@ class UserInterfaceToogleableNavigationController: UINavigationController, UINav
delegate = self
}

func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
override func navigationController(
_ navigationController: UINavigationController,
willShow viewController: UIViewController,
animated: Bool
) {
super.navigationController(navigationController, willShow: viewController, animated: animated)
viewController.navigationItem.rightBarButtonItem = toggleInterfaceStyleButton
}

Expand Down

0 comments on commit f2ddb60

Please sign in to comment.