Skip to content

Commit

Permalink
Merge pull request #1 from lkzhao/wip
Browse files Browse the repository at this point in the history
Improving CollectionKit2
  • Loading branch information
honghaoz authored Feb 3, 2020
2 parents 9a5dce4 + ee07228 commit f3a1260
Show file tree
Hide file tree
Showing 38 changed files with 1,521 additions and 1,381 deletions.
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.0
13 changes: 13 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# rules
--enable isEmpty

# format options
--decimalgrouping none
--hexgrouping none
--importgrouping testable-bottom
--indent tab
--octalgrouping none
--self init-only
--semicolons never
--tabwidth 2
--ifdef no-indent
4 changes: 2 additions & 2 deletions CollectionKit2.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "CollectionKit2"
s.version = "0.1.0"
s.version = "0.2.0"
s.summary = "A modern swift framework for building data-driven reusable collection view components."

s.description = <<-DESC
Expand All @@ -26,7 +26,7 @@ Pod::Spec.new do |s|
s.author = { "Luke" => "[email protected]" }
s.source = { :git => "https://github.com/lkzhao/CollectionKit.git", :tag => s.version.to_s }

s.ios.deployment_target = '8.0'
s.ios.deployment_target = '12.0'
s.ios.frameworks = 'UIKit', 'Foundation'

