Commit 34e53600 by Daniel Dahan

development: rework on cards

parent 5b66bcf0
...@@ -107,7 +107,7 @@ A button is used to trigger an action through a touch event. Material comes with ...@@ -107,7 +107,7 @@ A button is used to trigger an action through a touch event. Material comes with
![Material Image](http://www.cosmicmind.io/material/white/button.gif) ![Material Image](http://www.cosmicmind.io/material/white/button.gif)
* Download the complete [Button sample](https://github.com/CosmicMind/Samples/tree/master/Material/Programmatic/Button). * Download the complete [Button sample](https://github.com/CosmicMind/Samples/tree/master/Material/Programmatic/Button).
* Learn more about [TextField](http://cosmicmind.io/material/button). * Learn more about [Button](http://cosmicmind.io/material/button).
## Switch ## Switch
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>FMWK</string> <string>FMWK</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>2.2.1</string> <string>2.2.3</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
...@@ -259,7 +259,7 @@ open class Bar: View { ...@@ -259,7 +259,7 @@ open class Bar: View {
*/ */
open override func prepare() { open override func prepare() {
super.prepare() super.prepare()
heightPreset = .default heightPreset = .normal
autoresizingMask = .flexibleWidth autoresizingMask = .flexibleWidth
interimSpacePreset = .interimSpace3 interimSpacePreset = .interimSpace3
contentEdgeInsetsPreset = .square1 contentEdgeInsetsPreset = .square1
......
...@@ -70,6 +70,7 @@ open class Card: PulseView { ...@@ -70,6 +70,7 @@ open class Card: PulseView {
@IBInspectable @IBInspectable
open var toolbar: Toolbar? { open var toolbar: Toolbar? {
didSet { didSet {
oldValue?.removeFromSuperview()
layoutSubviews() layoutSubviews()
} }
} }
...@@ -93,6 +94,7 @@ open class Card: PulseView { ...@@ -93,6 +94,7 @@ open class Card: PulseView {
@IBInspectable @IBInspectable
open var contentView: UIView? { open var contentView: UIView? {
didSet { didSet {
oldValue?.removeFromSuperview()
layoutSubviews() layoutSubviews()
} }
} }
...@@ -116,6 +118,7 @@ open class Card: PulseView { ...@@ -116,6 +118,7 @@ open class Card: PulseView {
@IBInspectable @IBInspectable
open var bottomBar: Bar? { open var bottomBar: Bar? {
didSet { didSet {
oldValue?.removeFromSuperview()
layoutSubviews() layoutSubviews()
} }
} }
...@@ -193,7 +196,7 @@ open class Card: PulseView { ...@@ -193,7 +196,7 @@ open class Card: PulseView {
format += "-(toolbarTop)-[toolbar]-(toolbarBottom)" format += "-(toolbarTop)-[toolbar]-(toolbarBottom)"
views["toolbar"] = v views["toolbar"] = v
container.layout(v).horizontally(left: toolbarEdgeInsets.left, right: toolbarEdgeInsets.right) container.layout(v).horizontally(left: toolbarEdgeInsets.left, right: toolbarEdgeInsets.right).height(v.height)
} }
if let v = contentView { if let v = contentView {
...@@ -215,8 +218,6 @@ open class Card: PulseView { ...@@ -215,8 +218,6 @@ open class Card: PulseView {
} }
if let v = bottomBar { if let v = bottomBar {
metrics["bottomBarBottom"] = bottomBarEdgeInsets.bottom
if nil != contentView { if nil != contentView {
metrics["contentViewBottom"] = (metrics["contentViewBottom"] as! CGFloat) + bottomBarEdgeInsets.top metrics["contentViewBottom"] = (metrics["contentViewBottom"] as! CGFloat) + bottomBarEdgeInsets.top
format += "-[bottomBar]-(bottomBarBottom)" format += "-[bottomBar]-(bottomBarBottom)"
...@@ -225,18 +226,18 @@ open class Card: PulseView { ...@@ -225,18 +226,18 @@ open class Card: PulseView {
format += "-[bottomBar]-(bottomBarBottom)" format += "-[bottomBar]-(bottomBarBottom)"
} else { } else {
metrics["bottomBarTop"] = bottomBarEdgeInsets.top metrics["bottomBarTop"] = bottomBarEdgeInsets.top
format += "-(bottomBarTop)-[bottomBar]-(bottomBarBottom)" format += "-(bottomBarTop)-[bottomBar]"
} }
views["bottomBar"] = v views["bottomBar"] = v
container.layout(v).horizontally(left: bottomBarEdgeInsets.left, right: bottomBarEdgeInsets.right) container.layout(v).horizontally(left: bottomBarEdgeInsets.left, right: bottomBarEdgeInsets.right).height(v.height).bottom(bottomBarEdgeInsets.bottom)
} }
guard 0 < views.count else { guard 0 < views.count else {
return return
} }
container.addConstraints(Layout.constraint(format: "\(format)-|", options: [], metrics: metrics, views: views)) container.addConstraints(Layout.constraint(format: "\(format)|", options: [], metrics: metrics, views: views))
} }
/** /**
......
...@@ -32,12 +32,12 @@ import UIKit ...@@ -32,12 +32,12 @@ import UIKit
open class CollectionView: UICollectionView { open class CollectionView: UICollectionView {
/// A preset wrapper around contentEdgeInsets. /// A preset wrapper around contentEdgeInsets.
open var contentEdgeInsetsPreset: EdgeInsets { open var contentEdgeInsetsPreset: EdgeInsetsPreset {
get { get {
return (collectionViewLayout as? CollectionViewLayout)!.contentEdgeInsets return (collectionViewLayout as? CollectionViewLayout)!.contentEdgeInsetsPreset
} }
set(value) { set(value) {
(collectionViewLayout as? CollectionViewLayout)!.contentEdgeInsets = value (collectionViewLayout as? CollectionViewLayout)!.contentEdgeInsetsPreset = value
} }
} }
......
...@@ -32,8 +32,8 @@ import UIKit ...@@ -32,8 +32,8 @@ import UIKit
public protocol CollectionViewDataSource: UICollectionViewDataSource { public protocol CollectionViewDataSource: UICollectionViewDataSource {
/** /**
Retrieves the items for the collectionView. Retrieves the data source items for the collectionView.
- Returns: An Array of CollectionDataSourceItem objects. - Returns: An Array of CollectionDataSourceItem objects.
*/ */
func items() -> [CollectionDataSourceItem] var dataSourceItems: [CollectionDataSourceItem] { get }
} }
...@@ -38,7 +38,7 @@ open class CollectionViewLayout: UICollectionViewLayout { ...@@ -38,7 +38,7 @@ open class CollectionViewLayout: UICollectionViewLayout {
open var itemSize = CGSize.zero open var itemSize = CGSize.zero
/// A preset wrapper around contentEdgeInsets. /// A preset wrapper around contentEdgeInsets.
open var contentEdgeInsetsPreset: EdgeInsetsPreset = .none { open var contentEdgeInsetsPreset = EdgeInsetsPreset.none {
didSet { didSet {
contentEdgeInsets = EdgeInsetsPresetToValue(preset: contentEdgeInsetsPreset) contentEdgeInsets = EdgeInsetsPresetToValue(preset: contentEdgeInsetsPreset)
} }
...@@ -79,7 +79,7 @@ open class CollectionViewLayout: UICollectionViewLayout { ...@@ -79,7 +79,7 @@ open class CollectionViewLayout: UICollectionViewLayout {
- Returns: An Array of NSIndexPath objects. - Returns: An Array of NSIndexPath objects.
*/ */
open func indexPathsOfItemsInRect(rect: CGRect) -> [NSIndexPath] { open func indexPathsOfItemsInRect(rect: CGRect) -> [NSIndexPath] {
var paths: Array<NSIndexPath> = Array<NSIndexPath>() var paths = [NSIndexPath]()
for (attribute, indexPath) in layoutItems { for (attribute, indexPath) in layoutItems {
if rect.intersects(attribute.frame) { if rect.intersects(attribute.frame) {
paths.append(indexPath) paths.append(indexPath)
...@@ -104,7 +104,7 @@ open class CollectionViewLayout: UICollectionViewLayout { ...@@ -104,7 +104,7 @@ open class CollectionViewLayout: UICollectionViewLayout {
} }
open override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { open override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
var layoutAttributes: Array<UICollectionViewLayoutAttributes> = Array<UICollectionViewLayoutAttributes>() var layoutAttributes = [UICollectionViewLayoutAttributes]()
for (attribute, _) in layoutItems { for (attribute, _) in layoutItems {
if rect.intersects(attribute.frame) { if rect.intersects(attribute.frame) {
layoutAttributes.append(attribute) layoutAttributes.append(attribute)
...@@ -118,9 +118,10 @@ open class CollectionViewLayout: UICollectionViewLayout { ...@@ -118,9 +118,10 @@ open class CollectionViewLayout: UICollectionViewLayout {
} }
open override func prepare() { open override func prepare() {
if let dataSource: CollectionViewDataSource = collectionView?.dataSource as? CollectionViewDataSource { guard let dataSource = collectionView?.dataSource as? CollectionViewDataSource else {
prepareLayoutForItems(dataSourceItems: dataSource.items()) return
} }
prepareLayoutForItems(dataSourceItems: dataSource.dataSourceItems)
} }
open override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint { open override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint {
......
...@@ -99,6 +99,7 @@ open class ImageCard: Card { ...@@ -99,6 +99,7 @@ open class ImageCard: Card {
container.layout(v) container.layout(v)
.horizontally(left: toolbarEdgeInsets.left, right: toolbarEdgeInsets.right) .horizontally(left: toolbarEdgeInsets.left, right: toolbarEdgeInsets.right)
.top(.top == toolbarAlignment ? toolbarEdgeInsets.top : iv.height - v.height - toolbarEdgeInsets.bottom) .top(.top == toolbarAlignment ? toolbarEdgeInsets.top : iv.height - v.height - toolbarEdgeInsets.bottom)
.height(v.height)
} }
if let v = contentView { if let v = contentView {
...@@ -125,7 +126,7 @@ open class ImageCard: Card { ...@@ -125,7 +126,7 @@ open class ImageCard: Card {
} }
views["bottomBar"] = v views["bottomBar"] = v
container.layout(v).horizontally(left: bottomBarEdgeInsets.left, right: bottomBarEdgeInsets.right) container.layout(v).horizontally(left: bottomBarEdgeInsets.left, right: bottomBarEdgeInsets.right).height(v.height)
} }
guard 0 < views.count else { guard 0 < views.count else {
......
...@@ -83,7 +83,7 @@ internal class MaterialLayer { ...@@ -83,7 +83,7 @@ internal class MaterialLayer {
} }
/// Enables automatic shadowPath sizing. /// Enables automatic shadowPath sizing.
internal var isShadowPathAutoSizing = false internal var isShadowPathAutoSizing = true
/** /**
Initializer that takes in a CALayer. Initializer that takes in a CALayer.
...@@ -316,12 +316,6 @@ extension CALayer { ...@@ -316,12 +316,6 @@ extension CALayer {
return return
} }
if .none == depthPreset { shadowPath = .none == depthPreset ? nil : UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
shadowPath = nil
} else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
} else {
animate(animation: Animation.shadowPath(path: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
}
} }
} }
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
import UIKit import UIKit
@available(iOS 9.0, *)
open class PresenterCard: Card { open class PresenterCard: Card {
/// A preset wrapper around presenterViewEdgeInsets. /// A preset wrapper around presenterViewEdgeInsets.
open var presenterViewEdgeInsetsPreset = EdgeInsetsPreset.none { open var presenterViewEdgeInsetsPreset = EdgeInsetsPreset.none {
...@@ -50,94 +51,56 @@ open class PresenterCard: Card { ...@@ -50,94 +51,56 @@ open class PresenterCard: Card {
@IBInspectable @IBInspectable
open var presenterView: UIView? { open var presenterView: UIView? {
didSet { didSet {
oldValue?.removeFromSuperview()
layoutSubviews() layoutSubviews()
} }
} }
open override func reload() { open override func reload() {
// Clear constraints so new ones do not conflict. var top: CGFloat = 0
container.removeConstraints(container.constraints) var bottom: CGFloat = 0
for v in container.subviews {
v.removeFromSuperview()
}
var format = "V:|" container.removeConstraints(container.constraints)
var views = [String: Any]()
var metrics = [String: Any]()
if let v = toolbar { if let v = toolbar {
metrics["toolbarTop"] = toolbarEdgeInsets.top top += toolbarEdgeInsets.top
metrics["toolbarBottom"] = toolbarEdgeInsets.bottom container.layout(v).top(top).left(toolbarEdgeInsets.left).right(toolbarEdgeInsets.right).height(v.height)
top += v.height + toolbarEdgeInsets.bottom
format += "-(toolbarTop)-[toolbar]-(toolbarBottom)"
views["toolbar"] = v
container.layout(v).horizontally(left: toolbarEdgeInsets.left, right: toolbarEdgeInsets.right)
} }
if let v = presenterView { if let v = presenterView {
metrics["presenterViewBottom"] = presenterViewEdgeInsets.bottom top += presenterViewEdgeInsets.top
container.layout(v).top(top).left(presenterViewEdgeInsets.left).right(presenterViewEdgeInsets.right)
if nil != toolbar { top += v.height + presenterViewEdgeInsets.bottom
metrics["toolbarBottom"] = (metrics["toolbarBottom"] as! CGFloat) + presenterViewEdgeInsets.top
format += "-[presenterView]-(presenterViewBottom)"
} else {
metrics["presenterViewTop"] = presenterViewEdgeInsets.top
format += "-(presenterViewTop)-[presenterView]-(presenterViewBottom)"
}
views["presenterView"] = v
container.layout(v).horizontally(left: presenterViewEdgeInsets.left, right: presenterViewEdgeInsets.right)
v.grid.reload()
v.divider.reload()
}
if let v = contentView {
metrics["contentViewBottom"] = contentViewEdgeInsets.bottom
if nil != presenterView {
metrics["presenterViewBottom"] = (metrics["presenterViewBottom"] as! CGFloat) + contentViewEdgeInsets.top
format += "-[contentView]-(contentViewBottom)"
} else if nil != toolbar {
metrics["toolbarBottom"] = (metrics["toolbarBottom"] as! CGFloat) + contentViewEdgeInsets.top
format += "-[contentView]-(contentViewBottom)"
} else {
metrics["contentViewTop"] = contentViewEdgeInsets.top
format += "-(contentViewTop)-[contentView]-(contentViewBottom)"
}
views["contentView"] = v
container.layout(v).horizontally(left: contentViewEdgeInsets.left, right: contentViewEdgeInsets.right)
v.grid.reload()
v.divider.reload()
} }
//
if let v = bottomBar { // if let v = contentView {
metrics["bottomBarBottom"] = bottomBarEdgeInsets.bottom // top += contentViewEdgeInsets.top
// container.layout(v).top(top).left(contentViewEdgeInsets.left).right(contentViewEdgeInsets.right)
if nil != contentView { // top += v.height + contentViewEdgeInsets.bottom
metrics["contentViewBottom"] = (metrics["contentViewBottom"] as! CGFloat) + bottomBarEdgeInsets.top // }
format += "-[bottomBar]-(bottomBarBottom)" //
} else if nil != presenterView { // if let v = bottomBar {
metrics["presenterViewBottom"] = (metrics["presenterViewBottom"] as! CGFloat) + bottomBarEdgeInsets.top // top += bottomBarEdgeInsets.top
format += "-[bottomBar]-(bottomBarBottom)" // container.layout(v).top(top).left(bottomBarEdgeInsets.left).right(bottomBarEdgeInsets.right).bottom(bottomBarEdgeInsets.bottom)
} else if nil != toolbar { // bottom += v.height + bottomBarEdgeInsets.top + bottomBarEdgeInsets.bottom
metrics["toolbarBottom"] = (metrics["toolbarBottom"] as! CGFloat) + bottomBarEdgeInsets.top // }
format += "-[bottomBar]-(bottomBarBottom)" //
} else { // if let v = contentView {
metrics["bottomBarTop"] = bottomBarEdgeInsets.top // bottom += contentViewEdgeInsets.bottom
format += "-(bottomBarTop)-[bottomBar]-(bottomBarBottom)" // container.layout(v).bottom(bottom)
} // bottom += v.height + contentViewEdgeInsets.top
// }
views["bottomBar"] = v //
container.layout(v).horizontally(left: bottomBarEdgeInsets.left, right: bottomBarEdgeInsets.right) // if let v = presenterView {
} // bottom += presenterViewEdgeInsets.bottom
// container.layout(v).bottom(bottom)
guard 0 < views.count else { // bottom += v.height + presenterViewEdgeInsets.top
return // }
} //
// if let v = toolbar {
container.addConstraints(Layout.constraint(format: "\(format)-|", options: [], metrics: metrics, views: views)) // bottom += toolbarEdgeInsets.bottom
// container.layout(v).bottom(bottom)
// }
} }
} }
...@@ -170,7 +170,6 @@ open class SearchBar: Bar { ...@@ -170,7 +170,6 @@ open class SearchBar: Bar {
*/ */
open override func prepare() { open override func prepare() {
super.prepare() super.prepare()
heightPreset = .normal
prepareTextField() prepareTextField()
prepareClearButton() prepareClearButton()
} }
......
...@@ -32,10 +32,10 @@ import UIKit ...@@ -32,10 +32,10 @@ import UIKit
extension UIViewController { extension UIViewController {
/** /**
A convenience property that provides access to the StatusBarController. A convenience property that provides access to the StatusBarController.
This is the recommended method of accessing the StatusBarController This is the recommended method of accessing the StatusBarController
through child UIViewControllers. through child UIViewControllers.
*/ */
public var statusBarController: StatusBarController? { public var statusBarController: StatusBarController? {
var viewController: UIViewController? = self var viewController: UIViewController? = self
while nil != viewController { while nil != viewController {
...@@ -53,23 +53,23 @@ open class StatusBarController: RootController { ...@@ -53,23 +53,23 @@ open class StatusBarController: RootController {
open private(set) lazy var statusBar = 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
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()
statusBar.isHidden = Device.isLandscape && .phone == Device.userInterfaceIdiom statusBar.zPosition = Device.isLandscape && .phone == Device.userInterfaceIdiom ? 0 : 3000
rootViewController.view.frame = view.bounds rootViewController.view.frame = view.bounds
} }
/** /**
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()
prepareStatusBar() prepareStatusBar()
...@@ -77,7 +77,6 @@ open class StatusBarController: RootController { ...@@ -77,7 +77,6 @@ open class StatusBarController: RootController {
/// Prepares the statusBar. /// Prepares the statusBar.
private func prepareStatusBar() { private func prepareStatusBar() {
statusBar.zPosition = 3000
statusBar.backgroundColor = .white statusBar.backgroundColor = .white
view.layout(statusBar).top().horizontally().height(20) view.layout(statusBar).top().horizontally().height(20)
} }
......
...@@ -202,7 +202,6 @@ open class TabBar: Bar { ...@@ -202,7 +202,6 @@ open class TabBar: Bar {
*/ */
open override func prepare() { open override func prepare() {
super.prepare() super.prepare()
heightPreset = .normal
contentEdgeInsetsPreset = .none contentEdgeInsetsPreset = .none
interimSpacePreset = .none interimSpacePreset = .none
prepareLine() prepareLine()
......
...@@ -148,7 +148,6 @@ open class Toolbar: Bar { ...@@ -148,7 +148,6 @@ open class Toolbar: Bar {
*/ */
open override func prepare() { open override func prepare() {
super.prepare() super.prepare()
heightPreset = .normal
contentViewAlignment = .center contentViewAlignment = .center
prepareTitleLabel() prepareTitleLabel()
prepareDetailLabel() prepareDetailLabel()
......
...@@ -173,7 +173,7 @@ open class ToolbarController: StatusBarController { ...@@ -173,7 +173,7 @@ open class ToolbarController: StatusBarController {
super.layoutSubviews() super.layoutSubviews()
statusBar.layoutIfNeeded() statusBar.layoutIfNeeded()
let y = statusBar.isHidden ? 0 : statusBar.height let y = 0 == statusBar.zPosition ? 0 : statusBar.height
let p = y + toolbar.height let p = y + toolbar.height
toolbar.y = y toolbar.y = y
......
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