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