Commit da92a778 by Daniel Dahan

development: updated MaterialGravity to Gravity and updated SnackbarController…

development: updated MaterialGravity to Gravity and updated SnackbarController API with HeightPreset
parent 5cc2e5bd
...@@ -31,10 +31,24 @@ ...@@ -31,10 +31,24 @@
import UIKit import UIKit
import Material import Material
class PhotoLibraryCollectionViewCell: CollectionViewCell { class PhotoLibraryCollectionReusableView: CollectionReusableView {
/// A reference to the toolbar.
private(set) var toolbar: Toolbar!
open override func prepare() { open override func prepare() {
super.prepare() super.prepare()
pulseAnimation = .backing prepareToolbar()
contentsGravityPreset = .ResizeAspectFill }
/// Prepares the toolbar.
private func prepareToolbar() {
toolbar = Toolbar()
toolbar.titleLabel.font = RobotoFont.regular(with: 14)
toolbar.titleLabel.textAlignment = .left
toolbar.contentEdgeInsets.left = 16
toolbar.contentEdgeInsets.right = 16
toolbar.depthPreset = .none
toolbar.dividerColor = Color.grey.lighten3
layout(toolbar).edges()
} }
} }
...@@ -31,26 +31,11 @@ ...@@ -31,26 +31,11 @@
import UIKit import UIKit
import Material import Material
class PhotoLibraryCollectionReusableView: CollectionReusableView { class PhotoLibraryCollectionViewCell: CollectionViewCell {
/// A reference to the toolbar.
private(set) var toolbar: Toolbar!
open override func prepare() { open override func prepare() {
super.prepare() super.prepare()
backgroundColor = nil pulseColor = .white
pulseAnimation = .backing
prepareToolbar() contentsGravityPreset = .resizeAspectFill
}
/// Prepares the toolbar.
private func prepareToolbar() {
toolbar = Toolbar()
toolbar.titleLabel.font = RobotoFont.regular(with: 14)
toolbar.titleLabel.textAlignment = .left
toolbar.contentEdgeInsets.left = 16
toolbar.contentEdgeInsets.right = 16
toolbar.depthPreset = .none
toolbar.dividerColor = Color.grey.lighten3
layout(toolbar).edges()
} }
} }
...@@ -141,7 +141,7 @@ class PhotoLibraryViewController: PhotoLibraryController { ...@@ -141,7 +141,7 @@ class PhotoLibraryViewController: PhotoLibraryController {
layout.sectionHeadersPinToVisibleBounds = true layout.sectionHeadersPinToVisibleBounds = true
collectionView = PhotoLibraryCollectionView(frame: .zero, collectionViewLayout: layout) collectionView = PhotoLibraryCollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.backgroundColor = clear collectionView.backgroundColor = .clear
collectionView.delegate = self collectionView.delegate = self
collectionView.dataSource = self collectionView.dataSource = self
view.layout(collectionView).edges() view.layout(collectionView).edges()
......
...@@ -39,19 +39,19 @@ class AppSnackbarController: SnackbarController { ...@@ -39,19 +39,19 @@ class AppSnackbarController: SnackbarController {
} }
extension AppSnackbarController: SnackbarControllerDelegate { extension AppSnackbarController: SnackbarControllerDelegate {
func snackbarControllerWillShow(snackbarController: SnackbarController) { func snackbarController(snackbarController: SnackbarController, willShow snackbar: Snackbar) {
print("snackbarControllerWillShow") print("snackbarController will show")
} }
func snackbarControllerWillHide(snackbarController: SnackbarController) { func snackbarController(snackbarController: SnackbarController, willHide snackbar: Snackbar) {
print("snackbarControllerWillHide") print("snackbarController will hide")
} }
func snackbarControllerDidShow(snackbarController: SnackbarController) { func snackbarController(snackbarController: SnackbarController, didShow snackbar: Snackbar) {
print("snackbarControllerDidShow") print("snackbarController did show")
} }
func snackbarControllerDidHide(snackbarController: SnackbarController) { func snackbarController(snackbarController: SnackbarController, didHide snackbar: Snackbar) {
print("snackbarControllerDidHide") print("snackbarController did hide")
} }
} }
...@@ -37,12 +37,13 @@ class RootViewController: UIViewController { ...@@ -37,12 +37,13 @@ class RootViewController: UIViewController {
open override func viewDidLoad() { open override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
view.backgroundColor = Color.grey.lighten5 view.backgroundColor = Color.grey.lighten5
prepareUndoButton()
} }
open override func viewDidAppear(_ animated: Bool) { open override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated) super.viewDidAppear(animated)
prepareUndoButton()
prepareSnackbar() prepareSnackbar()
animateSnackbar() animateSnackbar()
scheduleAnimation() scheduleAnimation()
...@@ -55,12 +56,12 @@ class RootViewController: UIViewController { ...@@ -55,12 +56,12 @@ class RootViewController: UIViewController {
} }
private func prepareSnackbar() { private func prepareSnackbar() {
guard let sc = snackbarController else { guard let snackbar = snackbarController?.snackbar else {
return return
} }
sc.snackbar.text = "Reminder saved." snackbar.text = "Reminder saved."
sc.snackbar.rightViews = [undoButton] snackbar.rightViews = [undoButton]
} }
private func scheduleAnimation() { private func scheduleAnimation() {
......
...@@ -130,9 +130,9 @@ open class CollectionReusableView: UICollectionReusableView { ...@@ -130,9 +130,9 @@ open class CollectionReusableView: UICollectionReusableView {
} }
/// A Preset for the contentsGravity property. /// A Preset for the contentsGravity property.
open var contentsGravityPreset: MaterialGravity { open var contentsGravityPreset: Gravity {
didSet { didSet {
contentsGravity = MaterialGravityToValue(gravity: contentsGravityPreset) contentsGravity = GravityToValue(gravity: contentsGravityPreset)
} }
} }
...@@ -191,23 +191,23 @@ open class CollectionReusableView: UICollectionReusableView { ...@@ -191,23 +191,23 @@ open class CollectionReusableView: UICollectionReusableView {
} }
/** /**
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) {
contentsGravityPreset = .ResizeAspectFill contentsGravityPreset = .resizeAspectFill
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepare() prepare()
} }
/** /**
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) {
contentsGravityPreset = .ResizeAspectFill contentsGravityPreset = .resizeAspectFill
super.init(frame: frame) super.init(frame: frame)
prepare() prepare()
} }
...@@ -282,12 +282,12 @@ open class CollectionReusableView: UICollectionReusableView { ...@@ -282,12 +282,12 @@ open class CollectionReusableView: UICollectionReusableView {
} }
/** /**
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 func prepare() { open func prepare() {
contentScaleFactor = Device.scale contentScaleFactor = Device.scale
pulseAnimation = .none pulseAnimation = .none
......
...@@ -133,9 +133,9 @@ open class CollectionViewCell: UICollectionViewCell { ...@@ -133,9 +133,9 @@ open class CollectionViewCell: UICollectionViewCell {
} }
/// A Preset for the contentsGravity property. /// A Preset for the contentsGravity property.
public var contentsGravityPreset: MaterialGravity { public var contentsGravityPreset: Gravity {
didSet { didSet {
contentsGravity = MaterialGravityToValue(gravity: contentsGravityPreset) contentsGravity = GravityToValue(gravity: contentsGravityPreset)
} }
} }
...@@ -202,7 +202,7 @@ open class CollectionViewCell: UICollectionViewCell { ...@@ -202,7 +202,7 @@ open class CollectionViewCell: UICollectionViewCell {
- Parameter aDecoder: A NSCoder instance. - Parameter aDecoder: A NSCoder instance.
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
contentsGravityPreset = .ResizeAspectFill contentsGravityPreset = .resizeAspectFill
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepare() prepare()
} }
...@@ -214,7 +214,7 @@ open class CollectionViewCell: UICollectionViewCell { ...@@ -214,7 +214,7 @@ open class CollectionViewCell: UICollectionViewCell {
- Parameter frame: A CGRect instance. - Parameter frame: A CGRect instance.
*/ */
public override init(frame: CGRect) { public override init(frame: CGRect) {
contentsGravityPreset = .ResizeAspectFill contentsGravityPreset = .resizeAspectFill
super.init(frame: frame) super.init(frame: frame)
prepare() prepare()
} }
......
...@@ -87,9 +87,9 @@ open class Layer: CAShapeLayer { ...@@ -87,9 +87,9 @@ open class Layer: CAShapeLayer {
} }
/// A Preset for the contentsGravity property. /// A Preset for the contentsGravity property.
open var contentsGravityPreset: MaterialGravity { open var contentsGravityPreset: Gravity {
didSet { didSet {
contentsGravity = MaterialGravityToValue(gravity: contentsGravityPreset) contentsGravity = GravityToValue(gravity: contentsGravityPreset)
} }
} }
...@@ -124,7 +124,7 @@ open class Layer: CAShapeLayer { ...@@ -124,7 +124,7 @@ open class Layer: CAShapeLayer {
- Parameter aDecoder: A NSCoder instance. - Parameter aDecoder: A NSCoder instance.
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
contentsGravityPreset = .ResizeAspectFill contentsGravityPreset = .resizeAspectFill
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareVisualLayer() prepareVisualLayer()
} }
...@@ -135,14 +135,14 @@ open class Layer: CAShapeLayer { ...@@ -135,14 +135,14 @@ open class Layer: CAShapeLayer {
- Parameter layer: Any. - Parameter layer: Any.
*/ */
public override init(layer: Any) { public override init(layer: Any) {
contentsGravityPreset = .ResizeAspectFill contentsGravityPreset = .resizeAspectFill
super.init() super.init()
prepareVisualLayer() prepareVisualLayer()
} }
/// A convenience initializer. /// A convenience initializer.
public override init() { public override init() {
contentsGravityPreset = .ResizeAspectFill contentsGravityPreset = .resizeAspectFill
super.init() super.init()
prepareVisualLayer() prepareVisualLayer()
} }
......
...@@ -30,48 +30,48 @@ ...@@ -30,48 +30,48 @@
import UIKit import UIKit
@objc(MaterialGravity) @objc(Gravity)
public enum MaterialGravity: Int { public enum Gravity: Int {
case Center case center
case Top case top
case Bottom case bottom
case Left case left
case Right case right
case TopLeft case topLeft
case TopRight case topRight
case BottomLeft case bottomLeft
case BottomRight case bottomRight
case Resize case resize
case ResizeAspect case resizeAspect
case ResizeAspectFill case resizeAspectFill
} }
/// Converts the MaterialGravity enum to a String value. /// Converts the Gravity enum to a String value.
public func MaterialGravityToValue(gravity: MaterialGravity) -> String { public func GravityToValue(gravity: Gravity) -> String {
switch gravity { switch gravity {
case .Center: case .center:
return kCAGravityCenter return kCAGravityCenter
case .Top: case .top:
return kCAGravityTop return kCAGravityTop
case .Bottom: case .bottom:
return kCAGravityBottom return kCAGravityBottom
case .Left: case .left:
return kCAGravityLeft return kCAGravityLeft
case .Right: case .right:
return kCAGravityRight return kCAGravityRight
case .TopLeft: case .topLeft:
return kCAGravityBottomLeft return kCAGravityBottomLeft
case .TopRight: case .topRight:
return kCAGravityBottomRight return kCAGravityBottomRight
case .BottomLeft: case .bottomLeft:
return kCAGravityTopLeft return kCAGravityTopLeft
case .BottomRight: case .bottomRight:
return kCAGravityTopRight return kCAGravityTopRight
case .Resize: case .resize:
return kCAGravityResize return kCAGravityResize
case .ResizeAspect: case .resizeAspect:
return kCAGravityResizeAspect return kCAGravityResizeAspect
case .ResizeAspectFill: case .resizeAspectFill:
return kCAGravityResizeAspectFill return kCAGravityResizeAspectFill
} }
} }
...@@ -35,30 +35,34 @@ public protocol SnackbarControllerDelegate { ...@@ -35,30 +35,34 @@ public protocol SnackbarControllerDelegate {
/** /**
A delegation method that is executed when a Snackbar will show. A delegation method that is executed when a Snackbar will show.
- Parameter snackbarController: A SnackbarController. - Parameter snackbarController: A SnackbarController.
- Parameter snackbar: A Snackbar.
*/ */
@objc @objc
optional func snackbarControllerWillShow(snackbarController: SnackbarController) optional func snackbarController(snackbarController: SnackbarController, willShow snackbar: Snackbar)
/** /**
A delegation method that is executed when a Snackbar did show. A delegation method that is executed when a Snackbar did show.
- Parameter snackbarController: A SnackbarController. - Parameter snackbarController: A SnackbarController.
- Parameter snackbar: A Snackbar.
*/ */
@objc @objc
optional func snackbarControllerDidShow(snackbarController: SnackbarController) optional func snackbarController(snackbarController: SnackbarController, didShow snackbar: Snackbar)
/** /**
A delegation method that is executed when a Snackbar will hide. A delegation method that is executed when a Snackbar will hide.
- Parameter snackbarController: A SnackbarController. - Parameter snackbarController: A SnackbarController.
- Parameter snackbar: A Snackbar.
*/ */
@objc @objc
optional func snackbarControllerWillHide(snackbarController: SnackbarController) optional func snackbarController(snackbarController: SnackbarController, willHide snackbar: Snackbar)
/** /**
A delegation method that is executed when a Snackbar did hide. A delegation method that is executed when a Snackbar did hide.
- Parameter snackbarController: A SnackbarController. - Parameter snackbarController: A SnackbarController.
- Parameter snackbar: A Snackbar.
*/ */
@objc @objc
optional func snackbarControllerDidHide(snackbarController: SnackbarController) optional func snackbarController(snackbarController: SnackbarController, didHide snackbar: Snackbar)
} }
@objc(SnackbarAlignment) @objc(SnackbarAlignment)
...@@ -110,9 +114,9 @@ open class SnackbarController: RootController { ...@@ -110,9 +114,9 @@ open class SnackbarController: RootController {
} }
if .visible == status { if .visible == status {
s.delegate?.snackbarControllerWillShow?(snackbarController: s) s.delegate?.snackbarController?(snackbarController: s, willShow: s.snackbar)
} else { } else {
s.delegate?.snackbarControllerWillHide?(snackbarController: s) s.delegate?.snackbarController?(snackbarController: s, willHide: s.snackbar)
} }
s.isAnimating = true s.isAnimating = true
...@@ -134,11 +138,12 @@ open class SnackbarController: RootController { ...@@ -134,11 +138,12 @@ open class SnackbarController: RootController {
s.isAnimating = false s.isAnimating = false
s.isUserInteractionEnabled = true s.isUserInteractionEnabled = true
s.snackbar.status = status s.snackbar.status = status
s.layoutSubviews()
if .visible == status { if .visible == status {
s.delegate?.snackbarControllerDidShow?(snackbarController: s) s.delegate?.snackbarController?(snackbarController: s, didShow: s.snackbar)
} else { } else {
s.delegate?.snackbarControllerDidHide?(snackbarController: s) s.delegate?.snackbarController?(snackbarController: s, didHide: s.snackbar)
} }
completion?(s.snackbar) completion?(s.snackbar)
...@@ -163,7 +168,6 @@ open class SnackbarController: RootController { ...@@ -163,7 +168,6 @@ open class SnackbarController: RootController {
/// Reloads the view. /// Reloads the view.
open func reload() { open func reload() {
snackbar.width = view.width snackbar.width = view.width
snackbar.height = snackbar.intrinsicContentSize.height + snackbar.layoutEdgeInsets.top + snackbar.layoutEdgeInsets.bottom
layoutSnackbar(status: snackbar.status) layoutSnackbar(status: snackbar.status)
} }
......
...@@ -212,7 +212,7 @@ open class TabBar: Bar { ...@@ -212,7 +212,7 @@ open class TabBar: Bar {
// Prepares the line. // Prepares the line.
private func prepareLine() { private func prepareLine() {
line = UIView() line = UIView()
line.zPosition = 5100 line.zPosition = 6000
lineColor = Color.blueGrey.lighten3 lineColor = Color.blueGrey.lighten3
lineHeight = 3 lineHeight = 3
addSubview(line) addSubview(line)
......
...@@ -99,9 +99,9 @@ open class View: UIView { ...@@ -99,9 +99,9 @@ open class View: UIView {
/// A Preset for the contentsGravity property. /// A Preset for the contentsGravity property.
@IBInspectable @IBInspectable
open var contentsGravityPreset: MaterialGravity { open var contentsGravityPreset: Gravity {
didSet { didSet {
contentsGravity = MaterialGravityToValue(gravity: contentsGravityPreset) contentsGravity = GravityToValue(gravity: contentsGravityPreset)
} }
} }
...@@ -129,7 +129,7 @@ open class View: UIView { ...@@ -129,7 +129,7 @@ open class View: UIView {
- Parameter aDecoder: A NSCoder instance. - Parameter aDecoder: A NSCoder instance.
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
contentsGravityPreset = .ResizeAspectFill contentsGravityPreset = .resizeAspectFill
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepare() prepare()
} }
...@@ -141,7 +141,7 @@ open class View: UIView { ...@@ -141,7 +141,7 @@ open class View: UIView {
- Parameter frame: A CGRect instance. - Parameter frame: A CGRect instance.
*/ */
public override init(frame: CGRect) { public override init(frame: CGRect) {
contentsGravityPreset = .ResizeAspectFill contentsGravityPreset = .resizeAspectFill
super.init(frame: frame) super.init(frame: frame)
prepare() prepare()
} }
......
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