Skip to content

Commit

Permalink
Programatic approcash done.
Browse files Browse the repository at this point in the history
  • Loading branch information
Elijah Cobb committed Jul 13, 2019
1 parent 8fa5850 commit 6c736f5
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 85 deletions.
55 changes: 10 additions & 45 deletions subscribeto/subscribeto/S2UI/S2UIButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -38,55 +42,16 @@ 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) }

required init?(coder: NSCoder) {
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<UITouch>, with event: UIEvent?) {

isBeingTouched(true)

}

override func touchesMoved(_ touches: Set<UITouch>, 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<UITouch>, with event: UIEvent?) {

isBeingTouched(false)

func clicked() {
onClick()
}

}
37 changes: 37 additions & 0 deletions subscribeto/subscribeto/S2UI/S2UINavigationController.swift
Original file line number Diff line number Diff line change
@@ -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)
])


}

}
10 changes: 10 additions & 0 deletions subscribeto/subscribeto/S2UI/S2UIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ extension UIView {

}

extension UIViewController {

static func presentingViewController() -> UIViewController? {

return UIApplication.shared.keyWindow?.rootViewController

}

}


class S2UIView : UIView {

Expand Down
21 changes: 21 additions & 0 deletions subscribeto/subscribeto/pages/discover/S2DiscoverVC.swift
Original file line number Diff line number Diff line change
@@ -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

}

}
70 changes: 70 additions & 0 deletions subscribeto/subscribeto/pages/home/S2HomeDashboard.swift
Original file line number Diff line number Diff line change
@@ -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)

}

}
8 changes: 5 additions & 3 deletions subscribeto/subscribeto/pages/home/S2HomeLaunchItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

}

Expand Down
43 changes: 32 additions & 11 deletions subscribeto/subscribeto/pages/home/S2HomeLauncher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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()

}
Expand Down
21 changes: 0 additions & 21 deletions subscribeto/subscribeto/pages/home/S2HomeTopContainer.swift

This file was deleted.

10 changes: 5 additions & 5 deletions subscribeto/subscribeto/pages/home/S2HomeVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ 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() {

super.loadView()

stackView = UIStackView(frame: .zero)
topContainer = S2HomeTopContainer(frame: .zero)
topContainer = S2HomeDashboard(frame: .zero)
bottomContainer = S2HomeLauncher(frame: .zero)

stackView.useAutoLayout()
Expand All @@ -46,9 +46,9 @@ class S2HomeVC : UIViewController {

}

override func viewDidLoad() {
override var preferredStatusBarStyle: UIStatusBarStyle {

super.viewDidLoad()
return .lightContent

}

Expand Down

0 comments on commit 6c736f5

Please sign in to comment.