Commit 5a438b88 by Daniel Dahan

development: added blur and fade backing types for FABMenuController

parent 42b6d525
......@@ -42,6 +42,7 @@ open class FABButton: Button {
super.prepare()
depthPreset = .depth1
shapePreset = .circle
pulseAnimation = .centerWithBacking
backgroundColor = .white
}
}
......@@ -41,17 +41,6 @@ public enum FABMenuDirection: Int {
@objc(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.
- Parameter fabMenu: A FABMenu.
*/
......@@ -78,6 +67,17 @@ public protocol FABMenuDelegate {
*/
@objc
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 {
}
/// A boolean indicating if the menu is enabled.
open var isEnable: Bool {
open var isEnabled: Bool {
get {
return spring.isEnabled
}
......@@ -202,7 +202,7 @@ extension FABMenu {
- Parameter animations: An animation 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)
}
......@@ -216,7 +216,7 @@ extension FABMenu {
- Parameter animations: An animation 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)
}
}
......@@ -229,7 +229,7 @@ extension FABMenu {
- Returns: An optional 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)
}
......@@ -267,8 +267,9 @@ extension FABMenu {
extension FABMenu {
/// Opens the menu and reveals the FABMenuItems.
fileprivate func openMenu() {
open func openMenu() {
delegate?.fabMenuWillOpen?(fabMenu: self)
open { [weak self] (view) in
guard let s = self else {
return
......@@ -283,8 +284,9 @@ extension FABMenu {
}
/// Closes the menu and hides the FABMenuItems.
fileprivate func closeMenu() {
open func closeMenu() {
delegate?.fabMenuWillClose?(fabMenu: self)
close { [weak self] (view) in
guard let s = self else {
return
......
......@@ -30,6 +30,11 @@
import UIKit
public enum FABMenuBacking {
case fade
case blur
}
extension UIViewController {
/**
A convenience property that provides access to the FABMenuController.
......@@ -53,6 +58,15 @@ open class FABMenuController: RootController {
@IBInspectable
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() {
super.layoutSubviews()
rootViewController.view.frame = view.bounds
......@@ -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 {
@objc
open func fabMenuWillOpen(fabMenu: FABMenu) {
isUserInteractionEnabled = false
showFabMenuBacking()
}
// /**
// Opens the menu with a callback.
// - Parameter completion: An Optional callback that is executed when
// all menu items have been opened.
// */
// open func openMenu(completion: ((UIView) -> Void)? = nil) {
// if true == isUserInteractionEnabled {
// isUserInteractionEnabled = false
//
// UIView.animate(withDuration: 0.15, animations: { [weak self] in
// guard let s = self else {
// return
// }
// s.rootViewController.view.alpha = 0.15
// })
//
// fabMenu.open { [completion = completion] (view) in
// completion?(view)
// }
// }
// }
//
// /**
// 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
// }
// }
// }
// }
@objc
open func fabMenuDidOpen(fabMenu: FABMenu) {
isUserInteractionEnabled = true
}
@objc
open func fabMenuWillClose(fabMenu: FABMenu) {
isUserInteractionEnabled = false
hideFabMenuBacking()
}
@objc
open func fabMenuDidClose(fabMenu: FABMenu) {
isUserInteractionEnabled = true
}
@objc
open func fabMenu(fabMenu: FABMenu, tappedAt point: CGPoint, isOutside: Bool) {
guard isOutside else {
return
}
}
}
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