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 { // if let v = contentView {
metrics["presenterViewTop"] = presenterViewEdgeInsets.top // top += contentViewEdgeInsets.top
format += "-(presenterViewTop)-[presenterView]-(presenterViewBottom)" // container.layout(v).top(top).left(contentViewEdgeInsets.left).right(contentViewEdgeInsets.right)
} // top += v.height + contentViewEdgeInsets.bottom
// }
views["presenterView"] = v //
container.layout(v).horizontally(left: presenterViewEdgeInsets.left, right: presenterViewEdgeInsets.right) // if let v = bottomBar {
// top += bottomBarEdgeInsets.top
v.grid.reload() // container.layout(v).top(top).left(bottomBarEdgeInsets.left).right(bottomBarEdgeInsets.right).bottom(bottomBarEdgeInsets.bottom)
v.divider.reload() // bottom += v.height + bottomBarEdgeInsets.top + bottomBarEdgeInsets.bottom
} // }
//
if let v = contentView { // if let v = contentView {
metrics["contentViewBottom"] = contentViewEdgeInsets.bottom // bottom += contentViewEdgeInsets.bottom
// container.layout(v).bottom(bottom)
if nil != presenterView { // bottom += v.height + contentViewEdgeInsets.top
metrics["presenterViewBottom"] = (metrics["presenterViewBottom"] as! CGFloat) + contentViewEdgeInsets.top // }
format += "-[contentView]-(contentViewBottom)" //
} else if nil != toolbar { // if let v = presenterView {
metrics["toolbarBottom"] = (metrics["toolbarBottom"] as! CGFloat) + contentViewEdgeInsets.top // bottom += presenterViewEdgeInsets.bottom
format += "-[contentView]-(contentViewBottom)" // container.layout(v).bottom(bottom)
} else { // bottom += v.height + presenterViewEdgeInsets.top
metrics["contentViewTop"] = contentViewEdgeInsets.top // }
format += "-(contentViewTop)-[contentView]-(contentViewBottom)" //
} // if let v = toolbar {
// bottom += toolbarEdgeInsets.bottom
views["contentView"] = v // container.layout(v).bottom(bottom)
container.layout(v).horizontally(left: contentViewEdgeInsets.left, right: contentViewEdgeInsets.right) // }
v.grid.reload()
v.divider.reload()
}
if let v = bottomBar {
metrics["bottomBarBottom"] = bottomBarEdgeInsets.bottom
if nil != contentView {
metrics["contentViewBottom"] = (metrics["contentViewBottom"] as! CGFloat) + bottomBarEdgeInsets.top
format += "-[bottomBar]-(bottomBarBottom)"
} else if nil != presenterView {
metrics["presenterViewBottom"] = (metrics["presenterViewBottom"] as! CGFloat) + bottomBarEdgeInsets.top
format += "-[bottomBar]-(bottomBarBottom)"
} else if nil != toolbar {
metrics["toolbarBottom"] = (metrics["toolbarBottom"] as! CGFloat) + bottomBarEdgeInsets.top
format += "-[bottomBar]-(bottomBarBottom)"
} else {
metrics["bottomBarTop"] = bottomBarEdgeInsets.top
format += "-(bottomBarTop)-[bottomBar]-(bottomBarBottom)"
}
views["bottomBar"] = v
container.layout(v).horizontally(left: bottomBarEdgeInsets.left, right: bottomBarEdgeInsets.right)
}
guard 0 < views.count else {
return
}
container.addConstraints(Layout.constraint(format: "\(format)-|", options: [], metrics: metrics, views: views))
} }
} }
...@@ -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()
} }
......
...@@ -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()
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
} }
...@@ -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