Commit 93842963 by Daniel Dahan

development: addition of TabBarController with RootController

parent b009452c
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
963832421B88DFD80015F710 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 963832361B88DFD80015F710 /* Material.framework */; }; 963832421B88DFD80015F710 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 963832361B88DFD80015F710 /* Material.framework */; };
963FBEFD1D669510008F8512 /* Snackbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963FBEFC1D669510008F8512 /* Snackbar.swift */; }; 963FBEFD1D669510008F8512 /* Snackbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963FBEFC1D669510008F8512 /* Snackbar.swift */; };
963FBF051D669713008F8512 /* PageController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963FBF041D669713008F8512 /* PageController.swift */; }; 963FBF051D669713008F8512 /* PageController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963FBF041D669713008F8512 /* PageController.swift */; };
963FBF081D669D14008F8512 /* TabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963FBF071D669D14008F8512 /* TabBarController.swift */; };
9658F2171CD6FA4700B902C1 /* IconButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9658F2161CD6FA4700B902C1 /* IconButton.swift */; }; 9658F2171CD6FA4700B902C1 /* IconButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9658F2161CD6FA4700B902C1 /* IconButton.swift */; };
9660161D1CB2ED6C00AAB661 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 966016131CB2ED6C00AAB661 /* Material.framework */; }; 9660161D1CB2ED6C00AAB661 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 966016131CB2ED6C00AAB661 /* Material.framework */; };
9660162A1CB2F04E00AAB661 /* Material.h in Headers */ = {isa = PBXBuildFile; fileRef = 96D88C091C1328D800B91418 /* Material.h */; settings = {ATTRIBUTES = (Public, ); }; }; 9660162A1CB2F04E00AAB661 /* Material.h in Headers */ = {isa = PBXBuildFile; fileRef = 96D88C091C1328D800B91418 /* Material.h */; settings = {ATTRIBUTES = (Public, ); }; };
...@@ -210,6 +211,7 @@ ...@@ -210,6 +211,7 @@
963832591B88E31A0015F710 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 963832591B88E31A0015F710 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
963FBEFC1D669510008F8512 /* Snackbar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Snackbar.swift; sourceTree = "<group>"; }; 963FBEFC1D669510008F8512 /* Snackbar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Snackbar.swift; sourceTree = "<group>"; };
963FBF041D669713008F8512 /* PageController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PageController.swift; sourceTree = "<group>"; }; 963FBF041D669713008F8512 /* PageController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PageController.swift; sourceTree = "<group>"; };
963FBF071D669D14008F8512 /* TabBarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabBarController.swift; sourceTree = "<group>"; };
9658F2161CD6FA4700B902C1 /* IconButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IconButton.swift; sourceTree = "<group>"; }; 9658F2161CD6FA4700B902C1 /* IconButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IconButton.swift; sourceTree = "<group>"; };
966016131CB2ED6C00AAB661 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Material.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 966016131CB2ED6C00AAB661 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Material.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9660161C1CB2ED6C00AAB661 /* Material macOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Material macOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 9660161C1CB2ED6C00AAB661 /* Material macOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Material macOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
...@@ -400,6 +402,7 @@ ...@@ -400,6 +402,7 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
96BCB79A1CB40DC500C806FE /* TabBar.swift */, 96BCB79A1CB40DC500C806FE /* TabBar.swift */,
963FBF071D669D14008F8512 /* TabBarController.swift */,
963FBF041D669713008F8512 /* PageController.swift */, 963FBF041D669713008F8512 /* PageController.swift */,
); );
name = TabBar; name = TabBar;
...@@ -1052,6 +1055,7 @@ ...@@ -1052,6 +1055,7 @@
962864621D54111D00690B69 /* JSON.swift in Sources */, 962864621D54111D00690B69 /* JSON.swift in Sources */,
96BCB7C21CB40DC500C806FE /* Device.swift in Sources */, 96BCB7C21CB40DC500C806FE /* Device.swift in Sources */,
96BCB7A41CB40DC500C806FE /* CaptureSession.swift in Sources */, 96BCB7A41CB40DC500C806FE /* CaptureSession.swift in Sources */,
963FBF081D669D14008F8512 /* TabBarController.swift in Sources */,
963FBEFD1D669510008F8512 /* Snackbar.swift in Sources */, 963FBEFD1D669510008F8512 /* Snackbar.swift in Sources */,
96BCB7C51CB40DC500C806FE /* MaterialGravity.swift in Sources */, 96BCB7C51CB40DC500C806FE /* MaterialGravity.swift in Sources */,
968C99471D377849000074FF /* Offset.swift in Sources */, 968C99471D377849000074FF /* Offset.swift in Sources */,
......
...@@ -47,7 +47,8 @@ open class ControlView: View { ...@@ -47,7 +47,8 @@ open class ControlView: View {
} }
/// A wrapper around grid.contentInset. /// A wrapper around grid.contentInset.
@IBInspectable open var contentInset: EdgeInsets { @IBInspectable
open var contentInset: EdgeInsets {
get { get {
return grid.contentEdgeInsets return grid.contentEdgeInsets
} }
...@@ -64,7 +65,8 @@ open class ControlView: View { ...@@ -64,7 +65,8 @@ open class ControlView: View {
} }
/// A wrapper around grid.interimSpace. /// A wrapper around grid.interimSpace.
@IBInspectable open var interimSpace: InterimSpace { @IBInspectable
open var interimSpace: InterimSpace {
get { get {
return grid.interimSpace return grid.interimSpace
} }
...@@ -222,7 +224,6 @@ open class ControlView: View { ...@@ -222,7 +224,6 @@ open class ControlView: View {
interimSpacePreset = .interimSpace1 interimSpacePreset = .interimSpace1
contentEdgeInsetsPreset = .square1 contentEdgeInsetsPreset = .square1
autoresizingMask = .flexibleWidth autoresizingMask = .flexibleWidth
isShadowPathAutoSizing = false
prepareContentView() prepareContentView()
} }
......
...@@ -38,9 +38,7 @@ open class PageController: UIPageViewController { ...@@ -38,9 +38,7 @@ open class PageController: UIPageViewController {
The super.prepareView method should always be called immediately The super.prepareView method should always be called immediately
when subclassing. when subclassing.
*/ */
open override func prepareView() { open func prepareView() {
autoresizingMask = .flexibleWidth
contentScaleFactor = Device.scale
prepareLine()
} }
} }
...@@ -50,43 +50,45 @@ extension UIViewController { ...@@ -50,43 +50,45 @@ extension UIViewController {
open class SearchBarController: RootController { open class SearchBarController: RootController {
/// Reference to the SearchBar. /// Reference to the SearchBar.
open private(set) var searchBar: SearchBar! open internal(set) var searchBar: SearchBar!
/** /**
To execute in the order of the layout chain, override this To execute in the order of the layout chain, override this
method. LayoutSubviews should be called immediately, unless you method. LayoutSubviews should be called immediately, unless you
have a certain need. have a certain need.
*/ */
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if let v: SearchBar = searchBar { guard let v = searchBar else {
v.grid.layoutEdgeInsets.top = .phone == Device.userInterfaceIdiom && Device.isLandscape ? 0 : 20 return
}
let h: CGFloat = Device.height
let w: CGFloat = Device.width v.grid.layoutEdgeInsets.top = .phone == Device.userInterfaceIdiom && Device.isLandscape ? 0 : 20
let p: CGFloat = v.intrinsicContentSize.height + v.grid.layoutEdgeInsets.top + v.grid.layoutEdgeInsets.bottom
let h = Device.height
v.width = w + v.grid.layoutEdgeInsets.left + v.grid.layoutEdgeInsets.right let w = Device.width
v.height = p let p = v.intrinsicContentSize.height + v.grid.layoutEdgeInsets.top + v.grid.layoutEdgeInsets.bottom
rootViewController.view.frame.origin.y = p v.width = w + v.grid.layoutEdgeInsets.left + v.grid.layoutEdgeInsets.right
rootViewController.view.frame.size.height = h - p v.height = p
}
rootViewController.view.frame.origin.y = p
rootViewController.view.frame.size.height = h - p
} }
/** /**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method it is recommended to override the prepareView method
to initialize property values and other setup operations. to initialize property values and other setup operations.
The super.prepareView method should always be called immediately The super.prepareView method should always be called immediately
when subclassing. when subclassing.
*/ */
open override func prepareView() { open override func prepareView() {
super.prepareView() super.prepareView()
prepareSearchBar() prepareSearchBar()
} }
/// Prepares the SearchBar. /// Prepares the searchBar.
private func prepareSearchBar() { private func prepareSearchBar() {
if nil == searchBar { if nil == searchBar {
searchBar = SearchBar() searchBar = SearchBar()
......
...@@ -51,7 +51,50 @@ open class TabBar: View { ...@@ -51,7 +51,50 @@ open class TabBar: View {
open var willRenderView: Bool { open var willRenderView: Bool {
return 0 < width && 0 < height && nil != superview return 0 < width && 0 < height && nil != superview
} }
/// A preset wrapper around contentInset.
open var contentEdgeInsetsPreset: EdgeInsetsPreset {
get {
return grid.contentEdgeInsetsPreset
}
set(value) {
grid.contentEdgeInsetsPreset = value
}
}
/// A wrapper around grid.contentInset.
@IBInspectable
open var contentInset: EdgeInsets {
get {
return grid.contentEdgeInsets
}
set(value) {
grid.contentEdgeInsets = value
}
}
/// A preset wrapper around interimSpace.
open var interimSpacePreset: InterimSpacePreset = .none {
didSet {
interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset)
}
}
/// A wrapper around grid.interimSpace.
@IBInspectable
open var interimSpace: InterimSpace {
get {
return grid.interimSpace
}
set(value) {
grid.interimSpace = value
}
}
open override var intrinsicContentSize: CGSize {
return CGSize(width: width, height: 44)
}
/// Buttons. /// Buttons.
open var buttons: [UIButton]? { open var buttons: [UIButton]? {
didSet { didSet {
...@@ -110,9 +153,10 @@ open class TabBar: View { ...@@ -110,9 +153,10 @@ open class TabBar: View {
*/ */
open override func prepareView() { open override func prepareView() {
super.prepareView() super.prepareView()
autoresizingMask = .flexibleWidth interimSpacePreset = .interimSpace1
contentScaleFactor = Device.scale contentEdgeInsetsPreset = .square1
prepareLine() autoresizingMask = .flexibleWidth
prepareLine()
} }
// Prepares the line. // Prepares the line.
......
/*
* 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
//extension UIViewController {
// /**
// A convenience property that provides access to the TabBarController.
// This is the recommended method of accessing the TabBarController
// through child UIViewControllers.
// */
// public var tabBarController: TabBarController? {
// var viewController: UIViewController? = self
// while nil != viewController {
// if viewController is TabBarController {
// return viewController as? TabBarController
// }
// viewController = viewController?.parent
// }
// return nil
// }
//}
@objc(TabBarControllerDelegate)
public protocol TabBarControllerDelegate: MaterialDelegate {
}
@objc(TabBarController)
open class TabBarController: RootController {
/// Reference to the TabBar.
open internal(set) var tabBar: TabBar!
/// Delegation handler.
public weak var delegate: TabBarControllerDelegate?
/**
To execute in the order of the layout chain, override this
method. LayoutSubviews should be called immediately, unless you
have a certain need.
*/
open override func layoutSubviews() {
super.layoutSubviews()
guard let v = tabBar else {
return
}
let h = Device.height
let w = Device.width
let p = v.intrinsicContentSize.height + v.grid.layoutEdgeInsets.top + v.grid.layoutEdgeInsets.bottom
let y = h - p
v.y = y
v.width = w + v.grid.layoutEdgeInsets.left + v.grid.layoutEdgeInsets.right
v.height = p
rootViewController.view.frame.origin.y = 0
rootViewController.view.frame.size.height = y
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
open override func prepareView() {
super.prepareView()
prepareTabBar()
}
/// Prepares the tabBar.
private func prepareTabBar() {
if nil == tabBar {
tabBar = TabBar()
tabBar.zPosition = 1000
view.addSubview(tabBar)
}
}
}
...@@ -49,7 +49,7 @@ extension UIViewController { ...@@ -49,7 +49,7 @@ extension UIViewController {
} }
@objc(ToolbarControllerDelegate) @objc(ToolbarControllerDelegate)
public protocol ToolbarControllerDelegate : MaterialDelegate { public protocol ToolbarControllerDelegate: MaterialDelegate {
/// Delegation method that executes when the floatingViewController will open. /// Delegation method that executes when the floatingViewController will open.
@objc @objc
optional func toolbarControllerWillOpenFloatingViewController(toolbarController: ToolbarController) optional func toolbarControllerWillOpenFloatingViewController(toolbarController: ToolbarController)
...@@ -73,7 +73,7 @@ open class ToolbarController: RootController { ...@@ -73,7 +73,7 @@ open class ToolbarController: RootController {
private var internalFloatingViewController: UIViewController? private var internalFloatingViewController: UIViewController?
/// Reference to the Toolbar. /// Reference to the Toolbar.
public private(set) var toolbar: Toolbar! open internal(set) var toolbar: Toolbar!
/// Delegation handler. /// Delegation handler.
public weak var delegate: ToolbarControllerDelegate? public weak var delegate: ToolbarControllerDelegate?
...@@ -162,19 +162,21 @@ open class ToolbarController: RootController { ...@@ -162,19 +162,21 @@ open class ToolbarController: RootController {
*/ */
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if let v: Toolbar = toolbar { guard let v = toolbar else {
v.grid.layoutEdgeInsets.top = .phone == Device.userInterfaceIdiom && Device.isLandscape ? 0 : 20 return
}
let h: CGFloat = Device.height
let w: CGFloat = Device.width v.grid.layoutEdgeInsets.top = .phone == Device.userInterfaceIdiom && Device.isLandscape ? 0 : 20
let p: CGFloat = v.intrinsicContentSize.height + v.grid.layoutEdgeInsets.top + v.grid.layoutEdgeInsets.bottom
let h = Device.height
v.width = w + v.grid.layoutEdgeInsets.left + v.grid.layoutEdgeInsets.right let w = Device.width
v.height = p let p = v.intrinsicContentSize.height + v.grid.layoutEdgeInsets.top + v.grid.layoutEdgeInsets.bottom
rootViewController.view.frame.origin.y = p v.width = w + v.grid.layoutEdgeInsets.left + v.grid.layoutEdgeInsets.right
rootViewController.view.frame.size.height = h - p v.height = p
}
rootViewController.view.frame.origin.y = p
rootViewController.view.frame.size.height = h - p
} }
/** /**
...@@ -186,11 +188,11 @@ open class ToolbarController: RootController { ...@@ -186,11 +188,11 @@ open class ToolbarController: RootController {
*/ */
open override func prepareView() { open override func prepareView() {
super.prepareView() super.prepareView()
prepareToolbar() prepareTabBar()
} }
/// Prepares the Toolbar. /// Prepares the Toolbar.
private func prepareToolbar() { private func prepareTabBar() {
if nil == toolbar { if nil == toolbar {
toolbar = Toolbar() toolbar = Toolbar()
toolbar.zPosition = 1000 toolbar.zPosition = 1000
......
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