Skip to content

Commit

Permalink
Fix #2
Browse files Browse the repository at this point in the history
  • Loading branch information
aydenp committed Dec 4, 2017
1 parent e678110 commit 980176a
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 5 deletions.
8 changes: 8 additions & 0 deletions Bank.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/* Begin PBXBuildFile section */
522AF4AFBC5AE29C6CC94469 /* Pods_Bank.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8309205B2A03DC256D5ED50F /* Pods_Bank.framework */; };
C31107CF1FD507B600ABF56B /* Account+Transactions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C31107CE1FD507B600ABF56B /* Account+Transactions.swift */; };
C31107D11FD51C3700ABF56B /* HairlineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C31107D01FD51C3700ABF56B /* HairlineView.swift */; };
C31107D31FD51C4F00ABF56B /* StatusBarOverlayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C31107D21FD51C4F00ABF56B /* StatusBarOverlayView.swift */; };
C316128E1FD48B5D000EC5ED /* InstitutionResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = C316128D1FD48B5D000EC5ED /* InstitutionResponse.swift */; };
C31612901FD48B7E000EC5ED /* Institution.swift in Sources */ = {isa = PBXBuildFile; fileRef = C316128F1FD48B7E000EC5ED /* Institution.swift */; };
C31612961FD4EDB9000EC5ED /* NSAttributedString+LargestFontSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = C31612951FD4EDB9000EC5ED /* NSAttributedString+LargestFontSize.swift */; };
Expand Down Expand Up @@ -53,6 +55,8 @@
8309205B2A03DC256D5ED50F /* Pods_Bank.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Bank.framework; sourceTree = BUILT_PRODUCTS_DIR; };
A313A1E6671600F88ED6B46E /* Pods-Bank.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Bank.release.xcconfig"; path = "Pods/Target Support Files/Pods-Bank/Pods-Bank.release.xcconfig"; sourceTree = "<group>"; };
C31107CE1FD507B600ABF56B /* Account+Transactions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Account+Transactions.swift"; sourceTree = "<group>"; };
C31107D01FD51C3700ABF56B /* HairlineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HairlineView.swift; sourceTree = "<group>"; };
C31107D21FD51C4F00ABF56B /* StatusBarOverlayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusBarOverlayView.swift; sourceTree = "<group>"; };
C316128D1FD48B5D000EC5ED /* InstitutionResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstitutionResponse.swift; sourceTree = "<group>"; };
C316128F1FD48B7E000EC5ED /* Institution.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Institution.swift; sourceTree = "<group>"; };
C31612951FD4EDB9000EC5ED /* NSAttributedString+LargestFontSize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSAttributedString+LargestFontSize.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -192,6 +196,7 @@
children = (
C3F578081FD2EAB10017EE17 /* APButton.swift */,
C3F578061FD2EA480017EE17 /* GradientView.swift */,
C31107D01FD51C3700ABF56B /* HairlineView.swift */,
);
path = Utility;
sourceTree = "<group>";
Expand Down Expand Up @@ -229,6 +234,7 @@
C3CBCAB81FD461E700010AA8 /* AmountLabel.swift */,
C3CBCABC1FD4767A00010AA8 /* AccountHeaderView.swift */,
C3CBCABA1FD469B900010AA8 /* BackgroundGradientView.swift */,
C31107D21FD51C4F00ABF56B /* StatusBarOverlayView.swift */,
C3CBCAB71FD461B600010AA8 /* Utility */,
);
path = Views;
Expand Down Expand Up @@ -376,6 +382,7 @@
C3BCF73A1FCFB8FA0010497E /* PlaidManager.swift in Sources */,
C3F5780B1FD2EC170017EE17 /* StatusViewController.swift in Sources */,
C3CBCA971FD3079E00010AA8 /* ErrorResponse.swift in Sources */,
C31107D11FD51C3700ABF56B /* HairlineView.swift in Sources */,
C31612901FD48B7E000EC5ED /* Institution.swift in Sources */,
C3CBCAA71FD3186700010AA8 /* ViewController+Status.swift in Sources */,
C3F578021FD2DD8C0017EE17 /* PlaidResponse.swift in Sources */,
Expand All @@ -397,6 +404,7 @@
C3CBCAB11FD4491800010AA8 /* SessionDataStorage.swift in Sources */,
C3BCF7281FCF5C130010497E /* AppDelegate.swift in Sources */,
C3CBCAB61FD461A400010AA8 /* TransactionAmountLabel.swift in Sources */,
C31107D31FD51C4F00ABF56B /* StatusBarOverlayView.swift in Sources */,
C3F578071FD2EA480017EE17 /* GradientView.swift in Sources */,
C3CBCA9A1FD30B1500010AA8 /* UIViewController+ShorthandAlerts.swift in Sources */,
C3F578041FD2DDE40017EE17 /* PlaidError.swift in Sources */,
Expand Down
13 changes: 11 additions & 2 deletions Bank/AccountViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ class AccountViewController: UITableViewController, AccountHeaderViewDelegate {
return tableView.tableHeaderView as! AccountHeaderView
}

