From 8bc0e4b40cb02c77c9dba322ed37550ea6186979 Mon Sep 17 00:00:00 2001 From: alexazv_ilha Date: Fri, 26 Jul 2019 17:06:10 -0300 Subject: [PATCH 1/3] Linting, removing memory leak --- .../ISScrollViewPage/ISScrollViewPage.swift | 127 ++++++++---------- 1 file changed, 59 insertions(+), 68 deletions(-) diff --git a/ISScrollViewPage/ISScrollViewPage/ISScrollViewPage.swift b/ISScrollViewPage/ISScrollViewPage/ISScrollViewPage.swift index a0aeaad..5bfad05 100644 --- a/ISScrollViewPage/ISScrollViewPage/ISScrollViewPage.swift +++ b/ISScrollViewPage/ISScrollViewPage/ISScrollViewPage.swift @@ -14,31 +14,29 @@ import UIKit } @objc public protocol ISScrollViewPageDelegate { - func scrollViewPageDidChanged(_ scrollViewPage:ISScrollViewPage,index:Int); - @objc optional func scrollViewPageDidScroll(_ scrollView:UIScrollView); + func scrollViewPageDidChanged(_ scrollViewPage:ISScrollViewPage, index: Int); + @objc optional func scrollViewPageDidScroll(_ scrollView: UIScrollView); } open class ISScrollViewPage: UIScrollView, UIScrollViewDelegate { - open var viewControllers:[UIViewController]? + open var viewControllers: [UIViewController]? open var views = [UIView]() - open var scrollViewPageDelegate:ISScrollViewPageDelegate? + open weak var scrollViewPageDelegate: ISScrollViewPageDelegate? open var count: Int { - get { - let viewsCount = views.count - let controllersCount = viewControllers != nil ? viewControllers!.count : 0 - return viewsCount + controllersCount - } + let viewsCount = views.count + let controllersCount = viewControllers != nil ? viewControllers!.count : 0 + return viewsCount + controllersCount } var lastIndex = 0 - var enableBouces:Bool? - var enablePaging:Bool? - var fillContent:Bool? - open var scrollViewPageType:ISScrollViewPageType! - var isLoaded:Bool! - var sizeOfViews:CGFloat = 0 + var enableBouces: Bool? + var enablePaging: Bool? + var fillContent: Bool? + open var scrollViewPageType: ISScrollViewPageType! + var isLoaded: Bool! + var sizeOfViews: CGFloat = 0 - open func getScrollViewPageTypeFromInt(_ value:Int) -> ISScrollViewPageType { + open func getScrollViewPageTypeFromInt(_ value: Int) -> ISScrollViewPageType { switch(value) { case 1: return .horizontally @@ -74,24 +72,22 @@ open class ISScrollViewPage: UIScrollView, UIScrollViewDelegate { //MARK: UIScrollViewDelegate open func scrollViewDidScroll(_ scrollView: UIScrollView) { - if let scrollViewPageDelegate = self.scrollViewPageDelegate { - scrollViewPageDelegate.scrollViewPageDidScroll?(scrollView) - } + scrollViewPageDelegate?.scrollViewPageDidScroll?(scrollView) } open func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { var index:Int - switch (self.scrollViewPageType!) { + switch (scrollViewPageType!) { case .horizontally: let frame = self.frame.width if contentOffset.x != 0 { - index = Int(self.contentOffset.x / frame) - }else{ + index = Int(contentOffset.x / frame) + } else{ index = 0; } @@ -100,8 +96,8 @@ open class ISScrollViewPage: UIScrollView, UIScrollViewDelegate { let frame = self.frame.height if contentOffset.y != 0 { - index = Int(self.contentOffset.y / frame) - }else{ + index = Int(contentOffset.y / frame) + } else{ index = 0; } @@ -118,9 +114,9 @@ open class ISScrollViewPage: UIScrollView, UIScrollViewDelegate { //MARK: Public Functions - open func goToIndex(_ index:Int, animated:Bool){ + open func goToIndex(_ index: Int, animated: Bool){ - let countList = (self.viewControllers?.count)! > 0 ? self.viewControllers?.count : self.views.count + let countList = (viewControllers?.count)! > 0 ? viewControllers?.count : views.count if index >= countList! { @@ -133,7 +129,7 @@ open class ISScrollViewPage: UIScrollView, UIScrollViewDelegate { case .horizontally: - let frameWidth = Int(self.frame.width) + let frameWidth = Int(frame.width) let widthOfContentOffset = index * frameWidth self.setContentOffset(CGPoint(x: CGFloat(widthOfContentOffset), y: 0), animated: animated) @@ -155,87 +151,87 @@ open class ISScrollViewPage: UIScrollView, UIScrollViewDelegate { } - open func setFillContent(_ fillContent:Bool) { + open func setFillContent(_ fillContent: Bool) { self.fillContent = fillContent - setupLayout(self.scrollViewPageType) + setupLayout(scrollViewPageType) } - open func setControllers(_ viewControllers:[UIViewController]){ + open func setControllers(_ viewControllers: [UIViewController]) { self.viewControllers! = viewControllers; - setupLayout(self.scrollViewPageType) + setupLayout(scrollViewPageType) } - open func addCustomView(_ view:UIView) { - self.views.append(view) - setupLayout(self.scrollViewPageType) + open func addCustomView(_ view: UIView) { + views.append(view) + setupLayout(scrollViewPageType) } - open func setCustomViews(_ views:[UIView]){ + open func setCustomViews(_ views: [UIView]) { self.views = views - setupLayout(self.scrollViewPageType) + setupLayout(scrollViewPageType) } - open func removeCustomViewAtIndex(_ index:Int) { - if !views.isEmpty{ - self.views.remove(at: index) + open func removeCustomViewAtIndex(_ index: Int) { + if !views.isEmpty { + views.remove(at: index) } - setupLayout(self.scrollViewPageType) + setupLayout(scrollViewPageType) } - open func removeCustomView(_ mediaView:UIView) { + open func removeCustomView(_ mediaView: UIView) { if !views.isEmpty{ if let index = (views).firstIndex(of: mediaView) { - self.views.remove(at: index) + views.remove(at: index) } } - setupLayout(self.scrollViewPageType) + setupLayout(scrollViewPageType) } open func removeAllViews() { views.removeAll() viewControllers?.removeAll() - setupLayout(self.scrollViewPageType) + setupLayout(scrollViewPageType) } - open func setEnableBounces(_ enableBounces:Bool){ - self.bounces = enableBounces + open func setEnableBounces(_ enableBounces: Bool) { + bounces = enableBounces } - open func setPaging(_ pagingEnabled:Bool){ - self.enablePaging = pagingEnabled + open func setPaging(_ pagingEnabled: Bool) { + enablePaging = pagingEnabled } - open func setScrollViewPageType(_ value:Int) { - self.scrollViewPageType = getScrollViewPageTypeFromInt(value); + open func setScrollViewPageType(_ value: Int) { + scrollViewPageType = getScrollViewPageTypeFromInt(value); } //MARK: Private Functions fileprivate func initScrollView() { super.delegate = self - self.viewControllers = [] - self.views = [] - self.scrollViewPageType = ISScrollViewPageType.horizontally + viewControllers = [] + views = [] + scrollViewPageType = ISScrollViewPageType.horizontally } fileprivate func removeSubviews() { - for view in self.subviews { + for view in subviews { view.removeFromSuperview() } } - fileprivate func setupLayout (_ scrollViewPageType:ISScrollViewPageType){ + fileprivate func setupLayout (_ scrollViewPageType: ISScrollViewPageType) { sizeOfViews = 0 removeSubviews() - var list:[AnyObject] = [] + var list: [AnyObject] = [] if !viewControllers!.isEmpty { list = viewControllers! - }else if !views.isEmpty{ + } else if !views.isEmpty{ list = views - }else { + } else { return } @@ -245,19 +241,18 @@ open class ISScrollViewPage: UIScrollView, UIScrollViewDelegate { if let objectView = object as? UIView { build(list.count,index:i,objectView:objectView,scrollViewPageType: scrollViewPageType) - }else { + } else { let objectView = list[i] as! UIViewController - build(list.count,index:i,objectView:objectView.view,scrollViewPageType: scrollViewPageType) + build(list.count, index: i, objectView:objectView.view, scrollViewPageType: scrollViewPageType) } } self.isPagingEnabled = enablePaging! - } - fileprivate func build(_ numberOfViews:Int,index:Int,objectView:UIView,scrollViewPageType:ISScrollViewPageType) { - var frame = self.frame + fileprivate func build(_ numberOfViews: Int, index: Int, objectView: UIView, scrollViewPageType: ISScrollViewPageType) { + var frame = CGRect(x: self.frame.origin.x, y: self.frame.origin.y, width: self.frame.width, height: self.frame.height) let view:UIView = UIView() view.isUserInteractionEnabled = true view.clipsToBounds = true @@ -283,11 +278,7 @@ open class ISScrollViewPage: UIScrollView, UIScrollViewDelegate { } view.frame = frame - view.addSubview(objectView) - - self.addSubview(view) - + addSubview(view) } - } From 2a0a960e593c9efb5729a5c9262fb40170dccdfd Mon Sep 17 00:00:00 2001 From: alexazv_ilha Date: Mon, 29 Jul 2019 15:10:29 -0300 Subject: [PATCH 2/3] Update version --- .../ISScrollViewPage/ISScrollViewPage.swift | 12 +++++------- ISScrollViewPageSwift.podspec | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/ISScrollViewPage/ISScrollViewPage/ISScrollViewPage.swift b/ISScrollViewPage/ISScrollViewPage/ISScrollViewPage.swift index 5bfad05..c6836ea 100644 --- a/ISScrollViewPage/ISScrollViewPage/ISScrollViewPage.swift +++ b/ISScrollViewPage/ISScrollViewPage/ISScrollViewPage.swift @@ -24,9 +24,7 @@ open class ISScrollViewPage: UIScrollView, UIScrollViewDelegate { open var views = [UIView]() open weak var scrollViewPageDelegate: ISScrollViewPageDelegate? open var count: Int { - let viewsCount = views.count - let controllersCount = viewControllers != nil ? viewControllers!.count : 0 - return viewsCount + controllersCount + return views.count + (viewControllers?.count ?? 0) } var lastIndex = 0 var enableBouces: Bool? @@ -97,7 +95,7 @@ open class ISScrollViewPage: UIScrollView, UIScrollViewDelegate { if contentOffset.y != 0 { index = Int(contentOffset.y / frame) - } else{ + } else { index = 0; } @@ -229,7 +227,7 @@ open class ISScrollViewPage: UIScrollView, UIScrollViewDelegate { if !viewControllers!.isEmpty { list = viewControllers! - } else if !views.isEmpty{ + } else if !views.isEmpty { list = views } else { return @@ -261,7 +259,7 @@ open class ISScrollViewPage: UIScrollView, UIScrollViewDelegate { case .horizontally: sizeOfViews = sizeOfViews + objectView.frame.size.width - frame.origin.x = CGFloat(fillContent == true ? self.frame.size.width * CGFloat(index) : index == 0 ? 0 : sizeOfViews - objectView.frame.size.width); + frame.origin.x = CGFloat(fillContent == true ? self.frame.size.width * CGFloat(index) : index == 0 ? 0 : sizeOfViews - objectView.frame.size.width) frame.size = fillContent == true ? self.frame.size : objectView.frame.size frame.origin.y = 0 @@ -270,7 +268,7 @@ open class ISScrollViewPage: UIScrollView, UIScrollViewDelegate { case .vertically: sizeOfViews = sizeOfViews + objectView.frame.size.height - frame.origin.y = CGFloat(fillContent == true ? self.frame.size.height * CGFloat(index) : index == 0 ? 0 : sizeOfViews - objectView.frame.size.height); + frame.origin.y = CGFloat(fillContent == true ? self.frame.size.height * CGFloat(index) : index == 0 ? 0 : sizeOfViews - objectView.frame.size.height) frame.size = fillContent == true ? self.frame.size : objectView.frame.size frame.origin.x = 0 diff --git a/ISScrollViewPageSwift.podspec b/ISScrollViewPageSwift.podspec index 7589ef9..b80bca8 100644 --- a/ISScrollViewPageSwift.podspec +++ b/ISScrollViewPageSwift.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "ISScrollViewPageSwift" - s.version = "1.0.0" + s.version = "1.1.0" s.summary = "Page viewer implementation written in Swift." s.description = <<-DESC From ec5dad4ec8cbf3e0f531d80a6d3f00a075cbef6e Mon Sep 17 00:00:00 2001 From: alexazv_ilha Date: Mon, 29 Jul 2019 16:18:25 -0300 Subject: [PATCH 3/3] Revert version --- ISScrollViewPageSwift.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ISScrollViewPageSwift.podspec b/ISScrollViewPageSwift.podspec index b80bca8..7589ef9 100644 --- a/ISScrollViewPageSwift.podspec +++ b/ISScrollViewPageSwift.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "ISScrollViewPageSwift" - s.version = "1.1.0" + s.version = "1.0.0" s.summary = "Page viewer implementation written in Swift." s.description = <<-DESC