Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage improvements #198

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Example/SwiftSideMenu/MyNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,8 @@ extension MyNavigationController: ENSideMenuDelegate {
func sideMenuShouldOpenSideMenu() -> Bool {
return true
}

func sideMenuIsAnimating() {
print("sideMenuIsAnimating")
}
}
4 changes: 4 additions & 0 deletions Example/SwiftSideMenu/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,9 @@ class ViewController: UIViewController, ENSideMenuDelegate {
func sideMenuDidOpen() {
print("sideMenuDidOpen")
}

func sideMenuIsAnimating() {
print("sideMenuIsAnimating")
}
}

3 changes: 3 additions & 0 deletions Example/SwiftSideMenu/ViewController2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ class ViewController2: UIViewController, ENSideMenuDelegate {
return true
}

func sideMenuIsAnimating() {
print("sideMenuIsAnimating")
}
}
12 changes: 11 additions & 1 deletion Library/ENSideMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public protocol ENSideMenuDelegate: class {
func sideMenuShouldOpenSideMenu () -> Bool
func sideMenuDidOpen()
func sideMenuDidClose()
func sideMenuIsAnimating()
}

public protocol ENSideMenuProtocol: class {
Expand Down Expand Up @@ -143,13 +144,21 @@ open class ENSideMenu : NSObject, UIGestureRecognizerDelegate {
fileprivate var needUpdateApperance : Bool = false
/// The delegate of the side menu
open weak var delegate : ENSideMenuDelegate?
fileprivate(set) var isMenuOpen : Bool = false
fileprivate(set) open var isMenuOpen : Bool = false
/// A Boolean value indicating whether the left swipe is enabled.
open var allowLeftSwipe : Bool = true
/// A Boolean value indicating whether the right swipe is enabled.
open var allowRightSwipe : Bool = true
open var allowPanGesture : Bool = true
fileprivate var panRecognizer : UIPanGestureRecognizer?
open var isHidden: Bool {
get {
return sideMenuContainerView.isHidden
}
set {
sideMenuContainerView.isHidden = newValue
}
}

/**
Initializes an instance of a `ENSideMenu` object.
Expand Down Expand Up @@ -334,6 +343,7 @@ open class ENSideMenu : NSObject, UIGestureRecognizerDelegate {
withDuration: animationDuration,
animations: { [weak self] () -> Void in
self?.sideMenuContainerView.frame = destFrame
self?.delegate?.sideMenuIsAnimating()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I anticipate some unexpected side effects on the use site if the delegate method would be called inside an animation block. Instead I would suggest introducing another two delegate callbacks with an isAnimated argument and call them before scheduling the animation:
sideMenuWillOpen:isAnimated
sideMenuWillClose:isAnimated
I see this as a more universal approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point, but my specific case requries the delegate call inside the animate method so the statubar changes gradually not at once wzen animation startes or finishes.

},
completion: { [weak self] (Bool) -> Void in
guard let strongSelf = self else { return }
Expand Down