s.requires_arc = true
Expand Down
17 changes: 12 additions & 5 deletions CollectionKit2.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
02229B072294D6EF00318C18 /* SingleChildProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02229B062294D6EF00318C18 /* SingleChildProvider.swift */; };
02229B092294D6FF00318C18 /* MultiChildProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02229B082294D6FF00318C18 /* MultiChildProvider.swift */; };
02229B0B2294D94600318C18 /* ViewProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02229B0A2294D94600318C18 /* ViewProvider.swift */; };
024B12C223E67AE0004F4D00 /* CollectionView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 024B12C123E67AE0004F4D00 /* CollectionView+Extensions.swift */; };
A304892821C347010026EDA7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A304892721C347010026EDA7 /* AppDelegate.swift */; };
A304892A21C347010026EDA7 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A304892921C347010026EDA7 /* ViewController.swift */; };
A304892D21C347010026EDA7 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A304892B21C347010026EDA7 /* Main.storyboard */; };
Expand Down Expand Up @@ -46,6 +47,7 @@
02229B062294D6EF00318C18 /* SingleChildProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleChildProvider.swift; sourceTree = "<group>"; };
02229B082294D6FF00318C18 /* MultiChildProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiChildProvider.swift; sourceTree = "<group>"; };
02229B0A2294D94600318C18 /* ViewProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewProvider.swift; sourceTree = "<group>"; };
024B12C123E67AE0004F4D00 /* CollectionView+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CollectionView+Extensions.swift"; sourceTree = "<group>"; };
A304892421C347010026EDA7 /* CollectionKit2.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CollectionKit2.app; sourceTree = BUILT_PRODUCTS_DIR; };
A304892721C347010026EDA7 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
A304892921C347010026EDA7 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -146,13 +148,14 @@
isa = PBXGroup;
children = (
A304893921C347190026EDA7 /* CollectionView.swift */,
024B12C123E67AE0004F4D00 /* CollectionView+Extensions.swift */,
A304894121C35F2F0026EDA7 /* CollectionReuseManager.swift */,
A31FEA4E21E44981008D7667 /* ClosureViewProvider.swift */,
A3881A6021D595B00088FA90 /* Animator.swift */,
A304893F21C347420026EDA7 /* Provider.swift */,
02229B0A2294D94600318C18 /* ViewProvider.swift */,
02229B062294D6EF00318C18 /* SingleChildProvider.swift */,
02229B082294D6FF00318C18 /* MultiChildProvider.swift */,
A31FEA4E21E44981008D7667 /* ClosureViewProvider.swift */,
A327227B21FABF6500FBB493 /* SimpleViewProvider.swift */,
A327227321FAA5B800FBB493 /* FitViewProvider.swift */,
A327227521FAA5D400FBB493 /* FillViewProvider.swift */,
Expand Down Expand Up @@ -198,6 +201,7 @@
TargetAttributes = {
A304892321C347010026EDA7 = {
CreatedOnToolsVersion = 10.1;
LastSwiftMigration = 1130;
};
};
};
Expand Down Expand Up @@ -267,6 +271,7 @@
A327227021F9328F00FBB493 /* UIView+CollectionKit.swift in Sources */,
A31FEA4B21E44871008D7667 /* SortedLayoutProvider.swift in Sources */,
A304892821C347010026EDA7 /* AppDelegate.swift in Sources */,
024B12C223E67AE0004F4D00 /* CollectionView+Extensions.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -343,7 +348,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.1;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -398,7 +403,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.1;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
Expand All @@ -418,9 +423,10 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.2.0;
PRODUCT_BUNDLE_IDENTIFIER = com.lkzhao.CollectionKit2;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -435,9 +441,10 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.2.0;
PRODUCT_BUNDLE_IDENTIFIER = com.lkzhao.CollectionKit2;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
106 changes: 53 additions & 53 deletions CollectionKit2/AnimatedReloadAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,67 +9,67 @@
import UIKit

class AnimatedReloadAnimator: Animator {
static let defaultEntryTransform: CATransform3D = CATransform3DTranslate(CATransform3DScale(CATransform3DIdentity, 0.8, 0.8, 1), 0, 0, 0)
static let fancyEntryTransform: CATransform3D = {
var trans = CATransform3DIdentity
trans.m34 = -1 / 500
return CATransform3DScale(CATransform3DRotate(CATransform3DTranslate(trans, 0, -50, -100), 0.5, 1, 0, 0), 0.8, 0.8, 1)
}()
static let defaultEntryTransform: CATransform3D = CATransform3DTranslate(CATransform3DScale(CATransform3DIdentity, 0.8, 0.8, 1), 0, 0, 0)
static let fancyEntryTransform: CATransform3D = {
var trans = CATransform3DIdentity
trans.m34 = -1 / 500
return CATransform3DScale(CATransform3DRotate(CATransform3DTranslate(trans, 0, -50, -100), 0.5, 1, 0, 0), 0.8, 0.8, 1)
}()

let entryTransform: CATransform3D
let entryTransform: CATransform3D

init(entryTransform: CATransform3D = defaultEntryTransform) {
self.entryTransform = entryTransform
super.init()
}
init(entryTransform: CATransform3D = defaultEntryTransform) {
self.entryTransform = entryTransform
super.init()
}

override func delete(collectionView: CollectionView, view: UIView) {
if collectionView.isReloading, collectionView.bounds.intersects(view.frame) {
UIView.animate(withDuration: 0.25, animations: {
view.layer.transform = self.entryTransform
view.alpha = 0
}, completion: { _ in
if !collectionView.visibleCells.contains(view) {
view.transform = CGAffineTransform.identity
view.alpha = 1
view.recycleForCollectionKitReuse()
}
override func delete(collectionView: CollectionView, view: UIView) {
if collectionView.isReloading, collectionView.bounds.intersects(view.frame) {
UIView.animate(withDuration: 0.25, animations: {
view.layer.transform = self.entryTransform
view.alpha = 0
}, completion: { _ in
if !collectionView.visibleCells.contains(view) {
view.transform = CGAffineTransform.identity
view.alpha = 1
view.recycleForCollectionKitReuse()
}
})
} else {
view.recycleForCollectionKitReuse()
}
}
} else {
view.recycleForCollectionKitReuse()
}
}

override func insert(collectionView: CollectionView, view: UIView, frame: CGRect) {
view.bounds = frame.bounds
view.center = frame.center
if collectionView.isReloading, collectionView.hasReloaded, collectionView.bounds.intersects(frame) {
let offsetTime: TimeInterval = TimeInterval(frame.origin.distance(collectionView.contentOffset) / 3000)
view.layer.transform = entryTransform
view.alpha = 0
UIView.animate(withDuration: 0.5, delay: offsetTime, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: [], animations: {
view.transform = .identity
view.alpha = 1
override func insert(collectionView: CollectionView, view: UIView, frame: CGRect) {
view.bounds = frame.bounds
view.center = frame.center
if collectionView.isReloading, collectionView.hasReloaded, collectionView.bounds.intersects(frame) {
let offsetTime: TimeInterval = TimeInterval(frame.origin.distance(collectionView.contentOffset) / 3000)
view.layer.transform = entryTransform
view.alpha = 0
UIView.animate(withDuration: 0.5, delay: offsetTime, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: [], animations: {
view.transform = .identity
view.alpha = 1
})
}
}
}
}

override func update(collectionView: CollectionView, view: UIView, frame: CGRect) {
if view.center != frame.center {
UIView.animate(withDuration: 0.6, delay: 0, usingSpringWithDamping: 0.9, initialSpringVelocity: 0, options: [.layoutSubviews], animations: {
view.center = frame.center
override func update(collectionView _: CollectionView, view: UIView, frame: CGRect) {
if view.center != frame.center {
UIView.animate(withDuration: 0.6, delay: 0, usingSpringWithDamping: 0.9, initialSpringVelocity: 0, options: [.layoutSubviews], animations: {
view.center = frame.center
}, completion: nil)
}
if view.bounds.size != frame.bounds.size {
UIView.animate(withDuration: 0.6, delay: 0, usingSpringWithDamping: 0.9, initialSpringVelocity: 0, options: [.layoutSubviews], animations: {
view.bounds.size = frame.bounds.size
}
if view.bounds.size != frame.bounds.size {
UIView.animate(withDuration: 0.6, delay: 0, usingSpringWithDamping: 0.9, initialSpringVelocity: 0, options: [.layoutSubviews], animations: {
view.bounds.size = frame.bounds.size
}, completion: nil)
}
if view.alpha != 1 || view.transform != .identity {
UIView.animate(withDuration: 0.6, delay: 0, usingSpringWithDamping: 0.9, initialSpringVelocity: 0, options: [], animations: {
view.transform = .identity
view.alpha = 1
}
if view.alpha != 1 || view.transform != .identity {
UIView.animate(withDuration: 0.6, delay: 0, usingSpringWithDamping: 0.9, initialSpringVelocity: 0, options: [], animations: {
view.transform = .identity
view.alpha = 1
}, completion: nil)
}
}
}
}
}
61 changes: 28 additions & 33 deletions CollectionKit2/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,32 @@ import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


var window: UIWindow?

func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(_: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}

Loading

0 comments on commit f3a1260

Please sign in to comment.