From 7c13b59323c57f7fb979371727229dd6849bf194 Mon Sep 17 00:00:00 2001 From: Mikhail Konovalov Date: Thu, 11 Jan 2018 11:15:22 +0300 Subject: [PATCH 01/14] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=BF=D1=80=D0=B5=D0=B4=D1=83=D0=BF=D1=80=D0=B5?= =?UTF-8?q?=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8=D1=8F=20cocoapods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Example/Podfile | 9 ++++++--- Example/Podfile.lock | 16 ++++++++++++++++ .../project.pbxproj | 8 +++++++- 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 Example/Podfile.lock diff --git a/Example/Podfile b/Example/Podfile index 0b6e4a4..8e82ea7 100644 --- a/Example/Podfile +++ b/Example/Podfile @@ -1,8 +1,11 @@ source 'https://github.com/CocoaPods/Specs.git' +platform :ios, '9.0' use_frameworks! -target 'RMRPullToRefreshExample' do - project 'RMRPullToRefreshExample.xcodeproj' - pod 'RMRPullToRefresh’, :path => "../" +project 'RMRPullToRefreshExample.xcodeproj' +workspace 'RMRPullToRefreshExample.xcworkspace' + +target :RMRPullToRefreshExample do + pod 'RMRPullToRefresh', :path => "../" end diff --git a/Example/Podfile.lock b/Example/Podfile.lock new file mode 100644 index 0000000..71d485a --- /dev/null +++ b/Example/Podfile.lock @@ -0,0 +1,16 @@ +PODS: + - RMRPullToRefresh (0.5.0) + +DEPENDENCIES: + - RMRPullToRefresh (from `../`) + +EXTERNAL SOURCES: + RMRPullToRefresh: + :path: ../ + +SPEC CHECKSUMS: + RMRPullToRefresh: c80bde05dd42c5a32468ab282e18f9f05bc49397 + +PODFILE CHECKSUM: 6bf08c33e827c034420f4dcfc61024a8ba7eab2f + +COCOAPODS: 1.3.1 diff --git a/Example/RMRPullToRefreshExample.xcodeproj/project.pbxproj b/Example/RMRPullToRefreshExample.xcodeproj/project.pbxproj index 626c2ee..677b94a 100644 --- a/Example/RMRPullToRefreshExample.xcodeproj/project.pbxproj +++ b/Example/RMRPullToRefreshExample.xcodeproj/project.pbxproj @@ -199,13 +199,16 @@ files = ( ); inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-RMRPullToRefreshExample-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; 2BE863C51DEA329C1234F1B0 /* [CP] Embed Pods Frameworks */ = { @@ -214,9 +217,12 @@ files = ( ); inputPaths = ( + "${SRCROOT}/Pods/Target Support Files/Pods-RMRPullToRefreshExample/Pods-RMRPullToRefreshExample-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/RMRPullToRefresh/RMRPullToRefresh.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RMRPullToRefresh.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; From 303ac129e6d22af2ae8653b835d8e51fc59c459d Mon Sep 17 00:00:00 2001 From: Mikhail Konovalov Date: Thu, 11 Jan 2018 11:25:41 +0300 Subject: [PATCH 02/14] =?UTF-8?q?=D0=9C=D0=B8=D0=B3=D1=80=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BB=20=D0=BD=D0=B0=20Swift=204,=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=BF=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=D1=83=D0=BF=D1=80=D0=B5=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Example/RMRPullToRefresh/ViewController.swift | 32 ++++++++++--------- .../project.pbxproj | 25 ++++++++++++--- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/Example/RMRPullToRefresh/ViewController.swift b/Example/RMRPullToRefresh/ViewController.swift index 1432c01..29f6c63 100644 --- a/Example/RMRPullToRefresh/ViewController.swift +++ b/Example/RMRPullToRefresh/ViewController.swift @@ -46,7 +46,7 @@ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelega func configurePullToRefresh() { - pullToRefresh = RMRPullToRefresh(scrollView: tableView, position: position()) { [weak self] _ in + pullToRefresh = RMRPullToRefresh(scrollView: tableView, position: position()) { [weak self] in DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(5.0 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: { if self?.result == .success { self?.loadMore() @@ -117,22 +117,24 @@ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelega @IBAction func settings(_ sender: AnyObject) { - UIActionSheet(title: "Result type", delegate: self, cancelButtonTitle: nil, destructiveButtonTitle: nil, otherButtonTitles: ".Success", ".NoUpdates", ".Error").show(in: self.view) - } - - // MARK: - UIActionSheetDelegate - - func actionSheet(_ actionSheet: UIActionSheet, clickedButtonAt buttonIndex: Int) { - switch buttonIndex { - case 0: - self.result = .success - case 1: + let alertController = UIAlertController(title: "Result type", message: nil, preferredStyle: .actionSheet) + + let successAction = UIAlertAction(title: "Success", style: .default) { _ in self.result = .noUpdates - case 2: - self.result = .error - default: - break; } + alertController.addAction(successAction) + + let noUpdatesAction = UIAlertAction(title: "No updates", style: .default) { _ in + self.result = .noUpdates + } + alertController.addAction(noUpdatesAction) + + let errorAction = UIAlertAction(title: "Error", style: .default) { _ in + self.result = .error + } + alertController.addAction(errorAction) + + present(alertController, animated: true, completion: nil) } // MARK: - Test data diff --git a/Example/RMRPullToRefreshExample.xcodeproj/project.pbxproj b/Example/RMRPullToRefreshExample.xcodeproj/project.pbxproj index 677b94a..eab2cec 100644 --- a/Example/RMRPullToRefreshExample.xcodeproj/project.pbxproj +++ b/Example/RMRPullToRefreshExample.xcodeproj/project.pbxproj @@ -150,12 +150,12 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0720; + LastUpgradeCheck = 0920; ORGANIZATIONNAME = "Merkulov Ilya"; TargetAttributes = { 89CB12331C9DA07B00048E46 = { CreatedOnToolsVersion = 7.2.1; - LastSwiftMigration = 0800; + LastSwiftMigration = 0920; }; }; }; @@ -289,13 +289,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -333,13 +341,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -358,6 +374,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 9.2; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; VALIDATE_PRODUCT = YES; }; name = Release; @@ -372,7 +389,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.redmadrobot.RMRPullToRefresh; PRODUCT_NAME = RMRPullToRefreshExample; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -386,7 +403,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.redmadrobot.RMRPullToRefresh; PRODUCT_NAME = RMRPullToRefreshExample; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; From a59d153dbe143dd172ab9b8c33c0fe8cd94aa9c3 Mon Sep 17 00:00:00 2001 From: Mikhail Konovalov Date: Thu, 11 Jan 2018 11:34:25 +0300 Subject: [PATCH 03/14] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Base.lproj/Main.storyboard | 130 ++++++------ .../TableViewController.swift | 3 +- Example/RMRPullToRefresh/ViewController.swift | 191 +++++++++--------- 3 files changed, 165 insertions(+), 159 deletions(-) diff --git a/Example/RMRPullToRefresh/Base.lproj/Main.storyboard b/Example/RMRPullToRefresh/Base.lproj/Main.storyboard index d49d3ac..440c9be 100644 --- a/Example/RMRPullToRefresh/Base.lproj/Main.storyboard +++ b/Example/RMRPullToRefresh/Base.lproj/Main.storyboard @@ -1,8 +1,12 @@ - - + + + + + - + + @@ -10,9 +14,9 @@ - + - + @@ -20,79 +24,79 @@ - + - + - + - + - + - + - + - + - + - + - + @@ -102,28 +106,28 @@ - + - + - + @@ -133,28 +137,28 @@ - + - + - + @@ -168,28 +172,28 @@ - + - + - + @@ -199,28 +203,28 @@ - + - + - + @@ -252,26 +256,26 @@ - + - - - + + + - - + + - + @@ -284,7 +288,7 @@ - + @@ -311,7 +315,7 @@ - + diff --git a/Example/RMRPullToRefresh/TableViewController.swift b/Example/RMRPullToRefresh/TableViewController.swift index 81ada46..603643a 100644 --- a/Example/RMRPullToRefresh/TableViewController.swift +++ b/Example/RMRPullToRefresh/TableViewController.swift @@ -8,9 +8,8 @@ import UIKit -class TableViewController: UITableViewController { +final class TableViewController: UITableViewController { - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { super.prepare(for: segue, sender: sender) diff --git a/Example/RMRPullToRefresh/ViewController.swift b/Example/RMRPullToRefresh/ViewController.swift index 29f6c63..aa5949d 100644 --- a/Example/RMRPullToRefresh/ViewController.swift +++ b/Example/RMRPullToRefresh/ViewController.swift @@ -18,103 +18,25 @@ public enum ExampleType: Int { case redmadrobotBottom } -class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UIActionSheetDelegate { +final class ViewController: UIViewController { - @IBOutlet weak var tableView: UITableView! + // MARK: - Public properties var exampleType: ExampleType = .beelineBottom - var pullToRefresh: RMRPullToRefresh? + // MARK: - Private properites - let formatter = DateFormatter() + private var pullToRefresh: RMRPullToRefresh? + private let formatter = DateFormatter() + private var items: [String] = [] + private var count = 2 + private var result = RMRPullToRefreshResultType.success - var items: [String] = [] - var count = 2 + // MARK: - IBOutlets - var result = RMRPullToRefreshResultType.success - - override func viewDidLoad() { - super.viewDidLoad() - - someConfiguring() - loadData() - - configurePullToRefresh() - } - - // MARK: - Pull to Refresh - - func configurePullToRefresh() { - - pullToRefresh = RMRPullToRefresh(scrollView: tableView, position: position()) { [weak self] in - DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(5.0 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: { - if self?.result == .success { - self?.loadMore() - } - if let result = self?.result { - self?.pullToRefresh?.stopLoading(result) - } - }) - } - - if exampleType == .perekrestokTop || exampleType == .perekrestokBottom { - perekrestok() - } else if exampleType == .beelineTop || exampleType == .beelineBottom { - beeline() - } else if exampleType == .redmadrobotTop || exampleType == .redmadrobotBottom { - redmadrobot() - } - - pullToRefresh?.setHideDelay(5.0, result: .success) - - pullToRefresh?.hideWhenError = false - } - - // MARK: - Build example values - - func perekrestok() { - - if let pullToRefreshView = PerekrestokView.XIB_VIEW() { - pullToRefresh?.configureView(pullToRefreshView, state: .dragging, result: .success) - pullToRefresh?.configureView(pullToRefreshView, state: .loading, result: .success) - } - pullToRefresh?.height = 90.0 - pullToRefresh?.backgroundColor = UIColor(red: 16.0/255.0, - green: 192.0/255.0, - blue: 119.0/255.0, - alpha: 1.0) - } - - func beeline() { - - if let pullToRefreshView = BeelineView.XIB_VIEW() { - pullToRefresh?.configureView(pullToRefreshView, state: .dragging, result: .success) - pullToRefresh?.configureView(pullToRefreshView, state: .loading, result: .success) - } - pullToRefresh?.height = 90.0 - pullToRefresh?.backgroundColor = UIColor.white - } - - func redmadrobot() { - pullToRefresh?.setupDefaultSettings() - } - - func position() -> RMRPullToRefreshPosition { - if exampleType == .perekrestokTop || exampleType == .beelineTop || exampleType == .redmadrobotTop { - return .top - } - return .bottom - } - - // MARK: - Configure - - func someConfiguring() { - formatter.dateStyle = DateFormatter.Style.long - formatter.timeStyle = .medium - } - - // MARK: - Action + @IBOutlet weak var tableView: UITableView! + // MARK: - IBActions @IBAction func settings(_ sender: AnyObject) { let alertController = UIAlertController(title: "Result type", message: nil, preferredStyle: .actionSheet) @@ -137,22 +59,104 @@ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelega present(alertController, animated: true, completion: nil) } + // MARK: - UIViewController + + override func viewDidLoad() { + super.viewDidLoad() + + someConfiguring() + loadData() + + configurePullToRefresh() + } + + // MARK: - Pull to Refresh + + private func configurePullToRefresh() { + pullToRefresh = RMRPullToRefresh(scrollView: tableView, position: position()) { [weak self] in + DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 5, execute: { + if self?.result == .success { + self?.loadMore() + } + if let result = self?.result { + self?.pullToRefresh?.stopLoading(result) + } + }) + } + + switch exampleType { + case .perekrestokTop, .perekrestokBottom: + perekrestok() + case .beelineTop, .beelineBottom: + beeline() + case .redmadrobotTop, .redmadrobotBottom: + redmadrobot() + } + + pullToRefresh?.setHideDelay(5.0, result: .success) + pullToRefresh?.hideWhenError = false + } + + // MARK: - Build example values + + private func perekrestok() { + if let pullToRefreshView = PerekrestokView.XIB_VIEW() { + pullToRefresh?.configureView(pullToRefreshView, state: .dragging, result: .success) + pullToRefresh?.configureView(pullToRefreshView, state: .loading, result: .success) + } + pullToRefresh?.height = 90.0 + pullToRefresh?.backgroundColor = UIColor( + red: 16.0/255.0, + green: 192.0/255.0, + blue: 119.0/255.0, + alpha: 1.0) + } + + private func beeline() { + if let pullToRefreshView = BeelineView.XIB_VIEW() { + pullToRefresh?.configureView(pullToRefreshView, state: .dragging, result: .success) + pullToRefresh?.configureView(pullToRefreshView, state: .loading, result: .success) + } + pullToRefresh?.height = 90.0 + pullToRefresh?.backgroundColor = UIColor.white + } + + private func redmadrobot() { + pullToRefresh?.setupDefaultSettings() + } + + private func position() -> RMRPullToRefreshPosition { + if exampleType == .perekrestokTop || exampleType == .beelineTop || exampleType == .redmadrobotTop { + return .top + } + return .bottom + } + + // MARK: - Configure + + private func someConfiguring() { + formatter.dateStyle = DateFormatter.Style.long + formatter.timeStyle = .medium + } + // MARK: - Test data - func loadData() { + private func loadData() { for _ in 0...count { items.append(formatter.string(from: Date())) } } - func loadMore() { + private func loadMore() { for _ in 0...20 { self.items.append(formatter.string(from: Date(timeIntervalSinceNow: 20))) } self.tableView.reloadData() } - - // MARK: - TableView +} + +// MARK: - UITableViewDataSource +extension ViewController: UITableViewDataSource { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) @@ -168,4 +172,3 @@ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelega return 1; } } - From 788a5ae73c46d38b7d333d0955ef0fa4c96bb3fe Mon Sep 17 00:00:00 2001 From: Mikhail Konovalov Date: Thu, 11 Jan 2018 12:03:56 +0300 Subject: [PATCH 04/14] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=83=20=D1=81=20KVO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/RMRPullToRefreshConstants.swift | 8 --- Classes/RMRPullToRefreshController.swift | 84 ++++++++---------------- 2 files changed, 29 insertions(+), 63 deletions(-) diff --git a/Classes/RMRPullToRefreshConstants.swift b/Classes/RMRPullToRefreshConstants.swift index 699c372..341a41c 100755 --- a/Classes/RMRPullToRefreshConstants.swift +++ b/Classes/RMRPullToRefreshConstants.swift @@ -27,14 +27,6 @@ public enum RMRPullToRefreshResultType: Int { public struct RMRPullToRefreshConstants { - struct KeyPaths { - static let ContentOffset = "contentOffset" - static let ContentSize = "contentSize" - static let ContentInset = "contentInset" - static let PanState = "pan.state" - static let Frame = "frame" - } - static let DefaultHeight = CGFloat(90.0) static let DefaultBackgroundColor = UIColor.white } diff --git a/Classes/RMRPullToRefreshController.swift b/Classes/RMRPullToRefreshController.swift index f9482fb..952bfde 100755 --- a/Classes/RMRPullToRefreshController.swift +++ b/Classes/RMRPullToRefreshController.swift @@ -7,26 +7,6 @@ // import UIKit -fileprivate func < (lhs: T?, rhs: T?) -> Bool { - switch (lhs, rhs) { - case let (l?, r?): - return l < r - case (nil, _?): - return true - default: - return false - } -} - -fileprivate func > (lhs: T?, rhs: T?) -> Bool { - switch (lhs, rhs) { - case let (l?, r?): - return l > r - default: - return rhs < lhs - } -} - open class RMRPullToRefreshController: NSObject { @@ -41,7 +21,6 @@ open class RMRPullToRefreshController: NSObject { var backgroundViewTopConstraint: NSLayoutConstraint? var stopped = true - var subscribing = false var actionHandler: (() -> Void)! @@ -60,6 +39,12 @@ open class RMRPullToRefreshController: NSObject { open var hideWhenError: Bool = true + // MARK: - Observation + + private var contentOffsetObservation: NSKeyValueObservation? + private var contentSizeObservation: NSKeyValueObservation? + private var panStateObservation: NSKeyValueObservation? + // MARK: - Init init(scrollView: UIScrollView, position:RMRPullToRefreshPosition, actionHandler: @escaping () -> Void) { @@ -319,8 +304,10 @@ open class RMRPullToRefreshController: NSObject { } else { constant = contentOffsetY + contentInset.bottom } - if constant > 0 && constant > backgroundViewHeightConstraint?.constant { - backgroundViewHeightConstraint?.constant = constant + if let backgroundViewHeightConstraint = backgroundViewHeightConstraint, + constant > 0, + constant > backgroundViewHeightConstraint.constant { + backgroundViewHeightConstraint.constant = constant } } @@ -391,41 +378,28 @@ open class RMRPullToRefreshController: NSObject { // MARK: - KVO open func subscribeOnScrollViewEvents() { - if !subscribing, let scrollView = self.scrollView { - scrollView.addObserver(self, forKeyPath: RMRPullToRefreshConstants.KeyPaths.ContentOffset, options: .new, context: nil) - scrollView.addObserver(self, forKeyPath: RMRPullToRefreshConstants.KeyPaths.ContentSize, options: .new, context: nil) - scrollView.addObserver(self, forKeyPath: RMRPullToRefreshConstants.KeyPaths.PanState, options: .new, context: nil) - subscribing = true + guard let scrollView = scrollView else { + return + } + + self.contentOffsetObservation = scrollView.observe(\.contentOffset, options: [.new]) { scrollView, change in + guard let newContentOffset = change.newValue else { return } + self.scrollViewDidScroll(scrollView, contentOffset: newContentOffset) + } + + self.contentSizeObservation = scrollView.observe(\.contentSize, options: [.new]) { scrollView, change in + guard let newContentSize = change.newValue else { return } + self.scrollViewDidChangeContentSize(scrollView, contentSize: newContentSize) + } + + self.panStateObservation = scrollView.panGestureRecognizer.observe(\.state, options: [.new]) { panGestureRecognizer, _ in + self.scrollViewDidChangePanState(scrollView, panState: panGestureRecognizer.state) } } open func unsubscribeFromScrollViewEvents() { - if subscribing, let scrollView = self.containerView.superview { - scrollView.removeObserver(self, forKeyPath: RMRPullToRefreshConstants.KeyPaths.ContentOffset) - scrollView.removeObserver(self, forKeyPath: RMRPullToRefreshConstants.KeyPaths.ContentSize) - scrollView.removeObserver(self, forKeyPath: RMRPullToRefreshConstants.KeyPaths.PanState) - subscribing = false - } + contentOffsetObservation?.invalidate() + contentSizeObservation?.invalidate() + panStateObservation?.invalidate() } - - override open func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { - if keyPath == RMRPullToRefreshConstants.KeyPaths.ContentOffset { - if let newContentOffset = (change?[NSKeyValueChangeKey.newKey] as? NSValue)?.cgPointValue, let scrollView = self.scrollView { - scrollViewDidScroll(scrollView, contentOffset:newContentOffset) - } - } else if keyPath == RMRPullToRefreshConstants.KeyPaths.ContentSize { - if let newContentSize = (change?[NSKeyValueChangeKey.newKey] as? NSValue)?.cgSizeValue, let scrollView = self.scrollView { - if checkContentSize(scrollView) { - scrollViewDidChangeContentSize(scrollView, contentSize: newContentSize) - } - } - } else if keyPath == RMRPullToRefreshConstants.KeyPaths.PanState { - if let rawValue = change?[NSKeyValueChangeKey.newKey] as? Int { - if let state = UIGestureRecognizerState(rawValue: rawValue), let scrollView = self.scrollView { - scrollViewDidChangePanState(scrollView, panState: state) - } - } - } - } - } From 397f6d33b2d9ff889fb41deea1541196e9562402 Mon Sep 17 00:00:00 2001 From: Mikhail Konovalov Date: Thu, 11 Jan 2018 12:04:41 +0300 Subject: [PATCH 05/14] =?UTF-8?q?=D0=97=D0=B0=D0=BA=D0=BE=D0=BC=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BB=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D1=83=20=D1=81=D0=BA=D1=80?= =?UTF-8?q?=D1=8B=D1=82=D0=B8=D1=8F=20pull=20to=20refresh=20=D0=B8=20?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=B2=20=D1=81=D0=BB=D1=83=D1=87=D0=B0=D0=B5=20=D0=BE?= =?UTF-8?q?=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Example/RMRPullToRefresh/ViewController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Example/RMRPullToRefresh/ViewController.swift b/Example/RMRPullToRefresh/ViewController.swift index aa5949d..78a9f5c 100644 --- a/Example/RMRPullToRefresh/ViewController.swift +++ b/Example/RMRPullToRefresh/ViewController.swift @@ -93,8 +93,8 @@ final class ViewController: UIViewController { redmadrobot() } - pullToRefresh?.setHideDelay(5.0, result: .success) - pullToRefresh?.hideWhenError = false + //pullToRefresh?.setHideDelay(5.0, result: .success) + //pullToRefresh?.hideWhenError = false } // MARK: - Build example values From 59de97d267ca74117f729c89e92c293284f7bc14 Mon Sep 17 00:00:00 2001 From: Mikhail Konovalov Date: Thu, 11 Jan 2018 12:40:04 +0300 Subject: [PATCH 06/14] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D1=83=D1=82?= =?UTF-8?q?=D0=B5=D1=87=D0=BA=D0=B8=20=D0=BF=D0=B0=D0=BC=D1=8F=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/RMRPullToRefresh.swift | 8 -------- Classes/RMRPullToRefreshController.swift | 22 ++++++++++++++-------- 2 files changed, 14 insertions(+), 16 deletions(-) mode change 100755 => 100644 Classes/RMRPullToRefresh.swift mode change 100755 => 100644 Classes/RMRPullToRefreshController.swift diff --git a/Classes/RMRPullToRefresh.swift b/Classes/RMRPullToRefresh.swift old mode 100755 new mode 100644 index 3175e0d..33a850c --- a/Classes/RMRPullToRefresh.swift +++ b/Classes/RMRPullToRefresh.swift @@ -46,14 +46,6 @@ open class RMRPullToRefresh: NSObject { self.сontroller = controller } - /// Метод нужно вызывать в deinit экрана, в котором используется pull-to-refresh. - /// - /// Это временное решение для избежания краша из-за KVO-наблюдателей на scroll view - /// (при уничтожении скролла и экрана, в котором он лежит). - open func unsubscribeFromBindings() { - сontroller?.unsubscribeFromScrollViewEvents() - } - open func configureView(_ view :RMRPullToRefreshView, state:RMRPullToRefreshState, result:RMRPullToRefreshResultType) { сontroller?.configureView(view, state: state, result: result) } diff --git a/Classes/RMRPullToRefreshController.swift b/Classes/RMRPullToRefreshController.swift old mode 100755 new mode 100644 index 952bfde..2619126 --- a/Classes/RMRPullToRefreshController.swift +++ b/Classes/RMRPullToRefreshController.swift @@ -382,18 +382,24 @@ open class RMRPullToRefreshController: NSObject { return } - self.contentOffsetObservation = scrollView.observe(\.contentOffset, options: [.new]) { scrollView, change in - guard let newContentOffset = change.newValue else { return } - self.scrollViewDidScroll(scrollView, contentOffset: newContentOffset) + self.contentOffsetObservation = scrollView.observe( + \.contentOffset, + options: [.new]) { [weak self] (scrollView, change) in + guard let newContentOffset = change.newValue else { return } + self?.scrollViewDidScroll(scrollView, contentOffset: newContentOffset) } - self.contentSizeObservation = scrollView.observe(\.contentSize, options: [.new]) { scrollView, change in - guard let newContentSize = change.newValue else { return } - self.scrollViewDidChangeContentSize(scrollView, contentSize: newContentSize) + self.contentSizeObservation = scrollView.observe( + \.contentSize, + options: [.new]) { [weak self] (scrollView, change) in + guard let newContentSize = change.newValue else { return } + self?.scrollViewDidChangeContentSize(scrollView, contentSize: newContentSize) } - self.panStateObservation = scrollView.panGestureRecognizer.observe(\.state, options: [.new]) { panGestureRecognizer, _ in - self.scrollViewDidChangePanState(scrollView, panState: panGestureRecognizer.state) + self.panStateObservation = scrollView.panGestureRecognizer.observe( + \.state, + options: [.new]) { [weak self] panGestureRecognizer, _ in + self?.scrollViewDidChangePanState(scrollView, panState: panGestureRecognizer.state) } } From 43b8834736879e509b35261f236778f535bfe483 Mon Sep 17 00:00:00 2001 From: Mikhail Konovalov Date: Thu, 11 Jan 2018 12:40:23 +0300 Subject: [PATCH 07/14] =?UTF-8?q?Fileprivate=20=D0=BD=D0=B0=20private?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/RMRPullToRefresh.swift | 2 +- Classes/RMRPullToRefreshController.swift | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Classes/RMRPullToRefresh.swift b/Classes/RMRPullToRefresh.swift index 33a850c..194558f 100644 --- a/Classes/RMRPullToRefresh.swift +++ b/Classes/RMRPullToRefresh.swift @@ -10,7 +10,7 @@ import UIKit open class RMRPullToRefresh: NSObject { - fileprivate var сontroller: RMRPullToRefreshController? + private var сontroller: RMRPullToRefreshController? open var height : CGFloat = RMRPullToRefreshConstants.DefaultHeight { didSet { diff --git a/Classes/RMRPullToRefreshController.swift b/Classes/RMRPullToRefreshController.swift index 2619126..31aee68 100644 --- a/Classes/RMRPullToRefreshController.swift +++ b/Classes/RMRPullToRefreshController.swift @@ -62,13 +62,13 @@ open class RMRPullToRefreshController: NSObject { self.subscribeOnScrollViewEvents() } - fileprivate func configureBackgroundView(_ backgroundView: UIView) { + private func configureBackgroundView(_ backgroundView: UIView) { backgroundView.translatesAutoresizingMaskIntoConstraints = false scrollView?.addSubview(backgroundView) addBackgroundViewConstraints(backgroundView) } - fileprivate func addBackgroundViewConstraints(_ backgroundView: UIView) { + private func addBackgroundViewConstraints(_ backgroundView: UIView) { // Constraints self.backgroundViewHeightConstraint = NSLayoutConstraint(item: backgroundView, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 0) backgroundView.addConstraint(self.backgroundViewHeightConstraint!) @@ -84,7 +84,7 @@ open class RMRPullToRefreshController: NSObject { } } - fileprivate func configureHeight() { + private func configureHeight() { if let scrollView = self.scrollView { self.originalTopInset = scrollView.contentInset.top @@ -208,23 +208,23 @@ open class RMRPullToRefreshController: NSObject { containerView.startLoadingAnimation(startProgress) } - @objc fileprivate func stopAllAnimations() { + @objc private func stopAllAnimations() { if shouldHideWhenStopLoading() { stopped = true } containerView.stopAllAnimations(shouldHideWhenStopLoading()) } - @objc fileprivate func forceStopAllAnimations() { + @objc private func forceStopAllAnimations() { stopped = true containerView.stopAllAnimations(true) } - @objc fileprivate func resetBackgroundViewHeightConstraint() { + @objc private func resetBackgroundViewHeightConstraint() { backgroundViewHeightConstraint?.constant = 0 } - fileprivate func scrollViewDidChangePanState(_ scrollView: UIScrollView, panState: UIGestureRecognizerState) { + private func scrollViewDidChangePanState(_ scrollView: UIScrollView, panState: UIGestureRecognizerState) { if panState == .ended || panState == .cancelled || panState == .failed { if state == .loading || (shouldHideWhenStopLoading() && !stopped) { @@ -255,7 +255,7 @@ open class RMRPullToRefreshController: NSObject { } } - fileprivate func scrollViewDidChangeContentSize(_ scrollView: UIScrollView, contentSize: CGSize) { + private func scrollViewDidChangeContentSize(_ scrollView: UIScrollView, contentSize: CGSize) { updateContainerFrame() if position == .bottom { self.backgroundViewTopConstraint?.constant = max(scrollView.contentSize.height, scrollView.bounds.height) @@ -265,7 +265,7 @@ open class RMRPullToRefreshController: NSObject { } } - fileprivate func scrollViewDidScroll(_ scrollView: UIScrollView, contentOffset: CGPoint) { + private func scrollViewDidScroll(_ scrollView: UIScrollView, contentOffset: CGPoint) { if state == .loading { if scrollView.contentOffset.y >= 0 { @@ -297,7 +297,7 @@ open class RMRPullToRefreshController: NSObject { } } - fileprivate func configureBackgroundHeightConstraint(_ contentOffsetY: CGFloat, contentInset: UIEdgeInsets) { + private func configureBackgroundHeightConstraint(_ contentOffsetY: CGFloat, contentInset: UIEdgeInsets) { var constant = CGFloat(-1.0) if position == .top { constant = contentOffsetY + contentInset.top From db5402288bafccd6e9258f64524c4570b9204c78 Mon Sep 17 00:00:00 2001 From: Mikhail Konovalov Date: Thu, 11 Jan 2018 13:00:22 +0300 Subject: [PATCH 08/14] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=BD=D1=8F=D0=BB=20?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8E=20iOS=20=D0=B4=D0=BE=209?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Example/Podfile.lock | 2 +- Example/RMRPullToRefreshExample.xcodeproj/project.pbxproj | 4 ++-- RMRPullToRefresh.podspec | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 71d485a..3b14f7d 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -9,7 +9,7 @@ EXTERNAL SOURCES: :path: ../ SPEC CHECKSUMS: - RMRPullToRefresh: c80bde05dd42c5a32468ab282e18f9f05bc49397 + RMRPullToRefresh: 6c25f48af80d0e5d72b89ef5d6ea0dfcc21e5444 PODFILE CHECKSUM: 6bf08c33e827c034420f4dcfc61024a8ba7eab2f diff --git a/Example/RMRPullToRefreshExample.xcodeproj/project.pbxproj b/Example/RMRPullToRefreshExample.xcodeproj/project.pbxproj index eab2cec..18f58c9 100644 --- a/Example/RMRPullToRefreshExample.xcodeproj/project.pbxproj +++ b/Example/RMRPullToRefreshExample.xcodeproj/project.pbxproj @@ -325,7 +325,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.2; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -371,7 +371,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.2; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; diff --git a/RMRPullToRefresh.podspec b/RMRPullToRefresh.podspec index ce4a926..a183e9d 100644 --- a/RMRPullToRefresh.podspec +++ b/RMRPullToRefresh.podspec @@ -1,12 +1,12 @@ Pod::Spec.new do |spec| spec.name = "RMRPullToRefresh" spec.version = "0.5.0" - spec.platform = :ios, "8.0" + spec.platform = :ios, "9.0" spec.license = { :type => "MIT", :file => "LICENSE" } spec.summary = "A pull to refresh control for UIScrollView (UITableView and UICollectionView)" spec.homepage = "http://redmadrobot.com/" spec.author = "Ilya Merkulov" spec.source = { :git => "https://git.redmadrobot.com/helper-ios/RMRPullToRefresh.git", :tag => spec.version } spec.source_files = "Classes/*.{swift}", "Classes/Default/*.{swift}" - spec.resources = ['Images/*.png'] + spec.resources = ['Images/*.png'] end \ No newline at end of file From 99fa1ae6863d6f46838c343292b5c54ddd24ce80 Mon Sep 17 00:00:00 2001 From: Mikhail Konovalov Date: Thu, 11 Jan 2018 13:00:36 +0300 Subject: [PATCH 09/14] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80=D0=B5=D0=B8=CC=86=D0=BD?= =?UTF-8?q?=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/RMRPullToRefreshController.swift | 26 +++++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Classes/RMRPullToRefreshController.swift b/Classes/RMRPullToRefreshController.swift index 31aee68..8d293fa 100644 --- a/Classes/RMRPullToRefreshController.swift +++ b/Classes/RMRPullToRefreshController.swift @@ -69,23 +69,29 @@ open class RMRPullToRefreshController: NSObject { } private func addBackgroundViewConstraints(_ backgroundView: UIView) { - // Constraints - self.backgroundViewHeightConstraint = NSLayoutConstraint(item: backgroundView, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 0) - backgroundView.addConstraint(self.backgroundViewHeightConstraint!) + guard let scrollView = scrollView, let position = position else { + return + } + + let backgroundViewHeightConstraint = backgroundView.heightAnchor.constraint(equalToConstant: 0) + backgroundViewHeightConstraint.isActive = true + self.backgroundViewHeightConstraint = backgroundViewHeightConstraint - scrollView?.addConstraint(NSLayoutConstraint(item: backgroundView, attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal, toItem: scrollView, attribute: NSLayoutAttribute.width, multiplier: 1, constant: 0)) + backgroundView.widthAnchor.constraint(equalTo: scrollView.widthAnchor).isActive = true - if position == .top { - scrollView?.addConstraint(NSLayoutConstraint(item: backgroundView, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: scrollView, attribute: NSLayoutAttribute.top, multiplier: 1, constant: 0)) - } else if position == .bottom, let scrollView = self.scrollView { + switch position { + case .top: + backgroundView.bottomAnchor.constraint(equalTo: scrollView.topAnchor).isActive = true + case .bottom: let constant = max(scrollView.contentSize.height, scrollView.bounds.height) - self.backgroundViewTopConstraint = NSLayoutConstraint(item: backgroundView, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: scrollView, attribute: NSLayoutAttribute.top, multiplier: 1, constant: constant) - scrollView.addConstraint(self.backgroundViewTopConstraint!) + let backgroundViewTopConstraint = backgroundView.topAnchor.constraint( + equalTo: scrollView.bottomAnchor, constant: constant) + backgroundViewTopConstraint.isActive = true + self.backgroundViewTopConstraint = backgroundViewTopConstraint } } private func configureHeight() { - if let scrollView = self.scrollView { self.originalTopInset = scrollView.contentInset.top self.originalBottomInset = scrollView.contentInset.bottom From 36174af0e8ffa5cc1002743444d360b7be5424ac Mon Sep 17 00:00:00 2001 From: Mikhail Konovalov Date: Thu, 11 Jan 2018 13:03:23 +0300 Subject: [PATCH 10/14] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=BD=D1=8F=D0=BB=20?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8E=20=D0=B2=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=B4=D1=81=D0=BF=D0=B5=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AppIcon.appiconset/Contents.json | 15 +++++++++++++++ RMRPullToRefresh.podspec | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Example/RMRPullToRefresh/Assets.xcassets/AppIcon.appiconset/Contents.json b/Example/RMRPullToRefresh/Assets.xcassets/AppIcon.appiconset/Contents.json index 118c98f..19882d5 100644 --- a/Example/RMRPullToRefresh/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/Example/RMRPullToRefresh/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "29x29", @@ -29,6 +39,11 @@ "idiom" : "iphone", "size" : "60x60", "scale" : "3x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" } ], "info" : { diff --git a/RMRPullToRefresh.podspec b/RMRPullToRefresh.podspec index a183e9d..064206c 100644 --- a/RMRPullToRefresh.podspec +++ b/RMRPullToRefresh.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = "RMRPullToRefresh" - spec.version = "0.5.0" + spec.version = "0.6.0" spec.platform = :ios, "9.0" spec.license = { :type => "MIT", :file => "LICENSE" } spec.summary = "A pull to refresh control for UIScrollView (UITableView and UICollectionView)" From 4abdd966044c62f4bd3aa7288ae24595ab4d455d Mon Sep 17 00:00:00 2001 From: Jon Fir Date: Thu, 20 Sep 2018 18:11:23 +0700 Subject: [PATCH 11/14] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B2=D0=B5?= =?UTF-8?q?=D0=BB=20=D0=BD=D0=B0=20swift=204.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RMRPullToRefreshBaseMessageView.swift | 20 +++++++++---------- .../Default/RMRPullToRefreshBaseView.swift | 16 +++++++-------- Classes/RMRPullToRefreshContainerView.swift | 12 +++++------ Classes/RMRPullToRefreshController.swift | 6 +++--- Example/RMRPullToRefresh/AppDelegate.swift | 2 +- .../project.pbxproj | 20 ++----------------- 6 files changed, 30 insertions(+), 46 deletions(-) diff --git a/Classes/Default/RMRPullToRefreshBaseMessageView.swift b/Classes/Default/RMRPullToRefreshBaseMessageView.swift index d24b30a..ea05a16 100755 --- a/Classes/Default/RMRPullToRefreshBaseMessageView.swift +++ b/Classes/Default/RMRPullToRefreshBaseMessageView.swift @@ -39,10 +39,10 @@ class RMRPullToRefreshBaseMessageView: RMRPullToRefreshBaseView { messageView.addSubview(label) label.translatesAutoresizingMaskIntoConstraints = false - for attribute in [NSLayoutAttribute.top, NSLayoutAttribute.right, NSLayoutAttribute.left, NSLayoutAttribute.bottom] { + for attribute in [NSLayoutConstraint.Attribute.top, NSLayoutConstraint.Attribute.right, NSLayoutConstraint.Attribute.left, NSLayoutConstraint.Attribute.bottom] { messageView.addConstraint(NSLayoutConstraint(item: label, attribute: attribute, - relatedBy: NSLayoutRelation.equal, + relatedBy: NSLayoutConstraint.Relation.equal, toItem: messageView, attribute: attribute, multiplier: 1, @@ -58,18 +58,18 @@ class RMRPullToRefreshBaseMessageView: RMRPullToRefreshBaseView { messageView.translatesAutoresizingMaskIntoConstraints = false let heightConstraint = NSLayoutConstraint(item: messageView, - attribute: NSLayoutAttribute.height, - relatedBy: NSLayoutRelation.equal, + attribute: NSLayoutConstraint.Attribute.height, + relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, - attribute: NSLayoutAttribute.notAnAttribute, + attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: 30) let widthConstraint = NSLayoutConstraint(item: messageView, - attribute: NSLayoutAttribute.width, - relatedBy: NSLayoutRelation.equal, + attribute: NSLayoutConstraint.Attribute.width, + relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, - attribute: NSLayoutAttribute.notAnAttribute, + attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: 150) @@ -77,7 +77,7 @@ class RMRPullToRefreshBaseMessageView: RMRPullToRefreshBaseView { let verticalConstraint = NSLayoutConstraint(item: messageView, attribute: .centerY, - relatedBy: NSLayoutRelation.equal, + relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: .centerY, multiplier: 1, @@ -85,7 +85,7 @@ class RMRPullToRefreshBaseMessageView: RMRPullToRefreshBaseView { let leftConstraint = NSLayoutConstraint(item: messageView, attribute: .left, - relatedBy: NSLayoutRelation.equal, + relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: .right, multiplier: 1, diff --git a/Classes/Default/RMRPullToRefreshBaseView.swift b/Classes/Default/RMRPullToRefreshBaseView.swift index af3837e..cad3cc8 100755 --- a/Classes/Default/RMRPullToRefreshBaseView.swift +++ b/Classes/Default/RMRPullToRefreshBaseView.swift @@ -45,18 +45,18 @@ class RMRPullToRefreshBaseView: RMRPullToRefreshView { func configureConstraints() { logoImageView.translatesAutoresizingMaskIntoConstraints = false let heightConstraint = NSLayoutConstraint(item: logoImageView, - attribute: NSLayoutAttribute.height, - relatedBy: NSLayoutRelation.equal, + attribute: NSLayoutConstraint.Attribute.height, + relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, - attribute: NSLayoutAttribute.notAnAttribute, + attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: 50) let widthConstraint = NSLayoutConstraint(item: logoImageView, - attribute: NSLayoutAttribute.width, - relatedBy: NSLayoutRelation.equal, + attribute: NSLayoutConstraint.Attribute.width, + relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, - attribute: NSLayoutAttribute.notAnAttribute, + attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: 50) @@ -64,7 +64,7 @@ class RMRPullToRefreshBaseView: RMRPullToRefreshView { let verticalConstraint = NSLayoutConstraint(item: logoImageView, attribute: .centerY, - relatedBy: NSLayoutRelation.equal, + relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: .centerY, multiplier: 1, @@ -72,7 +72,7 @@ class RMRPullToRefreshBaseView: RMRPullToRefreshView { let horizontalConstraint = NSLayoutConstraint(item: logoImageView, attribute: .centerX, - relatedBy: NSLayoutRelation.equal, + relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: .centerX, multiplier: 1, diff --git a/Classes/RMRPullToRefreshContainerView.swift b/Classes/RMRPullToRefreshContainerView.swift index 81c5f0a..6dcc98c 100755 --- a/Classes/RMRPullToRefreshContainerView.swift +++ b/Classes/RMRPullToRefreshContainerView.swift @@ -25,10 +25,10 @@ open class RMRPullToRefreshContainerView: UIView { if let view = obtainView(state, result: result) { view.translatesAutoresizingMaskIntoConstraints = false addSubview(view) - addConstraint(constraint(self, subview: view, attribute: NSLayoutAttribute.left)) - addConstraint(constraint(self, subview: view, attribute: NSLayoutAttribute.top)) - addConstraint(constraint(self, subview: view, attribute: NSLayoutAttribute.right)) - addConstraint(constraint(self, subview: view, attribute: NSLayoutAttribute.bottom)) + addConstraint(constraint(self, subview: view, attribute: NSLayoutConstraint.Attribute.left)) + addConstraint(constraint(self, subview: view, attribute: NSLayoutConstraint.Attribute.top)) + addConstraint(constraint(self, subview: view, attribute: NSLayoutConstraint.Attribute.right)) + addConstraint(constraint(self, subview: view, attribute: NSLayoutConstraint.Attribute.bottom)) view.layoutIfNeeded() self.currentView = view } @@ -84,7 +84,7 @@ open class RMRPullToRefreshContainerView: UIView { // MARK: - Constraint - func constraint(_ superview: UIView, subview: UIView, attribute: NSLayoutAttribute) -> NSLayoutConstraint { - return NSLayoutConstraint(item: subview, attribute: attribute, relatedBy: NSLayoutRelation.equal, toItem: superview, attribute: attribute, multiplier: 1, constant: 0) + func constraint(_ superview: UIView, subview: UIView, attribute: NSLayoutConstraint.Attribute) -> NSLayoutConstraint { + return NSLayoutConstraint(item: subview, attribute: attribute, relatedBy: NSLayoutConstraint.Relation.equal, toItem: superview, attribute: attribute, multiplier: 1, constant: 0) } } diff --git a/Classes/RMRPullToRefreshController.swift b/Classes/RMRPullToRefreshController.swift index 8d293fa..599b2a7 100644 --- a/Classes/RMRPullToRefreshController.swift +++ b/Classes/RMRPullToRefreshController.swift @@ -230,7 +230,7 @@ open class RMRPullToRefreshController: NSObject { backgroundViewHeightConstraint?.constant = 0 } - private func scrollViewDidChangePanState(_ scrollView: UIScrollView, panState: UIGestureRecognizerState) { + private func scrollViewDidChangePanState(_ scrollView: UIScrollView, panState: UIGestureRecognizer.State) { if panState == .ended || panState == .cancelled || panState == .failed { if state == .loading || (shouldHideWhenStopLoading() && !stopped) { @@ -277,7 +277,7 @@ open class RMRPullToRefreshController: NSObject { if scrollView.contentOffset.y >= 0 { scrollView.contentInset = UIEdgeInsets.zero } else { - scrollView.contentInset = UIEdgeInsetsMake(min(-scrollView.contentOffset.y, originalTopInset+height),0,0,0) + scrollView.contentInset = UIEdgeInsets.init(top: min(-scrollView.contentOffset.y, originalTopInset+height),left: 0,bottom: 0,right: 0) } } @@ -353,7 +353,7 @@ open class RMRPullToRefreshController: NSObject { changingContentInset = true UIView.animate(withDuration: 0.3, delay: 0.0, - options: UIViewAnimationOptions.beginFromCurrentState, + options: UIView.AnimationOptions.beginFromCurrentState, animations: { [weak self]() -> Void in self?.scrollView?.contentInset = contentInset }, completion: { [weak self](finished) -> Void in diff --git a/Example/RMRPullToRefresh/AppDelegate.swift b/Example/RMRPullToRefresh/AppDelegate.swift index c410b83..4655fe4 100644 --- a/Example/RMRPullToRefresh/AppDelegate.swift +++ b/Example/RMRPullToRefresh/AppDelegate.swift @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } diff --git a/Example/RMRPullToRefreshExample.xcodeproj/project.pbxproj b/Example/RMRPullToRefreshExample.xcodeproj/project.pbxproj index 18f58c9..adcb369 100644 --- a/Example/RMRPullToRefreshExample.xcodeproj/project.pbxproj +++ b/Example/RMRPullToRefreshExample.xcodeproj/project.pbxproj @@ -132,7 +132,6 @@ 89CB12311C9DA07B00048E46 /* Frameworks */, 89CB12321C9DA07B00048E46 /* Resources */, 2BE863C51DEA329C1234F1B0 /* [CP] Embed Pods Frameworks */, - C137BE069515EFF1A69455DF /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -229,21 +228,6 @@ shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-RMRPullToRefreshExample/Pods-RMRPullToRefreshExample-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; - C137BE069515EFF1A69455DF /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-RMRPullToRefreshExample/Pods-RMRPullToRefreshExample-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -389,7 +373,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.redmadrobot.RMRPullToRefresh; PRODUCT_NAME = RMRPullToRefreshExample; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -403,7 +387,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.redmadrobot.RMRPullToRefresh; PRODUCT_NAME = RMRPullToRefreshExample; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; From baa205e0535cde9921cdd71628c16cfc394f4584 Mon Sep 17 00:00:00 2001 From: Jon Fir Date: Fri, 21 Sep 2018 10:20:00 +0700 Subject: [PATCH 12/14] =?UTF-8?q?=D0=A3=D1=81=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=BF=D1=80=D0=B5=D0=B4=D1=83=D0=BF=D1=80?= =?UTF-8?q?=D0=B5=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Example/RMRPullToRefreshExample.xcodeproj/project.pbxproj | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Example/RMRPullToRefreshExample.xcodeproj/project.pbxproj b/Example/RMRPullToRefreshExample.xcodeproj/project.pbxproj index adcb369..07510dd 100644 --- a/Example/RMRPullToRefreshExample.xcodeproj/project.pbxproj +++ b/Example/RMRPullToRefreshExample.xcodeproj/project.pbxproj @@ -149,7 +149,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0920; + LastUpgradeCheck = 1000; ORGANIZATIONNAME = "Merkulov Ilya"; TargetAttributes = { 89CB12331C9DA07B00048E46 = { @@ -277,12 +277,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -329,12 +331,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; From ba0dfe14897e8bda1512c0a049887e6020367fda Mon Sep 17 00:00:00 2001 From: Jon Fir Date: Fri, 21 Sep 2018 10:21:28 +0700 Subject: [PATCH 13/14] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=BD=D1=8F=D0=BB=20?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8E=20pod`=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RMRPullToRefresh.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RMRPullToRefresh.podspec b/RMRPullToRefresh.podspec index 064206c..77fc6c7 100644 --- a/RMRPullToRefresh.podspec +++ b/RMRPullToRefresh.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = "RMRPullToRefresh" - spec.version = "0.6.0" + spec.version = "0.7.0" spec.platform = :ios, "9.0" spec.license = { :type => "MIT", :file => "LICENSE" } spec.summary = "A pull to refresh control for UIScrollView (UITableView and UICollectionView)" From 99d4e48ed123a448e6bbd544ef3363dfd7985215 Mon Sep 17 00:00:00 2001 From: Evgenii Elchev Date: Mon, 15 Oct 2018 19:55:17 +0700 Subject: [PATCH 14/14] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=BD=D1=8F=D0=BB=20?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8E=20=D0=BF=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RMRPullToRefresh.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RMRPullToRefresh.podspec b/RMRPullToRefresh.podspec index 77fc6c7..4d1f32e 100644 --- a/RMRPullToRefresh.podspec +++ b/RMRPullToRefresh.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = "RMRPullToRefresh" - spec.version = "0.7.0" + spec.version = "0.8.0" spec.platform = :ios, "9.0" spec.license = { :type => "MIT", :file => "LICENSE" } spec.summary = "A pull to refresh control for UIScrollView (UITableView and UICollectionView)"