Commit 886ee171 by Daniel Dahan

development: added internal handlers for callback communication between FABMenu…

development: added internal handlers for callback communication between FABMenu and FABMenuController
parent 62f29b52
......@@ -221,6 +221,15 @@ open class FABMenu: View {
/// An internal handler for the FABButton.
internal var handleFABButtonCallback: ((UIButton) -> Void)?
/// An internal handler for the open function.
internal var handleOpenCallback: (() -> Void)?
/// An internal handler for the close function.
internal var handleCloseCallback: (() -> Void)?
/// An internal handler for the completion function.
internal var handleCompletionCallback: ((UIView) -> Void)?
/// Size of FABMenuItems.
open var fabMenuItemSize: CGSize {
get {
......@@ -333,6 +342,8 @@ extension FABMenu {
- Parameter completion: A completion block to execute on each view's animation.
*/
internal func open(isTriggeredByUserInteraction: Bool, duration: TimeInterval = 0.15, delay: TimeInterval = 0, usingSpringWithDamping: CGFloat = 0.5, initialSpringVelocity: CGFloat = 0, options: UIViewAnimationOptions = [], animations: ((UIView) -> Void)? = nil, completion: ((UIView) -> Void)? = nil) {
handleOpenCallback?()
if isTriggeredByUserInteraction {
delegate?.fabMenuWillOpen?(fabMenu: self)
}
......@@ -349,6 +360,7 @@ extension FABMenu {
}
completion?(view)
s.handleCompletionCallback?(view)
}
}
......@@ -379,6 +391,8 @@ extension FABMenu {
- Parameter completion: A completion block to execute on each view's animation.
*/
internal func close(isTriggeredByUserInteraction: Bool, duration: TimeInterval = 0.15, delay: TimeInterval = 0, usingSpringWithDamping: CGFloat = 0.5, initialSpringVelocity: CGFloat = 0, options: UIViewAnimationOptions = [], animations: ((UIView) -> Void)? = nil, completion: ((UIView) -> Void)? = nil) {
handleCloseCallback?()
if isTriggeredByUserInteraction {
delegate?.fabMenuWillClose?(fabMenu: self)
}
......@@ -395,6 +409,7 @@ extension FABMenu {
}
completion?(view)
s.handleCompletionCallback?(view)
}
}
}
......
......@@ -93,7 +93,10 @@ extension FABMenuController {
fileprivate func prepareFABMenu() {
fabMenu.delegate = self
fabMenu.zPosition = 1000
fabMenu.handleFABButtonCallback = handleFABButton
fabMenu.handleFABButtonCallback = handleFABButtonCallback
fabMenu.handleOpenCallback = handleOpenCallback
fabMenu.handleCloseCallback = handleCloseCallback
fabMenu.handleCompletionCallback = handleCompletionCallback
view.addSubview(fabMenu)
}
}
......@@ -183,24 +186,34 @@ extension FABMenuController {
- Parameter button: A UIButton.
*/
@objc
fileprivate func handleFABButton(button: UIButton) {
fileprivate func handleFABButtonCallback(button: UIButton) {
guard fabMenu.isOpened else {
isUserInteractionEnabled = false
showFabMenuBacking()
fabMenu.open(isTriggeredByUserInteraction: true, completion: handleCompletion)
fabMenu.open(isTriggeredByUserInteraction: true)
return
}
fabMenu.close(isTriggeredByUserInteraction: true)
}
/// Handler for when the FABMenu.open function is called.
@objc
fileprivate func handleOpenCallback() {
isUserInteractionEnabled = false
showFabMenuBacking()
}
/// Handler for when the FABMenu.close function is called.
@objc
fileprivate func handleCloseCallback() {
isUserInteractionEnabled = false
hideFabMenuBacking()
fabMenu.close(isTriggeredByUserInteraction: true, completion: handleCompletion)
}
/**
Completion handler for FABMenu open and close calls.
- Parameter view: A UIView.
*/
fileprivate func handleCompletion(view: UIView) {
fileprivate func handleCompletionCallback(view: UIView) {
if view == fabMenu.fabMenuItems.last {
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