Commit 5a438b88 by Daniel Dahan

development: added blur and fade backing types for FABMenuController

parent 42b6d525
...@@ -42,6 +42,7 @@ open class FABButton: Button { ...@@ -42,6 +42,7 @@ open class FABButton: Button {
super.prepare() super.prepare()
depthPreset = .depth1 depthPreset = .depth1
shapePreset = .circle shapePreset = .circle
pulseAnimation = .centerWithBacking
backgroundColor = .white backgroundColor = .white
} }
} }
...@@ -41,17 +41,6 @@ public enum FABMenuDirection: Int { ...@@ -41,17 +41,6 @@ public enum FABMenuDirection: Int {
@objc(FABMenuDelegate) @objc(FABMenuDelegate)
public protocol FABMenuDelegate { public protocol FABMenuDelegate {
/** /**
A delegation method that is executed when the user taps while
the menu is opened.
- Parameter fabMenu: A FABMenu.
- Parameter tappedAt point: A CGPoint.
- Parameter isOutside: A boolean indicating whether the tap
was outside the menu button area.
*/
@objc
optional func fabMenu(fabMenu: FABMenu, tappedAt point: CGPoint, isOutside: Bool)
/**
A delegation method that is execited when the menu will open. A delegation method that is execited when the menu will open.
- Parameter fabMenu: A FABMenu. - Parameter fabMenu: A FABMenu.
*/ */
...@@ -78,6 +67,17 @@ public protocol FABMenuDelegate { ...@@ -78,6 +67,17 @@ public protocol FABMenuDelegate {
*/ */
@objc @objc
optional func fabMenuDidClose(fabMenu: FABMenu) optional func fabMenuDidClose(fabMenu: FABMenu)
/**
A delegation method that is executed when the user taps while
the menu is opened.
- Parameter fabMenu: A FABMenu.
- Parameter tappedAt point: A CGPoint.
- Parameter isOutside: A boolean indicating whether the tap
was outside the menu button area.
*/
@objc
optional func fabMenu(fabMenu: FABMenu, tappedAt point: CGPoint, isOutside: Bool)
} }
...@@ -148,7 +148,7 @@ open class FABMenu: View, SpringableMotion { ...@@ -148,7 +148,7 @@ open class FABMenu: View, SpringableMotion {
} }
/// A boolean indicating if the menu is enabled. /// A boolean indicating if the menu is enabled.
open var isEnable: Bool { open var isEnabled: Bool {
get { get {
return spring.isEnabled return spring.isEnabled
} }
...@@ -202,7 +202,7 @@ extension FABMenu { ...@@ -202,7 +202,7 @@ extension FABMenu {
- Parameter animations: An animation block to execute on each view's animation. - Parameter animations: An animation block to execute on each view's animation.
- Parameter completion: A completion block to execute on each view's animation. - Parameter completion: A completion block to execute on each view's animation.
*/ */
open func open(duration: TimeInterval = 0.15, delay: TimeInterval = 0, usingSpringWithDamping: CGFloat = 0.5, initialSpringVelocity: CGFloat = 0, options: UIViewAnimationOptions = [], animations: ((UIView) -> Void)? = nil, completion: ((UIView) -> Void)? = nil) { fileprivate func open(duration: TimeInterval = 0.15, delay: TimeInterval = 0, usingSpringWithDamping: CGFloat = 0.5, initialSpringVelocity: CGFloat = 0, options: UIViewAnimationOptions = [], animations: ((UIView) -> Void)? = nil, completion: ((UIView) -> Void)? = nil) {
spring.expand(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations, completion: completion) spring.expand(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations, completion: completion)
} }
...@@ -216,7 +216,7 @@ extension FABMenu { ...@@ -216,7 +216,7 @@ extension FABMenu {
- Parameter animations: An animation block to execute on each view's animation. - Parameter animations: An animation block to execute on each view's animation.
- Parameter completion: A completion block to execute on each view's animation. - Parameter completion: A completion block to execute on each view's animation.
*/ */
open func close(duration: TimeInterval = 0.15, delay: TimeInterval = 0, usingSpringWithDamping: CGFloat = 0.5, initialSpringVelocity: CGFloat = 0, options: UIViewAnimationOptions = [], animations: ((UIView) -> Void)? = nil, completion: ((UIView) -> Void)? = nil) { fileprivate func close(duration: TimeInterval = 0.15, delay: TimeInterval = 0, usingSpringWithDamping: CGFloat = 0.5, initialSpringVelocity: CGFloat = 0, options: UIViewAnimationOptions = [], animations: ((UIView) -> Void)? = nil, completion: ((UIView) -> Void)? = nil) {
spring.contract(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations, completion: completion) spring.contract(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations, completion: completion)
} }
} }
...@@ -229,7 +229,7 @@ extension FABMenu { ...@@ -229,7 +229,7 @@ extension FABMenu {
- Returns: An optional UIView. - Returns: An optional UIView.
*/ */
open override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { open override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
guard spring.isOpened, spring.isEnabled else { guard isOpened, isEnabled else {
return super.hitTest(point, with: event) return super.hitTest(point, with: event)
} }
...@@ -267,8 +267,9 @@ extension FABMenu { ...@@ -267,8 +267,9 @@ extension FABMenu {
extension FABMenu { extension FABMenu {
/// Opens the menu and reveals the FABMenuItems. /// Opens the menu and reveals the FABMenuItems.
fileprivate func openMenu() { open func openMenu() {
delegate?.fabMenuWillOpen?(fabMenu: self) delegate?.fabMenuWillOpen?(fabMenu: self)
open { [weak self] (view) in open { [weak self] (view) in
guard let s = self else { guard let s = self else {
return return
...@@ -283,8 +284,9 @@ extension FABMenu { ...@@ -283,8 +284,9 @@ extension FABMenu {
} }
/// Closes the menu and hides the FABMenuItems. /// Closes the menu and hides the FABMenuItems.
fileprivate func closeMenu() { open func closeMenu() {
delegate?.fabMenuWillClose?(fabMenu: self) delegate?.fabMenuWillClose?(fabMenu: self)
close { [weak self] (view) in close { [weak self] (view) in
guard let s = self else { guard let s = self else {
return return
......
...@@ -30,6 +30,11 @@ ...@@ -30,6 +30,11 @@
import UIKit import UIKit
public enum FABMenuBacking {
case fade
case blur
}
extension UIViewController { extension UIViewController {
/** /**
A convenience property that provides access to the FABMenuController. A convenience property that provides access to the FABMenuController.
...@@ -53,6 +58,15 @@ open class FABMenuController: RootController { ...@@ -53,6 +58,15 @@ open class FABMenuController: RootController {
@IBInspectable @IBInspectable
open let fabMenu = FABMenu() open let fabMenu = FABMenu()
/// A FABMenuBacking value type.
open var fabMenuBacking = FABMenuBacking.blur
/// The fabMenuBacking UIBlurEffectStyle.
open var fabMenuBackingBlurEffectStyle = UIBlurEffectStyle.light
/// A reference to the blurView.
open fileprivate(set) var blurView: UIView?
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
rootViewController.view.frame = view.bounds rootViewController.view.frame = view.bounds
...@@ -80,55 +94,104 @@ extension FABMenuController { ...@@ -80,55 +94,104 @@ extension FABMenuController {
} }
} }
extension FABMenuController {
/// Shows the fabMenuBacking.
fileprivate func showFabMenuBacking() {
showFade()
showBlurView()
}
/// Hides the fabMenuBacking.
fileprivate func hideFabMenuBacking() {
hideFade()
hideBlurView()
}
/// Shows the blurView.
fileprivate func showBlurView() {
guard .blur == fabMenuBacking else {
return
}
guard !fabMenu.isOpened, fabMenu.isEnabled else {
return
}
guard nil == blurView else {
return
}
let blur = UIVisualEffectView(effect: UIBlurEffect(style: fabMenuBackingBlurEffectStyle))
blurView = UIView()
blurView?.layout(blur).edges()
view.layout(blurView!).edges()
view.bringSubview(toFront: fabMenu)
}
/// Hides the blurView.
fileprivate func hideBlurView() {
guard fabMenu.isOpened, fabMenu.isEnabled else {
return
}
blurView?.removeFromSuperview()
blurView = nil
}
/// Shows the fade.
fileprivate func showFade() {
guard .fade == fabMenuBacking else {
return
}
guard !fabMenu.isOpened, fabMenu.isEnabled else {
return
}
UIView.animate(withDuration: 0.15, animations: { [weak self] in
self?.rootViewController.view.alpha = 0.15
})
}
/// Hides the fade.
fileprivate func hideFade() {
guard fabMenu.isOpened, fabMenu.isEnabled else {
return
}
UIView.animate(withDuration: 0.15, animations: { [weak self] in
self?.rootViewController.view.alpha = 1
})
}
}
extension FABMenuController: FABMenuDelegate { extension FABMenuController: FABMenuDelegate {
@objc
open func fabMenuWillOpen(fabMenu: FABMenu) {
isUserInteractionEnabled = false
showFabMenuBacking()
}
// /** @objc
// Opens the menu with a callback. open func fabMenuDidOpen(fabMenu: FABMenu) {
// - Parameter completion: An Optional callback that is executed when isUserInteractionEnabled = true
// all menu items have been opened. }
// */
// open func openMenu(completion: ((UIView) -> Void)? = nil) { @objc
// if true == isUserInteractionEnabled { open func fabMenuWillClose(fabMenu: FABMenu) {
// isUserInteractionEnabled = false isUserInteractionEnabled = false
// hideFabMenuBacking()
// UIView.animate(withDuration: 0.15, animations: { [weak self] in }
// guard let s = self else {
// return @objc
// } open func fabMenuDidClose(fabMenu: FABMenu) {
// s.rootViewController.view.alpha = 0.15 isUserInteractionEnabled = true
// }) }
//
// fabMenu.open { [completion = completion] (view) in @objc
// completion?(view) open func fabMenu(fabMenu: FABMenu, tappedAt point: CGPoint, isOutside: Bool) {
// } guard isOutside else {
// } return
// } }
// }
// /**
// Opens the menu with a callback.
// - Parameter completion: An Optional callback that is executed when
// all menu items have been closed.
// */
// open func closeMenu(completion: ((UIView) -> Void)? = nil) {
// if false == isUserInteractionEnabled {
// UIView.animate(withDuration: 0.15, animations: { [weak self] in
// guard let s = self else {
// return
// }
// s.rootViewController.view.alpha = 1
// })
//
// fabMenu.close { [weak self] (view) in
// guard let s = self else {
// return
// }
//
// completion?(view)
//
// if view == s.fabMenu.items.last {
// s.isUserInteractionEnabled = true
// }
// }
// }
// }
} }
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