Commit 56d71fc4 by Daniel Dahan

added initial classes

parent e7086014
......@@ -13,6 +13,8 @@
657CD02F1B8EE0D3008C0029 /* ImageCardView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9A94D10A1B8A485C00F586A5 /* ImageCardView.swift */; settings = {ATTRIBUTES = (Public, ); }; };
65B9657E1B8A7C330055B139 /* MaterialButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65B9657D1B8A7C330055B139 /* MaterialButton.swift */; };
65B965871B8BEEC60055B139 /* SideNavigationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65B965861B8BEEC60055B139 /* SideNavigationViewController.swift */; };
65BDD1451BB5B8B8006F7F2B /* MaterialTheme+View.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BDD1441BB5B8B8006F7F2B /* MaterialTheme+View.swift */; settings = {ASSET_TAGS = (); }; };
65BDD1471BB5B916006F7F2B /* MaterialView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BDD1461BB5B916006F7F2B /* MaterialView.swift */; settings = {ASSET_TAGS = (); }; };
65DBE4201B9A9244000C804F /* Roboto-Bold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 65DBE41E1B9A9244000C804F /* Roboto-Bold.ttf */; };
65DBE4211B9A9244000C804F /* Roboto-Thin.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 65DBE41F1B9A9244000C804F /* Roboto-Thin.ttf */; };
962F3E531BACA68C0004B8AD /* NavigationBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 962F3E521BACA68C0004B8AD /* NavigationBarView.swift */; };
......@@ -64,6 +66,8 @@
/* Begin PBXFileReference section */
65B9657D1B8A7C330055B139 /* MaterialButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialButton.swift; sourceTree = "<group>"; };
65B965861B8BEEC60055B139 /* SideNavigationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SideNavigationViewController.swift; sourceTree = "<group>"; };
65BDD1441BB5B8B8006F7F2B /* MaterialTheme+View.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "MaterialTheme+View.swift"; sourceTree = "<group>"; };
65BDD1461BB5B916006F7F2B /* MaterialView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialView.swift; sourceTree = "<group>"; };
65DBE41E1B9A9244000C804F /* Roboto-Bold.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Bold.ttf"; sourceTree = "<group>"; };
65DBE41F1B9A9244000C804F /* Roboto-Thin.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Thin.ttf"; sourceTree = "<group>"; };
962F3E521BACA68C0004B8AD /* NavigationBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationBarView.swift; sourceTree = "<group>"; };
......@@ -111,13 +115,14 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
65B965851B8BEEB00055B139 /* Navigation */ = {
65B965851B8BEEB00055B139 /* View */ = {
isa = PBXGroup;
children = (
65B965861B8BEEC60055B139 /* SideNavigationViewController.swift */,
65BDD1461BB5B916006F7F2B /* MaterialView.swift */,
962F3E521BACA68C0004B8AD /* NavigationBarView.swift */,
65B965861B8BEEC60055B139 /* SideNavigationViewController.swift */,
);
name = Navigation;
name = View;
sourceTree = "<group>";
};
9638322C1B88DFD80015F710 = {
......@@ -146,7 +151,7 @@
96B57D4C1B90AF6A00DE7BBB /* Theme */,
9AAC38521B89553800FE6B2D /* Font */,
963832861B8907FE0015F710 /* Layout */,
65B965851B8BEEB00055B139 /* Navigation */,
65B965851B8BEEB00055B139 /* View */,
963832761B88E8990015F710 /* Text */,
963832751B88E87B0015F710 /* Button */,
9AAC384B1B89524E00FE6B2D /* Card */,
......@@ -222,6 +227,7 @@
isa = PBXGroup;
children = (
96B57D4D1B90AF7D00DE7BBB /* MaterialTheme.swift */,
65BDD1441BB5B8B8006F7F2B /* MaterialTheme+View.swift */,
);
name = Theme;
sourceTree = "<group>";
......@@ -381,12 +387,14 @@
buildActionMask = 2147483647;
files = (
963832691B88E5BF0015F710 /* Capture.swift in Sources */,
65BDD1471BB5B916006F7F2B /* MaterialView.swift in Sources */,
9A94D10B1B8A485C00F586A5 /* ImageCardView.swift in Sources */,
96B57D4E1B90AF7D00DE7BBB /* MaterialTheme.swift in Sources */,
962F3E531BACA68C0004B8AD /* NavigationBarView.swift in Sources */,
9638326B1B88E5BF0015F710 /* FabButton.swift in Sources */,
9A94D1091B8A3F5100F586A5 /* MaterialCardView.swift in Sources */,
65B965871B8BEEC60055B139 /* SideNavigationViewController.swift in Sources */,
65BDD1451BB5B8B8006F7F2B /* MaterialTheme+View.swift in Sources */,
9638326C1B88E5BF0015F710 /* FlatButton.swift in Sources */,
963832711B88E5BF0015F710 /* MaterialText.swift in Sources */,
9638326A1B88E5BF0015F710 /* CapturePreview.swift in Sources */,
......
//
// Copyright (C) 2015 GraphKit, Inc. <http://graphkit.io> and other GraphKit contributors.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program located at the root of the software package
// in a file called LICENSE. If not, see <http://www.gnu.org/licenses/>.
//
import UIKit
// MaterialTheme
public extension MaterialTheme {
public struct view {}
public struct navigation {}
}
// view
public extension MaterialTheme.view {
// frame
public static var x: CGFloat = 0
public static let y: CGFloat = 0
public static let width: CGFloat = UIScreen.mainScreen().bounds.width
public static let height: CGFloat = UIScreen.mainScreen().bounds.height
// layer
public static let shadowColor: UIColor = MaterialTheme.blueGrey.darken4
public static let shadowOffset: CGSize = CGSizeMake(0.2, 0.2)
public static let shadowOpacity: Float = 0.5
public static let shadowRadius: CGFloat = 1
public static let contentScale: CGFloat = UIScreen.mainScreen().scale
public static let masksToBounds: Bool = false
// color
public static let backgroudColor: UIColor = MaterialTheme.white.color
// interaction
public static let userInteractionEnabled: Bool = true
// image
public static let imageGravity: String = kCAGravityCenter
}
// navigation
public extension MaterialTheme.navigation {
// frame
public static let x: CGFloat = MaterialTheme.view.x
public static let y: CGFloat = MaterialTheme.view.y
public static let width: CGFloat = MaterialTheme.view.width
public static let height: CGFloat = 70
// layer
public static let shadowColor: UIColor = MaterialTheme.view.shadowColor
public static let shadowOffset: CGSize = MaterialTheme.view.shadowOffset
public static let shadowOpacity: Float = MaterialTheme.view.shadowOpacity
public static let shadowRadius: CGFloat = MaterialTheme.view.shadowRadius
public static let contentScale: CGFloat = MaterialTheme.view.contentScale
public static let masksToBounds: Bool = MaterialTheme.view.masksToBounds
// color
public static let backgroudColor: UIColor = MaterialTheme.blue.accent2
public static let lightContentStatusBar: Bool = true
// interaction
public static let userInteractionEnabled: Bool = false
// image
public static let imageGravity: String = MaterialTheme.view.imageGravity
}
//
// Copyright (C) 2015 GraphKit, Inc. <http://graphkit.io> and other GraphKit contributors.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program located at the root of the software package
// in a file called LICENSE. If not, see <http://www.gnu.org/licenses/>.
//
import UIKit
public class MaterialView: UIView {
/**
:name: image
*/
public var image: UIImage? {
didSet {
layer.contents = image?.CGImage
}
}
/**
:name: imageGravity
*/
public var imageGravity: String? {
didSet {
layer.contentsGravity = nil == imageGravity ? MaterialTheme.navigation.imageGravity : imageGravity!
}
}
/**
:name: backgroundColor
*/
public override var backgroundColor: UIColor? {
get {
return nil == layer.backgroundColor ? nil : UIColor(CGColor: layer.backgroundColor!)
}
set(value) {
layer.backgroundColor = value?.CGColor
}
}
/**
:name: x
*/
public var x: CGFloat! {
didSet {
layer.bounds.origin.x = x
}
}
/**
:name: y
*/
public var y: CGFloat! {
didSet {
layer.bounds.origin = CGPointMake(x, y)
}
}
/**
:name: width
*/
public var width: CGFloat! {
didSet {
layer.bounds.size.width = width
}
}
/**
:name: height
*/
public var height: CGFloat! {
didSet {
layer.bounds.size.height = height
}
}
/**
:name: shadowColor
*/
public var shadowColor: UIColor! {
didSet {
layer.shadowColor = shadowColor.CGColor
}
}
/**
:name: shadowOffset
*/
public var shadowOffset: CGSize! {
didSet {
layer.shadowOffset = shadowOffset
}
}
/**
:name: shadowOpacity
*/
public var shadowOpacity: Float! {
didSet {
layer.shadowOpacity = shadowOpacity
}
}
/**
:name: shadowRadius
*/
public var shadowRadius: CGFloat! {
didSet {
layer.shadowRadius = shadowRadius
}
}
/**
:name: masksToBounds
*/
public var masksToBounds: Bool! {
didSet {
layer.masksToBounds = masksToBounds
}
}
/**
:name: init
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
/**
:name: init
*/
public override init(frame: CGRect) {
super.init(frame: frame)
}
/**
:name: init
*/
public convenience init() {
self.init(frame: CGRectMake(MaterialTheme.view.x, MaterialTheme.view.y, MaterialTheme.view.width, MaterialTheme.view.height))
prepareView()
prepareFrame()
prepareLayer()
}
/**
:name: prepareView
*/
internal func prepareView() {
userInteractionEnabled = MaterialTheme.view.userInteractionEnabled
backgroundColor = MaterialTheme.view.backgroudColor
}
/**
:name: prepareFrame
*/
internal func prepareFrame() {
x = frame.origin.x
y = frame.origin.y
width = frame.size.width
height = frame.size.height
}
/**
:name: prepareLayer
*/
internal func prepareLayer() {
layer.contentsScale = MaterialTheme.view.contentScale
shadowColor = MaterialTheme.view.shadowColor
shadowOffset = MaterialTheme.view.shadowOffset
shadowOpacity = MaterialTheme.view.shadowOpacity
shadowRadius = MaterialTheme.view.shadowRadius
masksToBounds = MaterialTheme.view.masksToBounds
}
}
......@@ -18,254 +18,44 @@
import UIKit
public class NavigationBarView: UIView {
//
// :name: layoutConstraints
//
internal lazy var layoutConstraints: Array<NSLayoutConstraint> = Array<NSLayoutConstraint>()
//
// :name: lightContentStatusBar
//
public var lightContentStatusBar: Bool = false {
didSet {
UIApplication.sharedApplication().setStatusBarStyle(lightContentStatusBar ? .LightContent : .Default, animated: true)
}
}
//
// :name: horizontalInset
//
public var horizontalInset: CGFloat = MaterialTheme.cardHorizontalInset / 2 {
didSet {
reloadView()
}
}
/**
:name: titleLabelContainer
*/
public private(set) var titleLabelContainer: UIView?
/**
:name: titleLabel
*/
public var titleLabel: UILabel? {
didSet {
if let t = titleLabel {
// container
if nil == titleLabelContainer {
titleLabelContainer = UIView()
titleLabelContainer!.translatesAutoresizingMaskIntoConstraints = false
titleLabelContainer!.backgroundColor = MaterialTheme.clear.color
addSubview(titleLabelContainer!)
}
// text
titleLabelContainer!.addSubview(t)
t.translatesAutoresizingMaskIntoConstraints = false
t.backgroundColor = MaterialTheme.clear.color
t.font = Roboto.regular
t.numberOfLines = 1
t.lineBreakMode = .ByTruncatingTail
t.textColor = MaterialTheme.white.color
} else {
titleLabelContainer?.removeFromSuperview()
titleLabelContainer = nil
}
reloadView()
}
}
/**
:name: leftButtonsContainer
*/
public private(set) var leftButtonsContainer: UIView?
/**
:name: leftButtons
*/
public var leftButtons: Array<MaterialButton>? {
didSet {
if nil == leftButtons {
leftButtonsContainer?.removeFromSuperview()
leftButtonsContainer = nil
} else if nil == leftButtonsContainer {
leftButtonsContainer = UIView()
leftButtonsContainer!.translatesAutoresizingMaskIntoConstraints = false
leftButtonsContainer!.backgroundColor = MaterialTheme.clear.color
addSubview(leftButtonsContainer!)
} else {
for v in leftButtonsContainer!.subviews {
v.removeFromSuperview()
}
}
reloadView()
}
}
/**
:name: rightButtonsContainer
*/
public private(set) var rightButtonsContainer: UIView?
public class NavigationBarView: MaterialView {
/**
:name: rightButtons
:name: lightContentStatusBar
*/
public var rightButtons: Array<MaterialButton>? {
public var lightContentStatusBar: Bool = MaterialTheme.navigation.lightContentStatusBar {
didSet {
if nil == rightButtons {
rightButtonsContainer?.removeFromSuperview()
rightButtonsContainer = nil
} else if nil == rightButtonsContainer {
rightButtonsContainer = UIView()
rightButtonsContainer!.translatesAutoresizingMaskIntoConstraints = false
rightButtonsContainer!.backgroundColor = MaterialTheme.clear.color
addSubview(rightButtonsContainer!)
} else {
for v in rightButtonsContainer!.subviews {
v.removeFromSuperview()
}
}
reloadView()
UIApplication.sharedApplication().setStatusBarStyle(lightContentStatusBar ? .LightContent : .Default, animated: true)
}
}
/**
:name: init
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
/**
:name: init
*/
public override init(frame: CGRect) {
super.init(frame: frame)
prepareView()
}
/**
:name: init
*/
public convenience init() {
self.init(frame: CGRect.null)
self.init(frame: CGRectMake(MaterialTheme.navigation.x, MaterialTheme.navigation.y, MaterialTheme.navigation.width, MaterialTheme.navigation.height))
prepareView()
prepareFrame()
prepareLayer()
}
/**
:name: init
:name: prepareView
*/
public convenience init?(titleLabel: UILabel? = nil, leftButtons: Array<MaterialButton>? = nil, rightButtons: Array<MaterialButton>? = nil) {
self.init(frame: CGRect.null)
prepareProperties(titleLabel, leftButtons: leftButtons, rightButtons: rightButtons)
internal override func prepareView() {
userInteractionEnabled = MaterialTheme.navigation.userInteractionEnabled
backgroundColor = MaterialTheme.navigation.backgroudColor
lightContentStatusBar = MaterialTheme.navigation.lightContentStatusBar
}
/**
:name: reloadView
:name: prepareLayer
*/
public func reloadView() {
// clear all constraints
NSLayoutConstraint.deactivateConstraints(layoutConstraints)
layoutConstraints.removeAll(keepCapacity: false)
// detect all components and create constraints
var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
// left buttons
if nil != leftButtons {
// clear for updated constraints
leftButtonsContainer!.removeConstraints(leftButtonsContainer!.constraints)
//container
views["leftButtonsContainer"] = leftButtonsContainer!
// leftButtons
var hFormat: String = "H:|"
var buttonViews: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
for var i: Int = 0, l: Int = leftButtons!.count; i < l; ++i {
let button: MaterialButton = leftButtons![i]
leftButtonsContainer!.addSubview(button)
buttonViews["button\(i)"] = button
hFormat += "-(horizontalInset)-[button\(i)]"
Layout.expandToParentVerticallyWithPad(leftButtonsContainer!, child: button)
}
leftButtonsContainer!.addConstraints(Layout.constraint(hFormat + "|", options: [], metrics: ["horizontalInset": horizontalInset], views: buttonViews))
}
// title
if nil != titleLabel {
// clear for updated constraints
titleLabelContainer!.removeConstraints(titleLabelContainer!.constraints)
// container
views["titleLabelContainer"] = titleLabelContainer!
// common text
Layout.expandToParentVerticallyWithPad(titleLabelContainer!, child: titleLabel!)
Layout.expandToParentHorizontallyWithPad(titleLabelContainer!, child: titleLabel!)
}
// right buttons
if nil != rightButtons {
// clear for updated constraints
rightButtonsContainer!.removeConstraints(rightButtonsContainer!.constraints)
//container
views["rightButtonsContainer"] = rightButtonsContainer!
// leftButtons
var hFormat: String = "H:|"
var buttonViews: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
for var i: Int = 0, l: Int = rightButtons!.count; i < l; ++i {
let button: MaterialButton = rightButtons![i]
rightButtonsContainer!.addSubview(button)
buttonViews["button\(i)"] = button
hFormat += "[button\(i)]-(horizontalInset)-"
Layout.expandToParentVerticallyWithPad(rightButtonsContainer!, child: button)
}
rightButtonsContainer!.addConstraints(Layout.constraint(hFormat + "|", options: [], metrics: ["horizontalInset": horizontalInset], views: buttonViews))
}
if nil != leftButtons && nil != titleLabel {
layoutConstraints += Layout.constraint("H:|[leftButtonsContainer]-(inset)-[titleLabelContainer]", options: [], metrics: ["inset": horizontalInset], views: ["leftButtonsContainer": leftButtonsContainer!, "titleLabelContainer": titleLabelContainer!])
Layout.alignFromBottom(self, child: leftButtonsContainer!, bottom: horizontalInset)
Layout.alignFromBottom(self, child: titleLabelContainer!, bottom: horizontalInset + MaterialTheme.buttonVerticalInset - 1)
} else if nil != leftButtons {
layoutConstraints += Layout.constraint("H:|[leftButtonsContainer]", options: [], metrics: ["inset": horizontalInset], views: ["leftButtonsContainer": leftButtonsContainer!])
Layout.alignFromBottom(self, child: leftButtonsContainer!, bottom: horizontalInset)
} else if nil != titleLabel {
layoutConstraints += Layout.constraint("H:|-(inset)-[titleLabelContainer]", options: [], metrics: ["inset": horizontalInset], views: ["titleLabelContainer": titleLabelContainer!])
Layout.alignFromBottom(self, child: titleLabelContainer!, bottom: horizontalInset + MaterialTheme.buttonVerticalInset - 1)
}
if nil != rightButtons {
layoutConstraints += Layout.constraint("H:[rightButtonsContainer]|", options: [], metrics: ["inset": horizontalInset], views: ["rightButtonsContainer": rightButtonsContainer!])
Layout.alignFromBottom(self, child: rightButtonsContainer!, bottom: horizontalInset)
}
// constraints
NSLayoutConstraint.activateConstraints(layoutConstraints)
}
//
// :name: prepareProperties
//
internal func prepareProperties(titleLabel: UILabel?, leftButtons: Array<MaterialButton>?, rightButtons: Array<MaterialButton>?) {
self.titleLabel = titleLabel
self.leftButtons = leftButtons
self.rightButtons = rightButtons
}
//
// :name: prepareView
//
private func prepareView() {
translatesAutoresizingMaskIntoConstraints = false
layer.shadowColor = MaterialTheme.blueGrey.darken4.CGColor
layer.shadowOffset = CGSizeMake(0.2, 0.2)
layer.shadowOpacity = 0.5
layer.shadowRadius = 1
clipsToBounds = false
internal override func prepareLayer() {
layer.contentsScale = MaterialTheme.navigation.contentScale
shadowColor = MaterialTheme.navigation.shadowColor
shadowOffset = MaterialTheme.navigation.shadowOffset
shadowOpacity = MaterialTheme.navigation.shadowOpacity
shadowRadius = MaterialTheme.navigation.shadowRadius
masksToBounds = MaterialTheme.navigation.masksToBounds
}
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment