Skip to content

Commit

Permalink
Issue fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
luannguyenkhoa-agilityio committed Jul 5, 2018
1 parent ae4de65 commit 45a18e0
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 34 deletions.
8 changes: 7 additions & 1 deletion Example/LNSideMenu/ContentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ class ContentViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
/// Should set the below flag here to avoid its value gets changed while doing interactivePopGestureRecognizer
// Disable sidemene
sideMenuManager?.sideMenuController()?.sideMenu?.disabled = true
sideMenuManager?.instance()?.menu?.disabled = true
}

}
3 changes: 2 additions & 1 deletion Example/LNSideMenu/NextViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class NextViewController: UIViewController {
super.viewDidLoad()

// Do any additional setup after loading the view.
sideMenuManager?.instance()?.menu?.disabled = true
}

override func viewWillAppear(_ animated: Bool) {
Expand All @@ -39,7 +40,7 @@ class NextViewController: UIViewController {
// Revert navigation bar translucent style to default
navigationBarNonTranslecentStyle()
// Update side menu after reverted navigation bar style
sideMenuManager?.sideMenuController()?.sideMenu?.isNavbarHiddenOrTransparent = false
sideMenuManager?.instance()?.menu?.isNavbarHiddenOrTransparent = false
navigationItem.hidesBackButton = true
}

Expand Down
28 changes: 14 additions & 14 deletions Example/LNSideMenu/SMNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SMNavigationController: LNSideMenuNavigationController {
items = ["All","Hot Food","Sandwiches","Hot Pots","Hot Rolls", "Salads","Pies","Dessrts","Drinks","Breakfast","Cookies","Lunch fers"]
initialSideMenu(.left)
// Custom side menu
// initialCustomMenu(pos: .right)
// initialCustomMenu(pos: .left)
}

override func didReceiveMemoryWarning() {
Expand All @@ -29,21 +29,21 @@ class SMNavigationController: LNSideMenuNavigationController {
}

fileprivate func initialSideMenu(_ position: Position) {
sideMenu = LNSideMenu(sourceView: view, menuPosition: position, items: items!)
sideMenu?.menuViewController?.menuBgColor = UIColor.black.withAlphaComponent(0.85)
sideMenu?.delegate = self
sideMenu?.underNavigationBar = true
menu = LNSideMenu(sourceView: view, menuPosition: position, items: items!)
menu?.menuViewController?.menuBgColor = UIColor.black.withAlphaComponent(0.85)
menu?.delegate = self
menu?.underNavigationBar = true
view.bringSubview(toFront: navigationBar)
}

fileprivate func initialCustomMenu(pos position: Position) {
let menu = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "LeftMenuTableViewController") as! LeftMenuTableViewController
menu.delegate = self
sideMenu = LNSideMenu(navigation: self, menuPosition: position, customSideMenu: menu)
sideMenu?.delegate = self
sideMenu?.enableDynamic = true
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "LeftMenuTableViewController") as! LeftMenuTableViewController
vc.delegate = self
menu = LNSideMenu(navigation: self, menuPosition: position, customSideMenu: vc)
menu?.delegate = self
menu?.enableDynamic = true
// Moving down the menu view under navigation bar
sideMenu?.underNavigationBar = true
menu?.underNavigationBar = true
}