var shouldShowStatusBarHairline = false {
didSet {
if oldValue == shouldShowStatusBarHairline { return }
delegate?.accountViewController(self, shouldShowStatusBarHairlineChangedTo: shouldShowStatusBarHairline)
}
}

// MARK: - Data Loading

var transactions = [Transaction]() {
Expand All @@ -46,6 +53,7 @@ class AccountViewController: UITableViewController, AccountHeaderViewDelegate {

override func scrollViewDidScroll(_ scrollView: UIScrollView) {
scrollView.scrollIndicatorInsets.top = max(headerView.frame.maxY - scrollView.contentOffset.y - scrollView.adjustedContentInset.top, 0)
shouldShowStatusBarHairline = scrollView.contentOffset.y > headerView.infoStackView.convert(headerView.infoStackView.bounds, to: scrollView).minY - scrollView.adjustedContentInset.top
}

// MARK: - Table View Data Source
Expand All @@ -69,10 +77,11 @@ class AccountViewController: UITableViewController, AccountHeaderViewDelegate {
// MARK: - Account Header View Delegate

func shouldMove(to index: Int) {
delegate?.shouldMove(to: index)
delegate?.accountViewController(self, shouldMoveTo: index)
}
}

protocol AccountViewControllerDelegate: class {
func shouldMove(to index: Int)
func accountViewController(_ viewController: AccountViewController, shouldMoveTo index: Int)
func accountViewController(_ viewController: AccountViewController, shouldShowStatusBarHairlineChangedTo shouldShow: Bool)
}
1 change: 1 addition & 0 deletions Bank/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
<outlet property="amountLabel" destination="KUA-aH-omm" id="Q2X-oC-uXQ"/>
<outlet property="chartContainerView" destination="drY-yl-DdM" id="uZO-aA-w7i"/>
<outlet property="chartLoadingView" destination="abw-PF-ErW" id="mFm-e9-giY"/>
<outlet property="infoStackView" destination="UDC-Ph-GPI" id="Cqz-6j-UcJ"/>
<outlet property="institutionLabel" destination="5Gl-gL-Tu5" id="TKl-d7-QwK"/>
<outlet property="nameLabel" destination="Plo-Ia-DOK" id="W3J-qN-XBK"/>
<outlet property="pageControl" destination="7N1-VT-en8" id="5RI-lX-7y0"/>
Expand Down
31 changes: 28 additions & 3 deletions Bank/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@

import UIKit

class ViewController: UIPageViewController, UIPageViewControllerDataSource, AccountViewControllerDelegate, NoAccountsViewControllerDelegate {
class ViewController: UIPageViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate, AccountViewControllerDelegate, NoAccountsViewControllerDelegate {
var statusViewController: StatusViewController?
var statusBarOverlayView: StatusBarOverlayView!
var isExchanging = false

override func viewDidLoad() {
super.viewDidLoad()

dataSource = self
delegate = self

let appearance = UIPageControl.appearance(whenContainedInInstancesOf: [UIPageViewController.self])
appearance.pageIndicatorTintColor = UIColor(white: 0.8, alpha: 1)
Expand All @@ -24,6 +26,15 @@ class ViewController: UIPageViewController, UIPageViewControllerDataSource, Acco
// Add gradient view as background
view.insertSubview(BackgroundGradientView(frame: view.bounds), at: 0)

// Create status bar overlay view
statusBarOverlayView = StatusBarOverlayView()
view.addSubview(statusBarOverlayView)
statusBarOverlayView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
statusBarOverlayView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
statusBarOverlayView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
statusBarOverlayView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
statusBarOverlayView.viewHeightAnchor = view.heightAnchor

// Listen for and reload on fetched bank account changes
NotificationCenter.default.addObserver(self, selector: #selector(reloadViewControllers), name: SessionDataStorage.accountsChangedNotification, object: nil)

Expand Down Expand Up @@ -62,10 +73,14 @@ class ViewController: UIPageViewController, UIPageViewControllerDataSource, Acco
}

var currentIndex: Int? {
guard let account = (viewControllers?.first as? AccountViewController)?.account else { return nil }
guard let account = currentViewController?.account else { return nil }
return SessionDataStorage.shared.accounts?.index(of: account)
}

var currentViewController: AccountViewController? {
return viewControllers?.first as? AccountViewController
}

func getViewController(for index: Int) -> AccountViewController {
let vc = AccountViewController.get()
vc.account = SessionDataStorage.shared.accounts?[index]
Expand Down Expand Up @@ -104,6 +119,12 @@ class ViewController: UIPageViewController, UIPageViewControllerDataSource, Acco
return getViewController(for: newIndex)
}

// MARK: - Page View Controller Delegate

func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
statusBarOverlayView.isHairlineVisible = currentViewController?.shouldShowStatusBarHairline ?? false
}

// MARK: - No Accounts View Controller Delegate

func didTapUnlink() {
Expand All @@ -123,8 +144,12 @@ class ViewController: UIPageViewController, UIPageViewControllerDataSource, Acco

// MARK: - Account View Controller Delegate

func shouldMove(to index: Int) {
func accountViewController(_ viewController: AccountViewController, shouldMoveTo index: Int) {
guard let currentIndex = self.currentIndex, currentIndex != index else { return }
setViewControllers([getViewController(for: index)], direction: index > currentIndex ? .forward : .reverse, animated: true, completion: nil)
}

func accountViewController(_ viewController: AccountViewController, shouldShowStatusBarHairlineChangedTo shouldShow: Bool) {
statusBarOverlayView.isHairlineVisible = shouldShow
}
}
1 change: 1 addition & 0 deletions Bank/Views/AccountHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class AccountHeaderView: UIView {
@IBOutlet weak var chartContainerView: UIView!
@IBOutlet weak var chartLoadingView: UIActivityIndicatorView!
@IBOutlet weak var pageControl: UIPageControl!
@IBOutlet weak var infoStackView: UIStackView!
var hasAwaken = false
var chart: Chart!

Expand Down
58 changes: 58 additions & 0 deletions Bank/Views/StatusBarOverlayView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// StatusBarOverlayView.swift
// Bank
//
// Created by Ayden Panhuyzen on 2017-12-04.
// Copyright © 2017 Ayden Panhuyzen. All rights reserved.
//

import UIKit

class StatusBarOverlayView: UIView {
private var gradientView: BackgroundGradientView!, gradientViewHeightAnchor: NSLayoutConstraint?, hairlineView: HairlineView!

override init(frame: CGRect) {
super.init(frame: frame)

translatesAutoresizingMaskIntoConstraints = false
clipsToBounds = true

gradientView = BackgroundGradientView()
gradientView.translatesAutoresizingMaskIntoConstraints = false
addSubview(gradientView)
gradientView.topAnchor.constraint(equalTo: topAnchor).isActive = true
gradientView.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
gradientView.rightAnchor.constraint(equalTo: rightAnchor).isActive = true

hairlineView = HairlineView()
hairlineView.translatesAutoresizingMaskIntoConstraints = false
hairlineView.backgroundColor = UIColor(white: 0, alpha: 0.15)
hairlineView.alpha = 0
addSubview(hairlineView)
hairlineView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
hairlineView.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
hairlineView.rightAnchor.constraint(equalTo: rightAnchor).isActive = true
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

/// The height anchor to use to layout the gradient view (to match the background of the view controller)
var viewHeightAnchor: NSLayoutDimension? {
didSet {
gradientViewHeightAnchor?.isActive = false
guard let anchor = viewHeightAnchor else { return }
gradientViewHeightAnchor = gradientView.heightAnchor.constraint(equalTo: anchor)
gradientViewHeightAnchor!.isActive = true
}
}

/// Whether or not the hairline view should be shown.
var isHairlineVisible = false {
didSet {
if isHairlineVisible == oldValue { return }
UIView.animate(withDuration: 0.1) { self.hairlineView.alpha = self.isHairlineVisible ? 1 : 0 }
}
}
}
21 changes: 21 additions & 0 deletions Bank/Views/Utility/HairlineView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// HairlineView.swift
//
// Created by Ayden Panhuyzen on 2017-08-21.
// Copyright © 2017 Ayden Panhuyzen. All rights reserved.
//

import UIKit

class HairlineView: UIView {
private var heightConstraint: NSLayoutConstraint?

override func didMoveToWindow() {
super.didMoveToWindow()
translatesAutoresizingMaskIntoConstraints = false
heightConstraint?.isActive = false
heightConstraint = heightAnchor.constraint(equalToConstant: 1 / (window?.screen.scale ?? 1))
heightConstraint!.isActive = true
}
}

0 comments on commit 980176a

Please sign in to comment.