diff --git a/Example/Demo/WithURLsViewController.swift b/Example/Demo/WithURLsViewController.swift index 5ab295f..9dd4afe 100644 --- a/Example/Demo/WithURLsViewController.swift +++ b/Example/Demo/WithURLsViewController.swift @@ -95,16 +95,12 @@ extension WithURLsViewController:UICollectionViewDataSource { initialIndex: indexPath.item, options: [ .theme(.dark), - .rightNavItemTitle("Info", delegate: self) + .rightNavItemTitle("Info", onTap: { i in + print("TAPPED", i) + }) ], from: self) return cell } } - -extension WithURLsViewController:RightNavItemDelegate { - func imageViewer(_ imageViewer: ImageCarouselViewController, didTapRightNavItem index: Int) { - print("TAPPED", index) - } -} diff --git a/README.md b/README.md index 21161b4..5650db3 100644 --- a/README.md +++ b/README.md @@ -90,8 +90,8 @@ You can check this file [ImageViewerOption.swift](https://github.com/michaelhenr public enum ImageViewerOption { case theme(ImageViewerTheme) case closeIcon(UIImage) - case rightNavItemTitle(String, delegate: RightNavItemDelegate?) - case rightNavItemIcon(UIImage, delegate: RightNavItemDelegate?) + case rightNavItemTitle(String, onTap: ((Int) -> Void)?) + case rightNavItemIcon(UIImage, onTap: ((Int) -> Void)?) } ``` diff --git a/Sources/ImageCarouselViewController.swift b/Sources/ImageCarouselViewController.swift index 16f5e9b..3badc93 100644 --- a/Sources/ImageCarouselViewController.swift +++ b/Sources/ImageCarouselViewController.swift @@ -8,8 +8,10 @@ public protocol ImageDataSource:class { public class ImageCarouselViewController:UIPageViewController { weak var imageDatasource:ImageDataSource? + weak var sourceView:UIImageView! + var initialIndex = 0 - var sourceView:UIImageView! + var theme:ImageViewerTheme = .light { didSet { navItem.leftBarButtonItem?.tintColor = theme.tintColor @@ -19,7 +21,7 @@ public class ImageCarouselViewController:UIPageViewController { var options:[ImageViewerOption] = [] - weak var rightNavItemDelegate:RightNavItemDelegate? + private var onRightNavBarTapped:((Int) -> Void)? private(set) lazy var navBar:UINavigationBar = { let _navBar = UINavigationBar(frame: .zero) @@ -91,20 +93,20 @@ public class ImageCarouselViewController:UIPageViewController { self.theme = theme case .closeIcon(let icon): navItem.leftBarButtonItem?.image = icon - case .rightNavItemTitle(let title, let delegate): + case .rightNavItemTitle(let title, let onTap): navItem.rightBarButtonItem = UIBarButtonItem( title: title, style: .plain, target: self, action: #selector(diTapRightNavBarItem(_:))) - rightNavItemDelegate = delegate - case .rightNavItemIcon(let icon, let delegate): + onRightNavBarTapped = onTap + case .rightNavItemIcon(let icon, let onTap): navItem.rightBarButtonItem = UIBarButtonItem( image: icon, style: .plain, target: self, action: #selector(diTapRightNavBarItem(_:))) - rightNavItemDelegate = delegate + onRightNavBarTapped = onTap } } } @@ -155,10 +157,10 @@ public class ImageCarouselViewController:UIPageViewController { @objc func diTapRightNavBarItem(_ sender:UIBarButtonItem) { - guard let _delegate = rightNavItemDelegate, + guard let onTap = onRightNavBarTapped, let _firstVC = viewControllers?.first as? ImageViewerController else { return } - _delegate.imageViewer(self, didTapRightNavItem: _firstVC.index) + onTap(_firstVC.index) } override public var preferredStatusBarStyle: UIStatusBarStyle { diff --git a/Sources/ImageViewerOption.swift b/Sources/ImageViewerOption.swift index 142e099..5f5f3c6 100644 --- a/Sources/ImageViewerOption.swift +++ b/Sources/ImageViewerOption.swift @@ -4,6 +4,6 @@ public enum ImageViewerOption { case theme(ImageViewerTheme) case closeIcon(UIImage) - case rightNavItemTitle(String, delegate: RightNavItemDelegate?) - case rightNavItemIcon(UIImage, delegate: RightNavItemDelegate?) + case rightNavItemTitle(String, onTap: ((Int) -> Void)?) + case rightNavItemIcon(UIImage, onTap: ((Int) -> Void)?) } diff --git a/Sources/RightNavItemDelegate.swift b/Sources/RightNavItemDelegate.swift deleted file mode 100644 index 3dd1f4d..0000000 --- a/Sources/RightNavItemDelegate.swift +++ /dev/null @@ -1,4 +0,0 @@ - -public protocol RightNavItemDelegate:class { - func imageViewer(_ imageViewer: ImageCarouselViewController, didTapRightNavItem index:Int) -} diff --git a/Sources/UIImageView_Extensions.swift b/Sources/UIImageView_Extensions.swift index ccb0974..c19c62c 100644 --- a/Sources/UIImageView_Extensions.swift +++ b/Sources/UIImageView_Extensions.swift @@ -4,7 +4,7 @@ extension UIImageView { // Data holder tap recognizer private class TapWithDataRecognizer:UITapGestureRecognizer { - var from:UIViewController? + weak var from:UIViewController? var imageDatasource:ImageDataSource? var initialIndex:Int = 0 var options:[ImageViewerOption] = []