Skip to content

Commit

Permalink
Merge pull request #103 from michaelhenry/bugfixes/fix-memory-leaks
Browse files Browse the repository at this point in the history
fixed memory leaks #102
  • Loading branch information
michaelhenry authored Aug 19, 2020
2 parents 8c8a25f + 9cb5a74 commit a7026c0
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 24 deletions.
10 changes: 3 additions & 7 deletions Example/Demo/WithURLsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)?)
}
```

Expand Down
18 changes: 10 additions & 8 deletions Sources/ImageCarouselViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Sources/ImageViewerOption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)?)
}
4 changes: 0 additions & 4 deletions Sources/RightNavItemDelegate.swift

This file was deleted.

2 changes: 1 addition & 1 deletion Sources/UIImageView_Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
Expand Down

0 comments on commit a7026c0

Please sign in to comment.