Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isAutoHidden config property #6

Merged
merged 3 commits into from
Jan 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ANZBreadcrumbsNavigationController.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'ANZBreadcrumbsNavigationController'
s.version = '0.5.0'
s.version = '0.6.0'
s.summary = 'Breadcrumbs navigation controller.'
s.description = <<-DESC
ANZBreadcrumbsNavigationController is breadcrums navigation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Foundation
@objc public dynamic var maxWidth: CGFloat = 320.0
@objc public dynamic var showsHorizontalScrollIndicator: Bool = false
@objc public dynamic var isRootDisplayed: Bool = false
@objc public dynamic var isAutoHidden: Bool = false
@objc public dynamic var itemStyle: ItemStyle = ItemStyle()

@objc public class ItemStyle: NSObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,17 @@ public class ANZBreadcrumbsNavigationController: UINavigationController {
private var containerViewHeightConstraint: NSLayoutConstraint?

private var inTransition: Bool = false
private var inAnimation: Bool = false

public override func viewDidLoad() {
super.viewDidLoad()
self.setupUI()
self.delegate = self

self.setupUI()
}

public override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

if #available(iOS 11.0, *) {
self.additionalSafeAreaInsets = UIEdgeInsets(top: self.config.height, left: 0, bottom: 0, right: 0)
}
}

public override func viewDidAppear(_ animated: Bool) {
Expand Down Expand Up @@ -129,13 +127,10 @@ extension ANZBreadcrumbsNavigationController {

private func setupUI() {

if #available(iOS 11.0, *) {
self.additionalSafeAreaInsets = UIEdgeInsets(top: self.config.height, left: 0, bottom: 0, right: 0)
}

let container = UIView(frame: CGRect(x: 0, y: UIApplication.shared.statusBarFrame.height + self.navigationBar.frame.height, width: self.view.bounds.width, height: self.config.height))
container.backgroundColor = self.config.backgroundColor
container.translatesAutoresizingMaskIntoConstraints = false
container.isHidden = self.config.isAutoHidden
self.view.addSubview(container)
let heightConstraint = container.heightAnchor.constraint(equalToConstant: self.config.height)
if #available(iOS 11.0, *) {
Expand Down Expand Up @@ -177,10 +172,6 @@ extension ANZBreadcrumbsNavigationController {

private func updateUI(config: ANZBreadcrumbsNavigationConfig) {

if #available(iOS 11.0, *) {
self.additionalSafeAreaInsets = UIEdgeInsets(top: config.height, left: 0, bottom: 0, right: 0)
}

self.containerView?.backgroundColor = config.backgroundColor
self.containerViewHeightConstraint?.constant = config.height
self.containerViewHeightConstraint?.isActive = true
Expand All @@ -189,6 +180,62 @@ extension ANZBreadcrumbsNavigationController {

self.view.setNeedsLayout()
}

private func showBreadcrumbsIfNeeded() {

self.notifyDidShowBreadcrumbs()

guard !self.inAnimation, let containerView = self.containerView, containerView.isHidden else {
return
}
self.inAnimation = true

UIView.animate(withDuration: 0.3, animations: {
containerView.alpha = 1.0
}) { _ in
self.inAnimation = false
containerView.isHidden = false
}
}

private func hideBreadcrumbsIfNeeded() {

self.notifyDidHideBreadcrumbs()

guard !self.inAnimation, let containerView = self.containerView, !containerView.isHidden else {
return
}
self.inAnimation = true

UIView.animate(withDuration: 0.3, animations: {
containerView.alpha = 0.0
}) { _ in
self.inAnimation = false
containerView.isHidden = true
}
}
}

// MARK: - Notification
extension ANZBreadcrumbsNavigationController {

private func notifyDidShowBreadcrumbs() {

if #available(iOS 11.0, *), self.additionalSafeAreaInsets.top != self.config.height {
self.additionalSafeAreaInsets = UIEdgeInsets(top: self.config.height, left: 0, bottom: 0, right: 0)
}

NotificationCenter.default.post(name: .ANZBreadcrumbsDidShowBreadcrumbsView, object: self.config)
}

private func notifyDidHideBreadcrumbs() {

if #available(iOS 11.0, *), self.additionalSafeAreaInsets.top != 0 {
self.additionalSafeAreaInsets = .zero
}

NotificationCenter.default.post(name: .ANZBreadcrumbsDidHideBreadcrumbsView, object: self.config)
}
}

