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