Commit dd741ff0 by Daniel Dahan Committed by GitHub

Merge pull request #1046 from mjurenka/master

added ShouldOpen and ShouldClose delegate methods to FABMenuDelegate
parents e8691249 854e9057
...@@ -140,6 +140,13 @@ extension FABMenuItem { ...@@ -140,6 +140,13 @@ extension FABMenuItem {
@objc(FABMenuDelegate) @objc(FABMenuDelegate)
public protocol FABMenuDelegate { public protocol FABMenuDelegate {
/** /**
A delegation method that is executed to determine whether fabMenu should open.
- Parameter fabMenu: A FABMenu.
*/
@objc
optional func fabMenuShouldOpen(fabMenu: FABMenu) -> Bool
/**
A delegation method that is execited when the fabMenu will open. A delegation method that is execited when the fabMenu will open.
- Parameter fabMenu: A FABMenu. - Parameter fabMenu: A FABMenu.
*/ */
...@@ -154,6 +161,13 @@ public protocol FABMenuDelegate { ...@@ -154,6 +161,13 @@ public protocol FABMenuDelegate {
optional func fabMenuDidOpen(fabMenu: FABMenu) optional func fabMenuDidOpen(fabMenu: FABMenu)
/** /**
A delegation method that is executed to determine whether fabMenu should close.
- Parameter fabMenu: A FABMenu.
*/
@objc
optional func fabMenuShouldClose(fabMenu: FABMenu) -> Bool
/**
A delegation method that is execited when the fabMenu will close. A delegation method that is execited when the fabMenu will close.
- Parameter fabMenu: A FABMenu. - Parameter fabMenu: A FABMenu.
*/ */
...@@ -364,6 +378,29 @@ extension FABMenu { ...@@ -364,6 +378,29 @@ extension FABMenu {
delegate?.fabMenuWillOpen?(fabMenu: self) delegate?.fabMenuWillOpen?(fabMenu: self)
} }
/**
Open the Menu component with animation options.
- Parameter isTriggeredByUserInteraction: A boolean indicating whether the
state was changed by a user interaction, true if yes, false otherwise.
- Parameter duration: The time for each view's animation.
- Parameter delay: A delay time for each view's animation.
- Parameter usingSpringWithDamping: A damping ratio for the animation.
- Parameter initialSpringVelocity: The initial velocity for the animation.
- Parameter options: Options to pass to the 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.
*/
open 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) {
if delegate?.fabMenuShouldOpen?(fabMenu: self) == false {
return
}
handleOpenCallback?()
if isTriggeredByUserInteraction {
delegate?.fabMenuWillOpen?(fabMenu: self)
}
spring.expand(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations) { [weak self, isTriggeredByUserInteraction = isTriggeredByUserInteraction, completion = completion] (view) in spring.expand(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations) { [weak self, isTriggeredByUserInteraction = isTriggeredByUserInteraction, completion = completion] (view) in
guard let `self` = self else { guard let `self` = self else {
return return
...@@ -379,6 +416,7 @@ extension FABMenu { ...@@ -379,6 +416,7 @@ extension FABMenu {
self.handleCompletionCallback?(view) self.handleCompletionCallback?(view)
} }
} }
}
/** /**
Close the Menu component with animation options. Close the Menu component with animation options.
...@@ -413,6 +451,29 @@ extension FABMenu { ...@@ -413,6 +451,29 @@ extension FABMenu {
delegate?.fabMenuWillClose?(fabMenu: self) delegate?.fabMenuWillClose?(fabMenu: self)
} }
/**
Close the Menu component with animation options.
- Parameter isTriggeredByUserInteraction: A boolean indicating whether the
state was changed by a user interaction, true if yes, false otherwise.
- Parameter duration: The time for each view's animation.
- Parameter delay: A delay time for each view's animation.
- Parameter usingSpringWithDamping: A damping ratio for the animation.
- Parameter initialSpringVelocity: The initial velocity for the animation.
- Parameter options: Options to pass to the 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.
*/
open 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) {
if delegate?.fabMenuShouldClose?(fabMenu: self) == false {
return
}
handleCloseCallback?()
if isTriggeredByUserInteraction {
delegate?.fabMenuWillClose?(fabMenu: self)
}
spring.contract(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations) { [weak self, isTriggeredByUserInteraction = isTriggeredByUserInteraction, completion = completion] (view) in spring.contract(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations) { [weak self, isTriggeredByUserInteraction = isTriggeredByUserInteraction, completion = completion] (view) in
guard let `self` = self else { guard let `self` = self else {
return return
...@@ -428,6 +489,7 @@ extension FABMenu { ...@@ -428,6 +489,7 @@ extension FABMenu {
self.handleCompletionCallback?(view) self.handleCompletionCallback?(view)
} }
} }
}
} }
extension FABMenu { extension FABMenu {
......
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