Commit 825c260f by Daniel Dahan

development: Morged BarView and ContentView into Bar, and a base sample project

parent 5d842821
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
location = "container:" location = "container:"
name = "Programmatic"> name = "Programmatic">
<FileRef <FileRef
location = "group:Programmatic/Bar/Bar.xcodeproj">
</FileRef>
<FileRef
location = "group:Programmatic/BottomNavigationController/BottomNavigationController.xcodeproj"> location = "group:Programmatic/BottomNavigationController/BottomNavigationController.xcodeproj">
</FileRef> </FileRef>
<FileRef <FileRef
......
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:Bar.xcodeproj">
</FileRef>
</Workspace>
...@@ -29,60 +29,41 @@ ...@@ -29,60 +29,41 @@
*/ */
import UIKit import UIKit
import Material
open class BarView: ContentView { @UIApplicationMain
/// Divider layer. class AppDelegate: UIResponder, UIApplicationDelegate {
open internal(set) var divider: Divider!
/** var window: UIWindow?
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance. func applicationDidFinishLaunching(_ application: UIApplication) {
*/ window = UIWindow(frame: Device.bounds)
public required init?(coder aDecoder: NSCoder) { window!.rootViewController = ViewController()
super.init(coder: aDecoder) window!.makeKeyAndVisible()
} }
/** func applicationWillResignActive(_ application: UIApplication) {
An initializer that initializes the object with a CGRect object. // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
If AutoLayout is used, it is better to initilize the instance // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
using the init() initializer. }
- Parameter frame: A CGRect instance.
*/ func applicationDidEnterBackground(_ application: UIApplication) {
public override init(frame: CGRect) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
super.init(frame: frame) // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
/**
A convenience initializer with parameter settings.
- Parameter leftViews: An Array of UIViews that go on the left side.
- Parameter rightViews: An Array of UIViews that go on the right side.
*/
public override init(leftViews: [UIView]? = nil, rightViews: [UIView]? = nil) {
super.init(leftViews: leftViews, rightViews: rightViews)
}
open override func layoutSubviews() {
super.layoutSubviews()
guard willLayout else {
return
}
divider.reload()
} }
/** func applicationWillEnterForeground(_ application: UIApplication) {
Prepares the view instance when intialized. When subclassing, // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
it is recommended to override the prepare method
to initialize property values and other setup operations.
The super.prepare method should always be called immediately
when subclassing.
*/
open override func prepare() {
super.prepare()
prepareDivider()
} }
/// Prepares the divider. func applicationDidBecomeActive(_ application: UIApplication) {
private func prepareDivider() { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
divider = Divider(view: self)
} }
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
} }
{
"images" : [
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
import Material
class ViewController: UIViewController {
/// A reference to the Bar.
private var bar: Bar!
/// Left buttons.
private var favoriteButton: IconButton!
/// Right buttons.
private var shareButton: IconButton!
/// Title label.
private var titleLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = Color.white
prepareFavoriteButton()
prepareShareButton()
prepareTitleLabel()
prepareBar()
layoutSubviews()
}
private func prepareFavoriteButton() {
favoriteButton = IconButton(image: Icon.favorite, tintColor: Color.white)
favoriteButton.pulseColor = Color.white
}
private func prepareShareButton() {
shareButton = IconButton(image: Icon.cm.share, tintColor: Color.white)
shareButton.pulseColor = Color.white
}
private func prepareTitleLabel() {
titleLabel = UILabel()
titleLabel.text = "Title"
titleLabel.font = RobotoFont.bold(with: 17)
titleLabel.textColor = Color.white
}
private func prepareBar() {
bar = Bar()
bar.contentEdgeInsetsPreset = .square1
bar.backgroundColor = Color.blue.base
bar.leftViews = [favoriteButton]
bar.rightViews = [shareButton]
}
private func layoutSubviews() {
view.layout(bar).horizontally().center()
bar.contentView.layout(titleLabel).edges()
}
}
...@@ -36,7 +36,7 @@ public enum ContentViewAlignment: Int { ...@@ -36,7 +36,7 @@ public enum ContentViewAlignment: Int {
case center case center
} }
open class ContentView: View { open class Bar: View {
/// Should center the contentView. /// Should center the contentView.
open var contentViewAlignment = ContentViewAlignment.any { open var contentViewAlignment = ContentViewAlignment.any {
didSet { didSet {
...@@ -44,124 +44,127 @@ open class ContentView: View { ...@@ -44,124 +44,127 @@ open class ContentView: View {
} }
} }
/// Will render the view. /// Will render the view.
open var willLayout: Bool { open var willLayout: Bool {
return 0 < width && 0 < height && nil != superview return 0 < width && 0 < height && nil != superview
} }
/// A preset wrapper around contentInset. /// A preset wrapper around contentInset.
open var contentEdgeInsetsPreset: EdgeInsetsPreset { open var contentEdgeInsetsPreset: EdgeInsetsPreset {
get { get {
return grid.contentEdgeInsetsPreset return grid.contentEdgeInsetsPreset
} }
set(value) { set(value) {
grid.contentEdgeInsetsPreset = value grid.contentEdgeInsetsPreset = value
} }
} }
/// A wrapper around grid.contentInset. /// A wrapper around grid.contentInset.
@IBInspectable @IBInspectable
open var contentEdgeInsets: EdgeInsets { open var contentEdgeInsets: EdgeInsets {
get { get {
return grid.contentEdgeInsets return grid.contentEdgeInsets
} }
set(value) { set(value) {
grid.contentEdgeInsets = value grid.contentEdgeInsets = value
} }
} }
/// A preset wrapper around interimSpace. /// A preset wrapper around interimSpace.
open var interimSpacePreset = InterimSpacePreset.none { open var interimSpacePreset = InterimSpacePreset.none {
didSet { didSet {
interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset) interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset)
} }
} }
/// A wrapper around grid.interimSpace. /// A wrapper around grid.interimSpace.
@IBInspectable @IBInspectable
open var interimSpace: InterimSpace { open var interimSpace: InterimSpace {
get { get {
return grid.interimSpace return grid.interimSpace
} }
set(value) { set(value) {
grid.interimSpace = value grid.interimSpace = value
} }
} }
open override var intrinsicContentSize: CGSize { open override var intrinsicContentSize: CGSize {
return CGSize(width: width, height: 44) return CGSize(width: width, height: 44)
} }
/// Grid cell factor. /// Grid cell factor.
@IBInspectable @IBInspectable
open var gridFactor: CGFloat = 24 { open var gridFactor: CGFloat = 24 {
didSet { didSet {
assert(0 < gridFactor, "[Material Error: gridFactor must be greater than 0.]") assert(0 < gridFactor, "[Material Error: gridFactor must be greater than 0.]")
layoutSubviews() layoutSubviews()
} }
} }
/// ContentView that holds the any desired subviews. /// Divider layer.
open private(set) lazy var contentView = View() open internal(set) var divider: Divider!
/// Left side UIViews. /// ContentView that holds the any desired subviews.
open var leftViews = [UIView]() { open private(set) lazy var contentView = View()
didSet {
/// Left side UIViews.
open var leftViews = [UIView]() {
didSet {
for v in oldValue { for v in oldValue {
v.removeFromSuperview() v.removeFromSuperview()
} }
layoutSubviews() layoutSubviews()
} }
} }
/// Right side UIViews. /// Right side UIViews.
open var rightViews = [UIView]() { open var rightViews = [UIView]() {
didSet { didSet {
for v in oldValue { for v in oldValue {
v.removeFromSuperview() v.removeFromSuperview()
} }
layoutSubviews() layoutSubviews()
} }
} }
/** /**
An initializer that initializes the object with a NSCoder object. An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance. - Parameter aDecoder: A NSCoder instance.
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
} }
/** /**
An initializer that initializes the object with a CGRect object. An initializer that initializes the object with a CGRect object.
If AutoLayout is used, it is better to initilize the instance If AutoLayout is used, it is better to initilize the instance
using the init() initializer. using the init() initializer.
- Parameter frame: A CGRect instance. - Parameter frame: A CGRect instance.
*/ */
public override init(frame: CGRect) { public override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
} }
/// Basic initializer. /// Basic initializer.
public init() { public init() {
super.init(frame: .zero) super.init(frame: .zero)
frame.size = intrinsicContentSize frame.size = intrinsicContentSize
} }
/** /**
A convenience initializer with parameter settings. A convenience initializer with parameter settings.
- Parameter leftViews: An Array of UIViews that go on the left side. - Parameter leftViews: An Array of UIViews that go on the left side.
- Parameter rightViews: An Array of UIViews that go on the right side. - Parameter rightViews: An Array of UIViews that go on the right side.
*/ */
public init(leftViews: [UIView]? = nil, rightViews: [UIView]? = nil) { public init(leftViews: [UIView]? = nil, rightViews: [UIView]? = nil) {
self.leftViews = leftViews ?? [] self.leftViews = leftViews ?? []
self.rightViews = rightViews ?? [] self.rightViews = rightViews ?? []
super.init(frame: .zero) super.init(frame: .zero)
frame.size = intrinsicContentSize frame.size = intrinsicContentSize
} }
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
guard willLayout else { guard willLayout else {
return return
} }
...@@ -216,22 +219,30 @@ open class ContentView: View { ...@@ -216,22 +219,30 @@ open class ContentView: View {
grid.commit() grid.commit()
contentView.grid.commit() contentView.grid.commit()
divider.reload()
} }
/** /**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepare method it is recommended to override the prepare method
to initialize property values and other setup operations. to initialize property values and other setup operations.
The super.prepare method should always be called immediately The super.prepare method should always be called immediately
when subclassing. when subclassing.
*/ */
open override func prepare() { open override func prepare() {
super.prepare() super.prepare()
prepareContentView() prepareContentView()
} prepareDivider()
}
/// Prepares the contentView.
private func prepareContentView() { /// Prepares the contentView.
contentView.backgroundColor = nil private func prepareContentView() {
} contentView.backgroundColor = nil
}
/// Prepares the divider.
private func prepareDivider() {
divider = Divider(view: self)
}
} }
...@@ -90,7 +90,7 @@ open class ContentCard: PulseView { ...@@ -90,7 +90,7 @@ open class ContentCard: PulseView {
} }
/// A reference to the bottomBar. /// A reference to the bottomBar.
open var bottomBar: BarView? { open var bottomBar: Bar? {
didSet { didSet {
layoutSubviews() layoutSubviews()
} }
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
import UIKit import UIKit
open class SearchBar: BarView { open class SearchBar: Bar {
/// The UITextField for the searchBar. /// The UITextField for the searchBar.
open private(set) lazy var textField = UITextField() open private(set) lazy var textField = UITextField()
......
...@@ -36,7 +36,7 @@ public enum SnackbarStatus: Int { ...@@ -36,7 +36,7 @@ public enum SnackbarStatus: Int {
case hidden case hidden
} }
open class Snackbar: BarView { open class Snackbar: Bar {
/// A convenience property to set the titleLabel text. /// A convenience property to set the titleLabel text.
open var text: String? { open var text: String? {
get { get {
......
...@@ -49,8 +49,8 @@ extension UIViewController { ...@@ -49,8 +49,8 @@ extension UIViewController {
} }
open class StatusBarController: RootController { open class StatusBarController: RootController {
/// A reference to the statusBarView. /// A reference to the statusBar.
open private(set) lazy var statusBarView = View() open private(set) lazy var statusBar = View()
/** /**
To execute in the order of the layout chain, override this To execute in the order of the layout chain, override this
...@@ -59,7 +59,7 @@ open class StatusBarController: RootController { ...@@ -59,7 +59,7 @@ open class StatusBarController: RootController {
*/ */
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
statusBarView.isHidden = Device.isLandscape && .phone == Device.userInterfaceIdiom statusBar.isHidden = Device.isLandscape && .phone == Device.userInterfaceIdiom
rootViewController.view.frame = view.bounds rootViewController.view.frame = view.bounds
} }
...@@ -72,13 +72,13 @@ open class StatusBarController: RootController { ...@@ -72,13 +72,13 @@ open class StatusBarController: RootController {
*/ */
open override func prepare() { open override func prepare() {
super.prepare() super.prepare()
prepareStatusBarView() prepareStatusBar()
} }
/// Prepares the statusBarView. /// Prepares the statusBar.
private func prepareStatusBarView() { private func prepareStatusBar() {
statusBarView.zPosition = 3000 statusBar.zPosition = 3000
statusBarView.backgroundColor = Color.black.withAlphaComponent(0.12) statusBar.backgroundColor = Color.black.withAlphaComponent(0.12)
view.layout(statusBarView).top(0).horizontally().height(20) view.layout(statusBar).top().horizontally().height(20)
} }
} }
...@@ -57,7 +57,7 @@ public protocol TabBarDelegate { ...@@ -57,7 +57,7 @@ public protocol TabBarDelegate {
optional func tabBarDidSelectButton(tabBar: TabBar, button: UIButton) optional func tabBarDidSelectButton(tabBar: TabBar, button: UIButton)
} }
open class TabBar: BarView { open class TabBar: Bar {
/// A boolean indicating if the TabBar line is in an animation state. /// A boolean indicating if the TabBar line is in an animation state.
open internal(set) var isAnimating = false open internal(set) var isAnimating = false
......
...@@ -32,7 +32,7 @@ import UIKit ...@@ -32,7 +32,7 @@ import UIKit
private var ToolbarContext: UInt8 = 0 private var ToolbarContext: UInt8 = 0
open class Toolbar: BarView { open class Toolbar: Bar {
/// A convenience property to set the titleLabel text. /// A convenience property to set the titleLabel text.
open var title: String? { open var title: String? {
get { get {
......
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