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