Skip to content

Commit

Permalink
Merge pull request #64 from Yalantis/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
rnkyr committed Jan 29, 2018
2 parents 6ad93cc + f3d9a24 commit 7cf0e9b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,29 @@ public protocol ColorMatchTabsViewControllerDataSource: class {

}

public protocol ColorMatchTabsViewControllerDelegate: class {

func didSelectItemAt(_ index: Int)

}

extension ColorMatchTabsViewControllerDelegate {

func didSelectItemAt(_ index: Int) {}

}

open class ColorMatchTabsViewController: UITabBarController {

@IBInspectable open weak var dataSource: ColorMatchTabsViewControllerDataSource? {
@IBInspectable open weak var colorMatchTabDataSource: ColorMatchTabsViewControllerDataSource? {
didSet {
_view.scrollMenu.dataSource = dataSource == nil ? nil : self
_view.tabs.dataSource = dataSource == nil ? nil : self
_view.scrollMenu.dataSource = colorMatchTabDataSource == nil ? nil : self
_view.tabs.dataSource = colorMatchTabDataSource == nil ? nil : self
}
}

@IBInspectable open weak var colorMatchTabDelegate: ColorMatchTabsViewControllerDelegate?

@IBInspectable open var scrollEnabled = true {
didSet {
updateScrollEnabled()
Expand Down Expand Up @@ -109,7 +123,7 @@ open class ColorMatchTabsViewController: UITabBarController {
private extension ColorMatchTabsViewController {

func setupIcons() {
guard let dataSource = dataSource else {
guard let dataSource = colorMatchTabDataSource else {
return
}

Expand Down Expand Up @@ -155,7 +169,7 @@ private extension ColorMatchTabsViewController {
}

func updateNavigationBar(forSelectedIndex index: Int) {
let color = dataSource?.tabsViewController(self, tintColorAt: index) ?? .white
let color = colorMatchTabDataSource?.tabsViewController(self, tintColorAt: index) ?? .white

titleLabel.textColor = color
_view.scrollMenu.backgroundColor = color.withAlphaComponent(0.2)
Expand Down Expand Up @@ -185,9 +199,9 @@ private extension ColorMatchTabsViewController {

let image: UIImage?
if index == self._view.tabs.selectedSegmentIndex {
image = self.dataSource?.tabsViewController(self, hightlightedIconAt: index)
image = self.colorMatchTabDataSource?.tabsViewController(self, hightlightedIconAt: index)
} else {
image = self.dataSource?.tabsViewController(self, iconAt: index)
image = self.colorMatchTabDataSource?.tabsViewController(self, iconAt: index)
}
iconImageView.image = image
},
Expand Down Expand Up @@ -220,7 +234,7 @@ private extension ColorMatchTabsViewController {
initialSpringVelocity: 3,
options: [],
animations: {
iconImageView.image = self.dataSource?.tabsViewController(self, hightlightedIconAt: index)
iconImageView.image = self.colorMatchTabDataSource?.tabsViewController(self, hightlightedIconAt: index)
iconImageView.center = CGPoint(
x: iconImageView.center.x,
y: iconImageView.center.y + self.view.frame.height / 2
Expand Down Expand Up @@ -261,6 +275,7 @@ extension ColorMatchTabsViewController: ScrollMenuDelegate {
if _view.tabs.selectedSegmentIndex != index {
_view.tabs.selectedSegmentIndex = index
}
colorMatchTabDelegate?.didSelectItemAt(index)
}

}
Expand Down Expand Up @@ -292,63 +307,63 @@ extension ColorMatchTabsViewController: UIViewControllerTransitioningDelegate {
extension ColorMatchTabsViewController: ColorTabsDataSource {

open func numberOfItems(inTabSwitcher tabSwitcher: ColorTabs) -> Int {
return dataSource?.numberOfItems(inController: self) ?? 0
return colorMatchTabDataSource?.numberOfItems(inController: self) ?? 0
}

open func tabSwitcher(_ tabSwitcher: ColorTabs, titleAt index: Int) -> String {
return dataSource!.tabsViewController(self, titleAt: index)
return colorMatchTabDataSource!.tabsViewController(self, titleAt: index)
}

open func tabSwitcher(_ tabSwitcher: ColorTabs, iconAt index: Int) -> UIImage {
return dataSource!.tabsViewController(self, iconAt: index)
return colorMatchTabDataSource!.tabsViewController(self, iconAt: index)
}

open func tabSwitcher(_ tabSwitcher: ColorTabs, hightlightedIconAt index: Int) -> UIImage {
return dataSource!.tabsViewController(self, hightlightedIconAt: index)
return colorMatchTabDataSource!.tabsViewController(self, hightlightedIconAt: index)
}

open func tabSwitcher(_ tabSwitcher: ColorTabs, tintColorAt index: Int) -> UIColor {
return dataSource!.tabsViewController(self, tintColorAt: index)
return colorMatchTabDataSource!.tabsViewController(self, tintColorAt: index)
}

}

extension ColorMatchTabsViewController: ScrollMenuDataSource {

open func numberOfItemsInScrollMenu(_ scrollMenu: ScrollMenu) -> Int {
return dataSource?.numberOfItems(inController: self) ?? 0
return colorMatchTabDataSource?.numberOfItems(inController: self) ?? 0
}

open func scrollMenu(_ scrollMenu: ScrollMenu, viewControllerAtIndex index: Int) -> UIViewController {
return dataSource!.tabsViewController(self, viewControllerAt: index)
return colorMatchTabDataSource!.tabsViewController(self, viewControllerAt: index)
}

}

extension ColorMatchTabsViewController: CircleMenuDataSource {

open func numberOfItems(inMenu circleMenu: CircleMenu) -> Int {
return dataSource?.numberOfItems(inController: self) ?? 0
return colorMatchTabDataSource?.numberOfItems(inController: self) ?? 0
}

open func circleMenu(_ circleMenu: CircleMenu, tintColorAt index: Int) -> UIColor {
return dataSource!.tabsViewController(self, tintColorAt: index)
return colorMatchTabDataSource!.tabsViewController(self, tintColorAt: index)
}

}

extension ColorMatchTabsViewController: PopoverViewControllerDataSource {

open func numberOfItems(inPopoverViewController popoverViewController: PopoverViewController) -> Int {
return dataSource?.numberOfItems(inController: self) ?? 0
return colorMatchTabDataSource?.numberOfItems(inController: self) ?? 0
}

open func popoverViewController(_ popoverViewController: PopoverViewController, iconAt index: Int) -> UIImage {
return dataSource!.tabsViewController(self, iconAt: index)
return colorMatchTabDataSource!.tabsViewController(self, iconAt: index)
}

open func popoverViewController(_ popoverViewController: PopoverViewController, hightlightedIconAt index: Int) -> UIImage {
return dataSource!.tabsViewController(self, hightlightedIconAt: index)
return colorMatchTabDataSource!.tabsViewController(self, hightlightedIconAt: index)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ExampleViewContoller: ColorMatchTabsViewController {
popoverViewController = ExamplePopoverViewController()
popoverViewController?.delegate = self

dataSource = self
colorMatchTabDataSource = self
reloadData()
}

Expand Down

0 comments on commit 7cf0e9b

Please sign in to comment.