Commit cbac4b47 by Daniel Dahan

development: removed MaterialDelegate, added TabBarDelegate, and delegation…

development: removed MaterialDelegate, added TabBarDelegate, and delegation methods for will/did selected states
parent 8b0aa85d
......@@ -41,11 +41,6 @@ open class Button: UIButton {
*/
open private(set) var visualLayer: CAShapeLayer!
/**
A base delegate reference used when subclassing View.
*/
public weak var delegate: MaterialDelegate?
/// An Array of pulse layers.
public private(set) lazy var pulseLayers = [CAShapeLayer]()
......
......@@ -38,7 +38,7 @@ public enum CaptureMode: Int {
}
@objc(CaptureDelegate)
public protocol CaptureDelegate: MaterialDelegate {
public protocol CaptureDelegate {
/**
A delegation method that is fired when the record timer has started.
- Parameter capture: A reference to the calling capture.
......@@ -132,7 +132,10 @@ public protocol CaptureDelegate: MaterialDelegate {
}
open class Capture: View, UIGestureRecognizerDelegate {
/// A Timer reference for when recording is enabled.
/// A delegation reference.
public weak var delegate: CaptureDelegate?
/// A Timer reference for when recording is enabled.
private var timer: Timer?
/// A tap gesture reference for focus events.
......@@ -349,7 +352,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
timer?.invalidate()
timer = Timer(timeInterval: 0.5, target: self, selector: #selector(updateTimer), userInfo: nil, repeats: true)
RunLoop.main.add(timer!, forMode: .commonModes)
(delegate as? CaptureDelegate)?.captureDidStartRecordTimer?(capture: self)
delegate?.captureDidStartRecordTimer?(capture: self)
}
/// Updates the timer when recording.
......@@ -359,7 +362,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
let hours: Int = Int(time / 3600)
let minutes: Int = Int((time / 60).truncatingRemainder(dividingBy: 60))
let seconds: Int = Int(time.truncatingRemainder(dividingBy: 60))
(delegate as? CaptureDelegate)?.captureDidUpdateRecordTimer?(capture: self, hours: hours, minutes: minutes, seconds: seconds)
delegate?.captureDidUpdateRecordTimer?(capture: self, hours: hours, minutes: minutes, seconds: seconds)
}
/// Stops the timer when recording.
......@@ -371,7 +374,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
let seconds: Int = Int(time.truncatingRemainder(dividingBy: 60))
timer?.invalidate()
timer = nil
(delegate as? CaptureDelegate)?.captureDidStopRecordTimer?(capture: self, hours: hours, minutes: minutes, seconds: seconds)
delegate?.captureDidStopRecordTimer?(capture: self, hours: hours, minutes: minutes, seconds: seconds)
}
/**
......@@ -379,7 +382,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
- Parameter button: A UIButton that is associated with the event.
*/
internal func handleFlashButton(button: UIButton) {
(delegate as? CaptureDelegate)?.captureDidPressFlashButton?(capture: self, button: button)
delegate?.captureDidPressFlashButton?(capture: self, button: button)
}
/**
......@@ -388,7 +391,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
*/
internal func handleSwitchCamerasButton(button: UIButton) {
captureSession.switchCameras()
(delegate as? CaptureDelegate)?.captureDidPressSwitchCamerasButton?(capture: self, button: button)
delegate?.captureDidPressSwitchCamerasButton?(capture: self, button: button)
}
/**
......@@ -407,7 +410,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
startTimer()
}
}
(delegate as? CaptureDelegate)?.captureDidPressCaptureButton?(capture: self, button: button)
delegate?.captureDidPressCaptureButton?(capture: self, button: button)
}
/**
......@@ -416,7 +419,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
*/
internal func handleCameraButton(button: UIButton) {
captureMode = .photo
(delegate as? CaptureDelegate)?.captureDidPressCameraButton?(capture: self, button: button)
delegate?.captureDidPressCameraButton?(capture: self, button: button)
}
/**
......@@ -425,7 +428,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
*/
internal func handleVideoButton(button: UIButton) {
captureMode = .video
(delegate as? CaptureDelegate)?.captureDidPressVideoButton?(capture: self, button: button)
delegate?.captureDidPressVideoButton?(capture: self, button: button)
}
/**
......@@ -438,7 +441,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
let point: CGPoint = recognizer.location(in: self)
captureSession.focus(at: previewView.captureDevicePointOfInterestForPoint(point: point))
animateTapLayer(layer: focusLayer!, point: point)
(delegate as? CaptureDelegate)?.captureDidTapToFocusAtPoint?(capture: self, point: point)
delegate?.captureDidTapToFocusAtPoint?(capture: self, point: point)
}
}
......@@ -452,7 +455,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
let point: CGPoint = recognizer.location(in: self)
captureSession.expose(at: previewView.captureDevicePointOfInterestForPoint(point: point))
animateTapLayer(layer: exposureLayer!, point: point)
(delegate as? CaptureDelegate)?.captureDidTapToExposeAtPoint?(capture: self, point: point)
delegate?.captureDidTapToExposeAtPoint?(capture: self, point: point)
}
}
......@@ -466,7 +469,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
captureSession.reset()
let point: CGPoint = previewView.pointForCaptureDevicePointOfInterest(point: CGPoint(x: 0.5, y: 0.5))
animateTapLayer(layer: resetLayer!, point: point)
(delegate as? CaptureDelegate)?.captureDidTapToResetAtPoint?(capture: self, point: point)
delegate?.captureDidTapToResetAtPoint?(capture: self, point: point)
}
}
......
......@@ -41,9 +41,6 @@ open class MaterialCollectionReusableView: UICollectionReusableView {
*/
open private(set) var visualLayer: CAShapeLayer!
/// A base delegate reference used when subclassing View.
public weak var delegate: MaterialDelegate?
/// An Array of pulse layers.
open private(set) lazy var pulseLayers = [CAShapeLayer]()
......@@ -54,7 +51,7 @@ open class MaterialCollectionReusableView: UICollectionReusableView {
@IBInspectable open var pulseColor = Color.grey.base
/// The type of PulseAnimation.
open var pulseAnimation: PulseAnimation = .pointWithBacking
open var pulseAnimation = PulseAnimation.pointWithBacking
/**
A property that manages an image for the visualLayer's contents
......
......@@ -41,11 +41,6 @@ open class CollectionViewCell: UICollectionViewCell {
*/
open private(set) var visualLayer: CAShapeLayer!
/**
A base delegate reference used when subclassing View.
*/
public weak var delegate: MaterialDelegate?
/// An Array of pulse layers.
open private(set) lazy var pulseLayers = [CAShapeLayer]()
......@@ -56,7 +51,7 @@ open class CollectionViewCell: UICollectionViewCell {
@IBInspectable open var pulseColor: UIColor = Color.grey.base
/// The type of PulseAnimation.
open var pulseAnimation: PulseAnimation = .pointWithBacking
open var pulseAnimation = PulseAnimation.pointWithBacking
/**
A property that manages an image for the visualLayer's contents
......
......@@ -30,6 +30,6 @@
import UIKit
public protocol CollectionViewDelegate: MaterialDelegate, UICollectionViewDelegate {
public protocol CollectionViewDelegate: UICollectionViewDelegate {
}
......@@ -30,9 +30,6 @@
import UIKit
@objc(MaterialDelegate)
public protocol MaterialDelegate {}
@objc(Layer)
open class Layer: CAShapeLayer {
/**
......
......@@ -31,17 +31,19 @@
import UIKit
@objc(MenuViewDelegate)
public protocol MenuViewDelegate : MaterialDelegate {
public protocol MenuViewDelegate {
/// Gets called when the user taps outside menu buttons.
@objc
optional func menuViewDidTapOutside(menuView: MenuView)
}
public class MenuView : PulseView {
/// References the Menu instance.
public private(set) lazy var menu: Menu = Menu()
/// A delegation reference.
public weak var delegate: MenuViewDelegate?
public override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
/**
Since the subviews will be outside the bounds of this view,
......@@ -59,7 +61,7 @@ public class MenuView : PulseView {
}
if menu.isOpened {
(delegate as? MenuViewDelegate)?.menuViewDidTapOutside?(menuView: self)
delegate?.menuViewDidTapOutside?(menuView: self)
}
return super.hitTest(point, with: event)
......
......@@ -49,7 +49,7 @@ extension UIViewController {
}
@objc(PageTabBarControllerDelegate)
public protocol PageTabBarControllerDelegate: MaterialDelegate {
public protocol PageTabBarControllerDelegate {
}
......
......@@ -43,7 +43,7 @@ open class PulseView: View {
open var pulseColor = Color.grey.base
/// The type of PulseAnimation.
open var pulseAnimation: PulseAnimation = .pointWithBacking
open var pulseAnimation = PulseAnimation.pointWithBacking
/**
Triggers the pulse animation.
......
......@@ -36,6 +36,27 @@ public enum TabBarLineAlignment: Int {
case bottom
}
@objc(TabBarDelegate)
public protocol TabBarDelegate {
/**
A delegation method that is executed when the button will trigger the
animation to the next tab.
- Parameter tabBar: A TabBar.
- Parameter button: A UIButton.
*/
@objc
optional func tabBarWillSelectButton(tabBar: TabBar, button: UIButton)
/**
A delegation method that is executed when the button did complete the
animation to the next tab.
- Parameter tabBar: A TabBar.
- Parameter button: A UIButton.
*/
@objc
optional func tabBarDidSelectButton(tabBar: TabBar, button: UIButton)
}
open class TabBar: View {
/// Will render the view.
open var willRenderView: Bool {
......@@ -80,7 +101,10 @@ open class TabBar: View {
grid.interimSpace = value
}
}
/// A delegation reference.
public weak var delegate: TabBarDelegate?
open override var intrinsicContentSize: CGSize {
return CGSize(width: width, height: 49)
}
......@@ -161,14 +185,21 @@ open class TabBar: View {
/// Handles the button touch event.
@objc
internal func handleButton(button: UIButton) {
selected = button
delegate?.tabBarWillSelectButton?(tabBar: self, button: button)
selected = button
UIView.animate(withDuration: 0.25, animations: { [weak self] in
if let s = self {
s.line.x = button.x
s.line.width = button.width
}
})
UIView.animate(withDuration: 0.25, animations: { [weak self, button = button] in
guard let s = self else {
return
}
s.line.x = button.x
s.line.width = button.width
}) { [weak self, button = button] _ in
guard let s = self else {
return
}
s.delegate?.tabBarDidSelectButton?(tabBar: s, button: button)
}
}
/**
......
......@@ -40,9 +40,6 @@ open class TableViewCell: UITableViewCell {
*/
open internal(set) var visualLayer: CAShapeLayer!
/// A base delegate reference used when subclassing View.
public weak var delegate: MaterialDelegate?
/// An Array of pulse layers.
open private(set) lazy var pulseLayers = [CAShapeLayer]()
......@@ -55,7 +52,7 @@ open class TableViewCell: UITableViewCell {
open var pulseColor = Color.grey.base
/// The type of PulseAnimation.
open var pulseAnimation: PulseAnimation = .pointWithBacking
open var pulseAnimation = PulseAnimation.pointWithBacking
/// A property that accesses the backing layer's backgroundColor.
@IBInspectable
......
......@@ -49,7 +49,7 @@ extension UIViewController {
}
@objc(ToolbarControllerDelegate)
public protocol ToolbarControllerDelegate: MaterialDelegate {
public protocol ToolbarControllerDelegate {
/// Delegation method that executes when the floatingViewController will open.
@objc
optional func toolbarControllerWillOpenFloatingViewController(toolbarController: ToolbarController)
......
......@@ -41,9 +41,6 @@ open class View: UIView {
*/
open private(set) var visualLayer: CAShapeLayer!
/// A base delegate reference used when subclassing View.
public weak var delegate: MaterialDelegate?
/**
A property that manages an image for the visualLayer's contents
property. Images should not be set to the backing layer's contents
......
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