fileprivate func setContentVC(_ index: Int) {
Expand All @@ -58,8 +58,8 @@ class SMNavigationController: LNSideMenuNavigationController {
self.setContentViewController(viewController)
}
// Test moving up/down the menu view
if let sm = sideMenu, sm.isCustomMenu {
sideMenu?.underNavigationBar = false
if let sm = menu, sm.isCustomMenu {
menu?.underNavigationBar = false
}
}
}
Expand Down Expand Up @@ -88,7 +88,7 @@ extension SMNavigationController: LNSideMenuDelegate {

extension SMNavigationController: LeftMenuDelegate {
func didSelectItemAtIndex(index idx: Int) {
sideMenu?.toggleMenu() { [unowned self] in
menu?.toggleMenu() { [unowned self] in
self.setContentVC(idx)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Example/LNSideMenu/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class ViewController: UIViewController {
// Set navigation bar translucent style
self.navigationBarTranslucentStyle()
// Update side menu
sideMenuManager?.sideMenuController()?.sideMenu?.isNavbarHiddenOrTransparent = true
sideMenuManager?.instance()?.menu?.isNavbarHiddenOrTransparent = true
// Re-enable sidemenu
sideMenuManager?.sideMenuController()?.sideMenu?.disabled = false
sideMenuManager?.instance()?.menu?.disabled = false
}

@IBAction func toogleSideMenu(_ sender: AnyObject) {
Expand Down
2 changes: 1 addition & 1 deletion LNSideMenu.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'LNSideMenu'
s.version = '3.2'
s.version = '3.3'
s.summary = 'A side menu control for iOS in Swift with custom layer and scrolling effect. Right and Left sides. iOS 8+.'

# This description is used to generate tags and improve search results.
Expand Down
6 changes: 3 additions & 3 deletions LNSideMenu/Classes/LNCommon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public enum LNColor {
// MARK: Protocols

public protocol LNSideMenuProtocol {
var sideMenu: LNSideMenu?{get}
var sideMenuAnimationType: LNSideMenuAnimation {get set}
var menu: LNSideMenu?{get}
var animationType: LNSideMenuAnimation {get set}
func setContentViewController(_ contentViewController: UIViewController)
}

Expand All @@ -96,7 +96,7 @@ internal protocol LNSMDelegate: class {

public protocol LNSideMenuManager {

mutating func sideMenuController()-> LNSideMenuProtocol?
mutating func instance()-> LNSideMenuProtocol?
mutating func toggleSideMenuView()
mutating func hideSideMenuView()
mutating func showSideMenuView()
Expand Down
16 changes: 14 additions & 2 deletions LNSideMenu/Classes/LNSideMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ public final class LNSideMenu: NSObject {
}

open var tapOutsideToDismiss = true
open var disabled: Bool = false
open var disabled: Bool = false {
didSet {
print("Reset Flag")
}
}
open var enableAnimation: Bool = true
open var customMenu: UIViewController?
open var isCustomMenu: Bool {
Expand Down Expand Up @@ -224,7 +228,7 @@ public final class LNSideMenu: NSObject {
// MARK: Gesture handlers

@objc internal func handlePanGesture(_ gesture: UIPanGestureRecognizer) {

guard !disabled else { return }
let leftToRight = gesture.velocity(in: gesture.view).x > 0
switch gesture.state {
case .began:
Expand Down Expand Up @@ -277,6 +281,14 @@ public final class LNSideMenu: NSObject {
toggleMenu()
}
} else {
if let touch = sideMenuContainerView.subviews.first?.subviews.first as? LNSideMenuView {
if let scrollView = touch.subviews.filter({ $0 is UIScrollView }).first {
let bounds = scrollView.convert(scrollView.bounds, to: sideMenuContainerView)
if bounds.contains(gesture.location(in: sideMenuContainerView)) {
return
}
}
}
toggleMenu()
}
}
Expand Down
12 changes: 6 additions & 6 deletions LNSideMenu/Classes/LNSideMenuMangement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,35 @@ public struct LNSideMenuManagement: LNSideMenuManager {
return self.getSideMenuController()
}()

mutating public func sideMenuController() -> LNSideMenuProtocol? {
mutating public func instance() -> LNSideMenuProtocol? {
return self.lazySideMenuController
}

/**
Changes current state of side menu view
*/
public mutating func toggleSideMenuView() {
lazySideMenuController?.sideMenu?.toggleMenu()
lazySideMenuController?.menu?.toggleMenu()
}
/**
Hides the side menu view
*/
public mutating func hideSideMenuView() {
lazySideMenuController?.sideMenu?.hideSideMenu()
lazySideMenuController?.menu?.hideSideMenu()
}
/**
Shows the side menu view
*/
public mutating func showSideMenuView() {
lazySideMenuController?.sideMenu?.showSideMenu()
lazySideMenuController?.menu?.showSideMenu()
}
/**
Returns a Bool value indicating whether the side menu is showed

- returns: Bool value
*/
public mutating func isSideMenuOpen() -> Bool {
guard let sideMenu = lazySideMenuController?.sideMenu else {
guard let sideMenu = lazySideMenuController?.menu else {
return false
}
return sideMenu.isMenuOpen
Expand All @@ -59,7 +59,7 @@ public struct LNSideMenuManagement: LNSideMenuManager {
*/
public func fixSideMenuSize() {
if let navController = viewController?.navigationController as? LNSideMenuNavigationController {
navController.sideMenu?.updateFrame()
navController.menu?.updateFrame()
}
}
/**
Expand Down
8 changes: 4 additions & 4 deletions LNSideMenu/Classes/LNSideMenuNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import UIKit

open class LNSideMenuNavigationController: UINavigationController, LNSideMenuProtocol {

open var sideMenu: LNSideMenu?
open var sideMenuAnimationType: LNSideMenuAnimation = .default
open var menu: LNSideMenu?
open var animationType: LNSideMenuAnimation = .default

open override func viewDidLoad() {
super.viewDidLoad()
}

open func setContentViewController(_ contentViewController: UIViewController) {
// Hide side menu at the first
sideMenu?.hideSideMenu()
menu?.hideSideMenu()
// Add contentViewController within default animation or none
switch sideMenuAnimationType {
switch animationType {
case .none:
self.viewControllers = [contentViewController]
break
Expand Down
1 change: 1 addition & 0 deletions LNSideMenu/Classes/LNSideMenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ internal final class LNSideMenuView: UIView, UIScrollViewDelegate {
let dest = abs(index-currentIndex)
let sum = (0..<dest).reduce(0, { $0 + $1*kNumberAriProg })
let originX = (right ? 1 : -1) * CGFloat(sum + kNumberDefaultItemsHoziConstant*dest)
print(originX)
let itemFrame = CGRect(x: originX, y: CGFloat(index*Int(kNumberDefaultItemHeight)), width: menusScrollView.width, height: kNumberDefaultItemHeight)

// Initial item by index
Expand Down

0 comments on commit 45a18e0

Please sign in to comment.