From c69e6898d6faad37abea0d4240a19ba82a0b16ec Mon Sep 17 00:00:00 2001 From: janlionly Date: Sat, 20 Jun 2020 18:25:42 +0800 Subject: [PATCH 1/2] feat: support for SwiftPM --- .../contents.xcworkspacedata | 7 ++ Package.swift | 29 ++++++++ SVPullToRefresh/include/SVPullToRefresh.h | 15 +++++ .../UIScrollView+SVInfiniteScrolling.h | 45 +++++++++++++ .../include/UIScrollView+SVPullToRefresh.h | 67 +++++++++++++++++++ Tests/LinuxMain.swift | 7 ++ .../SVPullToRefreshTests.swift | 15 +++++ .../XCTestManifests.swift | 9 +++ 8 files changed, 194 insertions(+) create mode 100644 .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata create mode 100644 Package.swift create mode 100644 SVPullToRefresh/include/SVPullToRefresh.h create mode 100644 SVPullToRefresh/include/UIScrollView+SVInfiniteScrolling.h create mode 100644 SVPullToRefresh/include/UIScrollView+SVPullToRefresh.h create mode 100644 Tests/LinuxMain.swift create mode 100644 Tests/SVPullToRefreshTests/SVPullToRefreshTests.swift create mode 100644 Tests/SVPullToRefreshTests/XCTestManifests.swift diff --git a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Package.swift b/Package.swift new file mode 100644 index 00000000..7db4d901 --- /dev/null +++ b/Package.swift @@ -0,0 +1,29 @@ +// swift-tools-version:5.2 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "SVPullToRefresh", + products: [ + // Products define the executables and libraries produced by a package, and make them visible to other packages. + .library( + name: "SVPullToRefresh", + targets: ["SVPullToRefresh"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages which this package depends on. + .target( + name: "SVPullToRefresh", + dependencies: [], + path: "SVPullToRefresh"), + .testTarget( + name: "SVPullToRefreshTests", + dependencies: ["SVPullToRefresh"]), + ] +) diff --git a/SVPullToRefresh/include/SVPullToRefresh.h b/SVPullToRefresh/include/SVPullToRefresh.h new file mode 100644 index 00000000..1031b937 --- /dev/null +++ b/SVPullToRefresh/include/SVPullToRefresh.h @@ -0,0 +1,15 @@ +// +// SVPullToRefresh.h +// SVPullToRefreshDemo +// +// Created by Sam Vermette on 23.04.12. +// Copyright (c) 2012 samvermette.com. All rights reserved. +// +// https://github.com/samvermette/SVPullToRefresh +// + +// this header file is provided for backwards compatibility and will be removed in the future +// here's how you should import SVPullToRefresh now: + +#import "UIScrollView+SVPullToRefresh.h" +#import "UIScrollView+SVInfiniteScrolling.h" diff --git a/SVPullToRefresh/include/UIScrollView+SVInfiniteScrolling.h b/SVPullToRefresh/include/UIScrollView+SVInfiniteScrolling.h new file mode 100644 index 00000000..7ce16501 --- /dev/null +++ b/SVPullToRefresh/include/UIScrollView+SVInfiniteScrolling.h @@ -0,0 +1,45 @@ +// +// UIScrollView+SVInfiniteScrolling.h +// +// Created by Sam Vermette on 23.04.12. +// Copyright (c) 2012 samvermette.com. All rights reserved. +// +// https://github.com/samvermette/SVPullToRefresh +// + +#import + +@class SVInfiniteScrollingView; + +@interface UIScrollView (SVInfiniteScrolling) + +- (void)addInfiniteScrollingWithActionHandler:(void (^)(void))actionHandler; +- (void)triggerInfiniteScrolling; + +@property (nonatomic, strong, readonly) SVInfiniteScrollingView *infiniteScrollingView; +@property (nonatomic, assign) BOOL showsInfiniteScrolling; + +@end + + +enum { + SVInfiniteScrollingStateStopped = 0, + SVInfiniteScrollingStateTriggered, + SVInfiniteScrollingStateLoading, + SVInfiniteScrollingStateAll = 10 +}; + +typedef NSUInteger SVInfiniteScrollingState; + +@interface SVInfiniteScrollingView : UIView + +@property (nonatomic, readwrite) UIActivityIndicatorViewStyle activityIndicatorViewStyle; +@property (nonatomic, readonly) SVInfiniteScrollingState state; +@property (nonatomic, readwrite) BOOL enabled; + +- (void)setCustomView:(UIView *)view forState:(SVInfiniteScrollingState)state; + +- (void)startAnimating; +- (void)stopAnimating; + +@end diff --git a/SVPullToRefresh/include/UIScrollView+SVPullToRefresh.h b/SVPullToRefresh/include/UIScrollView+SVPullToRefresh.h new file mode 100644 index 00000000..73c92b7f --- /dev/null +++ b/SVPullToRefresh/include/UIScrollView+SVPullToRefresh.h @@ -0,0 +1,67 @@ +// +// UIScrollView+SVPullToRefresh.h +// +// Created by Sam Vermette on 23.04.12. +// Copyright (c) 2012 samvermette.com. All rights reserved. +// +// https://github.com/samvermette/SVPullToRefresh +// + +#import +#import + + +@class SVPullToRefreshView; + +@interface UIScrollView (SVPullToRefresh) + +typedef NS_ENUM(NSUInteger, SVPullToRefreshPosition) { + SVPullToRefreshPositionTop = 0, + SVPullToRefreshPositionBottom, +}; + +- (void)addPullToRefreshWithActionHandler:(void (^)(void))actionHandler; +- (void)addPullToRefreshWithActionHandler:(void (^)(void))actionHandler position:(SVPullToRefreshPosition)position; +- (void)triggerPullToRefresh; + +@property (nonatomic, strong, readonly) SVPullToRefreshView *pullToRefreshView; +@property (nonatomic, assign) BOOL showsPullToRefresh; + +@end + + +typedef NS_ENUM(NSUInteger, SVPullToRefreshState) { + SVPullToRefreshStateStopped = 0, + SVPullToRefreshStateTriggered, + SVPullToRefreshStateLoading, + SVPullToRefreshStateAll = 10 +}; + +@interface SVPullToRefreshView : UIView + +@property (nonatomic, strong) UIColor *arrowColor; +@property (nonatomic, strong) UIColor *textColor; +@property (nonatomic, strong, readonly) UILabel *titleLabel; +@property (nonatomic, strong, readonly) UILabel *subtitleLabel; +@property (nonatomic, strong, readwrite) UIColor *activityIndicatorViewColor NS_AVAILABLE_IOS(5_0); +@property (nonatomic, readwrite) UIActivityIndicatorViewStyle activityIndicatorViewStyle; + +@property (nonatomic, readonly) SVPullToRefreshState state; +@property (nonatomic, readonly) SVPullToRefreshPosition position; + +- (void)setTitle:(NSString *)title forState:(SVPullToRefreshState)state; +- (void)setSubtitle:(NSString *)subtitle forState:(SVPullToRefreshState)state; +- (void)setCustomView:(UIView *)view forState:(SVPullToRefreshState)state; + +- (void)startAnimating; +- (void)stopAnimating; + +// deprecated; use setSubtitle:forState: instead +@property (nonatomic, strong, readonly) UILabel *dateLabel DEPRECATED_ATTRIBUTE; +@property (nonatomic, strong) NSDate *lastUpdatedDate DEPRECATED_ATTRIBUTE; +@property (nonatomic, strong) NSDateFormatter *dateFormatter DEPRECATED_ATTRIBUTE; + +// deprecated; use [self.scrollView triggerPullToRefresh] instead +- (void)triggerRefresh DEPRECATED_ATTRIBUTE; + +@end diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift new file mode 100644 index 00000000..34b946b6 --- /dev/null +++ b/Tests/LinuxMain.swift @@ -0,0 +1,7 @@ +import XCTest + +import SVPullToRefreshTests + +var tests = [XCTestCaseEntry]() +tests += SVPullToRefreshTests.allTests() +XCTMain(tests) diff --git a/Tests/SVPullToRefreshTests/SVPullToRefreshTests.swift b/Tests/SVPullToRefreshTests/SVPullToRefreshTests.swift new file mode 100644 index 00000000..c9e0117e --- /dev/null +++ b/Tests/SVPullToRefreshTests/SVPullToRefreshTests.swift @@ -0,0 +1,15 @@ +import XCTest +@testable import SVPullToRefresh + +final class SVPullToRefreshTests: XCTestCase { + func testExample() { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct + // results. + XCTAssertEqual(SVPullToRefresh().text, "Hello, World!") + } + + static var allTests = [ + ("testExample", testExample), + ] +} diff --git a/Tests/SVPullToRefreshTests/XCTestManifests.swift b/Tests/SVPullToRefreshTests/XCTestManifests.swift new file mode 100644 index 00000000..c6b11f14 --- /dev/null +++ b/Tests/SVPullToRefreshTests/XCTestManifests.swift @@ -0,0 +1,9 @@ +import XCTest + +#if !canImport(ObjectiveC) +public func allTests() -> [XCTestCaseEntry] { + return [ + testCase(SVPullToRefreshTests.allTests), + ] +} +#endif From 407dfae9aaad0818264692be1c0ed8bbeea68a75 Mon Sep 17 00:00:00 2001 From: janlionly Date: Tue, 17 Nov 2020 21:42:14 +0800 Subject: [PATCH 2/2] fix: set custom view hide indicator when stopped --- SVPullToRefresh/UIScrollView+SVInfiniteScrolling.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SVPullToRefresh/UIScrollView+SVInfiniteScrolling.m b/SVPullToRefresh/UIScrollView+SVInfiniteScrolling.m index e43490ec..c3f594a5 100644 --- a/SVPullToRefresh/UIScrollView+SVInfiniteScrolling.m +++ b/SVPullToRefresh/UIScrollView+SVInfiniteScrolling.m @@ -276,6 +276,10 @@ - (void)setState:(SVInfiniteScrollingState)newState { CGRect viewBounds = [customView bounds]; CGPoint origin = CGPointMake(roundf((self.bounds.size.width-viewBounds.size.width)/2), roundf((self.bounds.size.height-viewBounds.size.height)/2)); [customView setFrame:CGRectMake(origin.x, origin.y, viewBounds.size.width, viewBounds.size.height)]; + + if (newState == SVInfiniteScrollingStateStopped) { + [self.activityIndicatorView stopAnimating]; + } } else { CGRect viewBounds = [self.activityIndicatorView bounds];