From 6c736f5edcee4d7023ee391429e3cbff96dac731 Mon Sep 17 00:00:00 2001 From: Elijah Cobb Date: Sat, 13 Jul 2019 12:43:19 -0400 Subject: [PATCH] Programatic approcash done. --- subscribeto/subscribeto/S2UI/S2UIButton.swift | 55 +++------------ .../S2UI/S2UINavigationController.swift | 37 ++++++++++ subscribeto/subscribeto/S2UI/S2UIView.swift | 10 +++ .../pages/discover/S2DiscoverVC.swift | 21 ++++++ .../pages/home/S2HomeDashboard.swift | 70 +++++++++++++++++++ .../pages/home/S2HomeLaunchItem.swift | 8 ++- .../pages/home/S2HomeLauncher.swift | 43 +++++++++--- .../pages/home/S2HomeTopContainer.swift | 21 ------ .../subscribeto/pages/home/S2HomeVC.swift | 10 +-- 9 files changed, 190 insertions(+), 85 deletions(-) create mode 100644 subscribeto/subscribeto/S2UI/S2UINavigationController.swift create mode 100644 subscribeto/subscribeto/pages/discover/S2DiscoverVC.swift create mode 100644 subscribeto/subscribeto/pages/home/S2HomeDashboard.swift delete mode 100644 subscribeto/subscribeto/pages/home/S2HomeTopContainer.swift diff --git a/subscribeto/subscribeto/S2UI/S2UIButton.swift b/subscribeto/subscribeto/S2UI/S2UIButton.swift index 722edab..247f57c 100644 --- a/subscribeto/subscribeto/S2UI/S2UIButton.swift +++ b/subscribeto/subscribeto/S2UI/S2UIButton.swift @@ -8,22 +8,26 @@ import UIKit -class S2UIButton : UIView { +class S2UIButton : S2UIView, S2UIClickAnimator { var onClick: () -> Void private var text : String private let label: UILabel + let clickManager: S2UIClickManager init(text: String, onClick: @escaping () -> Void) { self.text = text self.onClick = onClick self.label = UILabel() + self.clickManager = S2UIClickManager() - super.init(frame: CGRect()) + super.init() + + self.clickManager.start(delegate: self) self.label.text = self.text - self.label.translatesAutoresizingMaskIntoConstraints = false + self.label.useAutoLayout() self.label.textAlignment = .center self.label.textColor = S2UITheme.white self.label.font = UIFont.systemFont(ofSize: self.label.font.pointSize, weight: .bold) @@ -38,7 +42,7 @@ class S2UIButton : UIView { } - convenience init() { self.init(text: "", onClick: {}) } + convenience override init() { self.init(text: "", onClick: {}) } convenience init(text: String) { self.init(text: text, onClick: {}) } convenience init(onClick: @escaping () -> Void) { self.init(text: "", onClick: onClick) } @@ -46,47 +50,8 @@ class S2UIButton : UIView { fatalError("init(coder:) has not been implemented") } - private func isBeingTouched(_ beingTouched: Bool) { - - let scale: CGFloat = beingTouched ? 1.1 : 1 - let duration: Double = beingTouched ? 0.5 : 0.5 - let damping: CGFloat = beingTouched ? 0.55 : 0.25 - let velocity: CGFloat = beingTouched ? 0.25 : 0.25 - - UIView.animate(withDuration: duration, delay: 0, usingSpringWithDamping: damping, initialSpringVelocity: velocity, options: [], animations: { - - self.transform = CGAffineTransform(scaleX: scale, y: scale) - - }) - - } - - override func touchesBegan(_ touches: Set, with event: UIEvent?) { - - isBeingTouched(true) - - } - - override func touchesMoved(_ touches: Set, with event: UIEvent?) { - - for touch in touches { - - let point = touch.location(in: self) - if point.x < 0 || point.x > self.frame.size.width || point.y < 0 || point.y > self.frame.size.height { - - isBeingTouched(false) - return - - } - - } - - } - - override func touchesEnded(_ touches: Set, with event: UIEvent?) { - - isBeingTouched(false) - + func clicked() { + onClick() } } diff --git a/subscribeto/subscribeto/S2UI/S2UINavigationController.swift b/subscribeto/subscribeto/S2UI/S2UINavigationController.swift new file mode 100644 index 0000000..ad6a980 --- /dev/null +++ b/subscribeto/subscribeto/S2UI/S2UINavigationController.swift @@ -0,0 +1,37 @@ +// +// S2UINavigationController.swift +// subscribeto +// +// Created by Elijah Cobb on 13/07/19. +// Copyright © 2019 subscribeto. All rights reserved. +// + +import UIKit + +class S2UINavigationController : UINavigationController { + + override func viewDidLoad() { + + self.navigationBar.isTranslucent = false + self.navigationBar.barTintColor = S2UITheme.darkBackground + self.navigationBar.tintColor = S2UITheme.white + self.navigationBar.titleTextAttributes = [.foregroundColor: S2UITheme.white] + + let grabber = UIView() + grabber.backgroundColor = S2UITheme.white + grabber.useAutoLayout() + grabber.layer.cornerRadius = 0 + + self.navigationBar.addSubview(grabber) + + NSLayoutConstraint.activate([ + grabber.widthAnchor.constraint(equalToConstant: 40), + grabber.heightAnchor.constraint(equalToConstant: 10), + grabber.topAnchor.constraint(equalTo: navigationBar.topAnchor, constant: -10), + grabber.centerXAnchor.constraint(equalTo: navigationBar.centerXAnchor) + ]) + + + } + +} diff --git a/subscribeto/subscribeto/S2UI/S2UIView.swift b/subscribeto/subscribeto/S2UI/S2UIView.swift index a48bf00..dd327d7 100644 --- a/subscribeto/subscribeto/S2UI/S2UIView.swift +++ b/subscribeto/subscribeto/S2UI/S2UIView.swift @@ -24,6 +24,16 @@ extension UIView { } +extension UIViewController { + + static func presentingViewController() -> UIViewController? { + + return UIApplication.shared.keyWindow?.rootViewController + + } + +} + class S2UIView : UIView { diff --git a/subscribeto/subscribeto/pages/discover/S2DiscoverVC.swift b/subscribeto/subscribeto/pages/discover/S2DiscoverVC.swift new file mode 100644 index 0000000..e3f836f --- /dev/null +++ b/subscribeto/subscribeto/pages/discover/S2DiscoverVC.swift @@ -0,0 +1,21 @@ +// +// S2DiscoverVC.swift +// subscribeto +// +// Created by Elijah Cobb on 13/07/19. +// Copyright © 2019 subscribeto. All rights reserved. +// + +import UIKit + +class S2DiscoverVC : UIViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + self.navigationItem.title = "Store" + self.view.backgroundColor = S2UITheme.lightBackground + + } + +} diff --git a/subscribeto/subscribeto/pages/home/S2HomeDashboard.swift b/subscribeto/subscribeto/pages/home/S2HomeDashboard.swift new file mode 100644 index 0000000..9124c28 --- /dev/null +++ b/subscribeto/subscribeto/pages/home/S2HomeDashboard.swift @@ -0,0 +1,70 @@ +// +// ouij.swift +// subscribeto +// +// Created by Elijah Cobb on 12/07/19. +// Copyright © 2019 subscribeto. All rights reserved. +// + +import UIKit + + +class S2HomeDashboard : UIView { + + var logoImage: UIImageView! + var logoText: UILabel! + var discoverButton: S2UIButton! + + func applyConstraints(padding: CGFloat) { + + NSLayoutConstraint.activate([ + logoImage.topAnchor.constraint(equalTo: self.topAnchor, constant: padding + 60), + logoImage.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 0), + logoImage.rightAnchor.constraint(equalTo: self.rightAnchor, constant: 0), + logoImage.bottomAnchor.constraint(equalTo: logoText.topAnchor, constant: -padding/2), + logoText.bottomAnchor.constraint(equalTo: discoverButton.topAnchor, constant: -padding * 2), + logoText.leftAnchor.constraint(equalTo: self.leftAnchor, constant: padding), + logoText.rightAnchor.constraint(equalTo: self.rightAnchor, constant: -padding), + logoText.heightAnchor.constraint(equalToConstant: 48), + discoverButton.leftAnchor.constraint(equalTo: self.leftAnchor, constant: padding * 4), + discoverButton.rightAnchor.constraint(equalTo: self.rightAnchor, constant: -padding * 4), + discoverButton.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: -padding * 2), + discoverButton.heightAnchor.constraint(equalToConstant: 60), + ]) + + } + + override func layoutSubviews() { + + super.layoutSubviews() + + self.backgroundColor = S2UITheme.darkBackground + + logoImage = UIImageView(image: UIImage(named: "iconTransparent")) + logoImage.contentMode = .scaleAspectFit + logoImage.useAutoLayout() + + logoText = UILabel() + logoText.text = "sub.scribe.to" + logoText.textAlignment = .center + logoText.textColor = S2UITheme.white + logoText.font = UIFont.systemFont(ofSize: 48, weight: .bold) + logoText.useAutoLayout() + + discoverButton = S2UIButton(text: "Discover") { + + print("Clicked launch item: Discover.") + let alert = UIAlertController(title: "Clicked 'Discover'", message: nil, preferredStyle: .alert) + alert.addAction(UIAlertAction.init(title: "Done", style: .default, handler: nil)) + UIViewController.presentingViewController()?.present(alert, animated: true, completion: nil) + + } + discoverButton.useAutoLayout() + + self.addSubviews(logoImage, logoText, discoverButton) + + applyConstraints(padding: 20) + + } + +} diff --git a/subscribeto/subscribeto/pages/home/S2HomeLaunchItem.swift b/subscribeto/subscribeto/pages/home/S2HomeLaunchItem.swift index a36fc6e..e57c8e6 100644 --- a/subscribeto/subscribeto/pages/home/S2HomeLaunchItem.swift +++ b/subscribeto/subscribeto/pages/home/S2HomeLaunchItem.swift @@ -13,16 +13,18 @@ class S2HomeLaunchItem : S2UIView, S2UIClickAnimator { let label: UILabel! let icon: UIImageView! let clickManager: S2UIClickManager + let onClick: () -> Void required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } - init(text: String, image: String) { + init(text: String, image: String, onClick : @escaping () -> Void) { let label = UILabel() label.text = text self.label = label self.icon = UIImageView(image: UIImage(named: image)?.withRenderingMode(.alwaysTemplate)) self.clickManager = S2UIClickManager() + self.onClick = onClick super.init() @@ -62,14 +64,14 @@ class S2HomeLaunchItem : S2UIView, S2UIClickAnimator { self.addSubviews(label, icon) - applyConstraints(padding: 20) + applyConstraints(padding: 10) } func clicked() { - print("Clicked launch item: \(self.label.text ?? "err").") + self.onClick() } diff --git a/subscribeto/subscribeto/pages/home/S2HomeLauncher.swift b/subscribeto/subscribeto/pages/home/S2HomeLauncher.swift index f6a90ad..03f2e76 100644 --- a/subscribeto/subscribeto/pages/home/S2HomeLauncher.swift +++ b/subscribeto/subscribeto/pages/home/S2HomeLauncher.swift @@ -15,16 +15,7 @@ class S2HomeLauncher : UIView { var launchItemStore: S2HomeLaunchItem! var launchItemSettings: S2HomeLaunchItem! - func layoutLaunchItems() { - - launchItemOrder = S2HomeLaunchItem(text: "Order", image: "order") - launchItemSubscriptions = S2HomeLaunchItem(text: "Subscriptions", image: "subscriptions") - launchItemStore = S2HomeLaunchItem(text: "Store", image: "store") - launchItemSettings = S2HomeLaunchItem(text: "Settings", image: "settings") - - self.addSubviews(launchItemOrder, launchItemSubscriptions, launchItemStore, launchItemSettings) - - let padding: CGFloat = 20 + func addConstraints(padding: CGFloat) { NSLayoutConstraint.activate([ launchItemOrder.topAnchor.constraint(equalTo: self.topAnchor, constant: padding), @@ -53,12 +44,42 @@ class S2HomeLauncher : UIView { } + func layoutLaunchItems() { + + launchItemOrder = S2HomeLaunchItem(text: "Order", image: "order") { + + + + } + + launchItemSubscriptions = S2HomeLaunchItem(text: "Subscriptions", image: "subscriptions") { + + + + } + + launchItemStore = S2HomeLaunchItem(text: "Store", image: "store") { + + let discoverVC = S2DiscoverVC() + let navigation = S2UINavigationController(rootViewController: discoverVC) + UIViewController.presentingViewController()?.present(navigation, animated: true, completion: nil) + + } + + launchItemSettings = S2HomeLaunchItem(text: "Settings", image: "settings") { + + } + + self.addSubviews(launchItemOrder, launchItemSubscriptions, launchItemStore, launchItemSettings) + addConstraints(padding: 20) + + } + override func layoutSubviews() { super.layoutSubviews() self.backgroundColor = S2UITheme.lightBackground - layoutLaunchItems() } diff --git a/subscribeto/subscribeto/pages/home/S2HomeTopContainer.swift b/subscribeto/subscribeto/pages/home/S2HomeTopContainer.swift deleted file mode 100644 index 0f59a08..0000000 --- a/subscribeto/subscribeto/pages/home/S2HomeTopContainer.swift +++ /dev/null @@ -1,21 +0,0 @@ -// -// ouij.swift -// subscribeto -// -// Created by Elijah Cobb on 12/07/19. -// Copyright © 2019 subscribeto. All rights reserved. -// - -import UIKit - -class S2HomeTopContainer : UIView { - - override func layoutSubviews() { - - super.layoutSubviews() - - self.backgroundColor = S2UITheme.darkBackground - - } - -} diff --git a/subscribeto/subscribeto/pages/home/S2HomeVC.swift b/subscribeto/subscribeto/pages/home/S2HomeVC.swift index 5c36518..341085b 100644 --- a/subscribeto/subscribeto/pages/home/S2HomeVC.swift +++ b/subscribeto/subscribeto/pages/home/S2HomeVC.swift @@ -11,10 +11,10 @@ import UIKit class S2HomeVC : UIViewController { // The percentage of height the bottom takes up compared to the top. - let containerRatio: CGFloat = 0.75 + let containerRatio: CGFloat = 0.6 var stackView: UIStackView! - var topContainer: S2HomeTopContainer! + var topContainer: S2HomeDashboard! var bottomContainer: S2HomeLauncher! override func loadView() { @@ -22,7 +22,7 @@ class S2HomeVC : UIViewController { super.loadView() stackView = UIStackView(frame: .zero) - topContainer = S2HomeTopContainer(frame: .zero) + topContainer = S2HomeDashboard(frame: .zero) bottomContainer = S2HomeLauncher(frame: .zero) stackView.useAutoLayout() @@ -46,9 +46,9 @@ class S2HomeVC : UIViewController { } - override func viewDidLoad() { + override var preferredStatusBarStyle: UIStatusBarStyle { - super.viewDidLoad() + return .lightContent }