Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ary-ios into develop
  • Loading branch information
alejandrojimenez committed Feb 25, 2017
2 parents 3716195 + 958ac59 commit 0e0239f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
6 changes: 5 additions & 1 deletion Source/UIComponents/SlideMenu/MenuSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ open class MenuSection {
open let icon: UIImage
open let storyboard: String
open let viewController: String?
open var modeButtonType: Bool?
open var completionButtonType: (() -> Void)?

lazy var sectionController: UIViewController = self.instantiateViewController()


public init(name: String, icon: UIImage, storyboard: String, viewController: String? = nil) {
public init(name: String, icon: UIImage, storyboard: String, viewController: String? = nil, modeButtonType: Bool? = nil, completionButtonType: (() -> Void)? = nil) {
self.name = name
self.icon = icon
self.storyboard = storyboard
self.viewController = viewController
self.modeButtonType = modeButtonType
self.completionButtonType = completionButtonType
}


Expand Down
26 changes: 16 additions & 10 deletions Source/UIComponents/SlideMenu/Private/MenuSectionCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MenuSectionCell: UITableViewCell {
@IBOutlet weak fileprivate var imageMenuSection: UIImageView!
@IBOutlet weak fileprivate var labelMenuSection: UILabel!
@IBOutlet weak fileprivate var viewSelector: UIView!

override func awakeFromNib() {
self.viewSelector.backgroundColor = SlideMenuConfig.shared.sectionSelectorColor
Expand All @@ -23,21 +23,27 @@ class MenuSectionCell: UITableViewCell {
func bindMenuSection(_ menuSection: MenuSection) {
self.labelMenuSection.text = menuSection.name
self.imageMenuSection.image = menuSection.icon
self.viewSelector.alpha = 0

guard let modeButtonType = menuSection.modeButtonType else {
return
}

if modeButtonType {
self.viewSelector.backgroundColor = UIColor.clear
} else {
self.viewSelector.backgroundColor = SlideMenuConfig.shared.sectionSelectorColor
}
}


override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

UIView.animate(withDuration: 0.4, animations: {
if selected {
self.viewSelector.alpha = 1
}
else {
self.viewSelector.alpha = 0
}
})
if selected {
self.viewSelector.alpha = 1
} else {
self.viewSelector.alpha = 0
}
}

}
15 changes: 13 additions & 2 deletions Source/UIComponents/SlideMenu/Private/SlideMenuTableVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class SlideMenuTableVC: UIViewController, UITableViewDataSource, UITableViewDele
// MARK - Public Methods

func selectSection(_ index: Int) {
self.indexToShow = index
guard self.tableView != nil else {
self.indexToShow = index
return
}

Expand Down Expand Up @@ -94,6 +94,17 @@ class SlideMenuTableVC: UIViewController, UITableViewDataSource, UITableViewDele
}

delegate.tableDidSelecteSection(menuSection, index: (indexPath as NSIndexPath).row)

guard let modeButtonType = menuSection.modeButtonType else {
self.indexToShow = indexPath.row
return
}

if modeButtonType {
guard let index = self.indexToShow else {
return
}
self.selectSection(index)
}
}

}
15 changes: 12 additions & 3 deletions Source/UIComponents/SlideMenu/Private/SlideMenuVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class SlideMenuVC: UIViewController, MenuTableDelegate, UIGestureRecognizerDeleg

if let index = self.sectionIndexToShow {
self.menuTableView?.selectSection(index)
self.sectionIndexToShow = nil
}
}

Expand Down Expand Up @@ -225,8 +224,18 @@ class SlideMenuVC: UIViewController, MenuTableDelegate, UIGestureRecognizerDeleg
// MARK: - MenuTableDelegate

func tableDidSelecteSection(_ menuSection: MenuSection, index: Int) {
self.setSection(menuSection.sectionController, index: index)
self.animate(closeMenu)

guard let _ = menuSection.modeButtonType else {
self.setSection(menuSection.sectionController, index: index)
self.animate(closeMenu)
return
}

guard let completion = menuSection.completionButtonType else {
LogWarn("completion Button Type nil!")
return
}
completion()
}


Expand Down

0 comments on commit 0e0239f

Please sign in to comment.