// MARK: - Manage list view
Expand Down Expand Up @@ -221,8 +268,17 @@ extension ANZBreadcrumbsNavigationController: UICollectionViewDataSource {

public func numberOfSections(in collectionView: UICollectionView) -> Int {

if !self.config.isRootDisplayed && self.viewControllers.count == 1 {
return 0
if 1 >= self.viewControllers.count {

if self.config.isAutoHidden {
self.hideBreadcrumbsIfNeeded()
}

if !self.config.isRootDisplayed {
return 0
}
} else if self.config.isAutoHidden {
self.showBreadcrumbsIfNeeded()
}

return self.viewControllers.count
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// NotificationName+ANZBreadscrumbs.swift
// ANZBreadcrumbsNavigationController
//
// Created by sasato on 2019/01/27.
//

import Foundation

extension Notification.Name {

public static let ANZBreadcrumbsDidShowBreadcrumbsView: Notification.Name = Notification.Name("ANZBreadcrumbs.didShowBreadcrumbsView")

public static let ANZBreadcrumbsDidHideBreadcrumbsView: Notification.Name = Notification.Name("ANZBreadcrumbs.didHideBreadcrumbsView")
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -70,7 +69,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
<userDefinedRuntimeAttribute type="color" keyPath="config.itemStyle.textColor">
<color key="value" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="boolean" keyPath="config.isAutoHidden" value="YES"/>
</userDefinedRuntimeAttributes>
<connections>
<segue destination="VFc-rK-gPj" kind="relationship" relationship="rootViewController" id="GZG-iz-MTb"/>
Expand Down Expand Up @@ -145,6 +146,9 @@
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="boolean" keyPath="config.isAutoHidden" value="NO"/>
</userDefinedRuntimeAttributes>
<connections>
<segue destination="vXZ-lx-hvc" kind="relationship" relationship="rootViewController" id="Z6b-KN-aSa"/>
</connections>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,34 @@ import UIKit
import ANZBreadcrumbsNavigationController

class TableViewController: UITableViewController {

override func viewDidLoad() {
super.viewDidLoad()

self.title = "Table \(self.navigationController?.viewControllers.count ?? 0)"

if let navicationController = self.navigationController as? ANZBreadcrumbsNavigationController, let root = navicationController.viewControllers.first {
if root == self {
let barButton = UIBarButtonItem(title: "Close", style: .plain, target: self, action: #selector(type(of: self).back))
navigationItem.leftBarButtonItems = [barButton]
}

if #available(iOS 11.0, *) { } else {
var inset = self.tableView.contentInset
inset.top += navicationController.listViewHeight
self.tableView.contentInset = inset
}
}
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

NotificationCenter.default.addObserver(self, selector: #selector(type(of: self).didShowBreadcrumbsViewNotified(_:)), name: .ANZBreadcrumbsDidShowBreadcrumbsView, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(type(of: self).didHideBreadcrumbsViewNotified(_:)), name: .ANZBreadcrumbsDidHideBreadcrumbsView, object: nil)

}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)

NotificationCenter.default.removeObserver(self)
}

@objc func back() {
self.dismiss(animated: true, completion: nil)
}
Expand Down Expand Up @@ -57,3 +66,38 @@ class TableViewController: UITableViewController {
}

}

// MARK: - Notification
@objc extension TableViewController {

private func didShowBreadcrumbsViewNotified(_ notification: Notification) {

guard let config = notification.object as? ANZBreadcrumbsNavigationConfig else {
return
}

if #available(iOS 11.0, *) { } else {
var inset = self.tableView.contentInset
var top = UIApplication.shared.statusBarFrame.height + config.height
if let navigationBar = self.navigationController?.navigationBar {
top += navigationBar.frame.height
}
inset.top = top
self.tableView.contentInset = inset
}
}

private func didHideBreadcrumbsViewNotified(_ notification: Notification) {

if #available(iOS 11.0, *) { } else {
var inset = self.tableView.contentInset
var top = UIApplication.shared.statusBarFrame.height
if let navigationBar = self.navigationController?.navigationBar {
top += navigationBar.frame.height
}
inset.top = top
self.tableView.contentInset = inset
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

self.title = "ViewController \(self.navigationController?.viewControllers.count ?? 0)"

if let navicationController = self.navigationController as? ANZBreadcrumbsNavigationController {
Expand All @@ -27,10 +28,6 @@ class ViewController: UIViewController {
navigationItem.leftBarButtonItems = [barButton]
}
}

if #available(iOS 11.0, *) { } else {
stackViewTopConstraint.constant = navicationController.listViewHeight
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- ANZBreadcrumbsNavigationController (0.5.0)
- ANZBreadcrumbsNavigationController (0.6.0)

DEPENDENCIES:
- ANZBreadcrumbsNavigationController (from `../`)
Expand All @@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
ANZBreadcrumbsNavigationController: b304ce5d44aa61a802e1f65925d9584fa356c5e1
ANZBreadcrumbsNavigationController: 77439ecda85fd34e67aa763c8fb9dfdcc4cf7787

PODFILE CHECKSUM: 14d21dd73be5a678d45c01fbc2c2f183e4908221

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading