diff --git a/SkeletonView.podspec b/SkeletonView.podspec index cdd17bcf..f4fae540 100644 --- a/SkeletonView.podspec +++ b/SkeletonView.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SkeletonView" - s.version = "1.22.0" + s.version = "1.23.0" s.summary = "An elegant way to show users that something is happening and also prepare them to which contents he is waiting" s.description = <<-DESC Today almost all apps have async processes, as API requests, long runing processes, etc. And while the processes are working, usually developers place a loading view to show users that something is going on. diff --git a/SkeletonView.xcodeproj/project.pbxproj b/SkeletonView.xcodeproj/project.pbxproj index e070b2d5..4cc3982f 100644 --- a/SkeletonView.xcodeproj/project.pbxproj +++ b/SkeletonView.xcodeproj/project.pbxproj @@ -10,10 +10,9 @@ F556F56626CD1F3900A80B83 /* SkeletonAppearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_9 /* SkeletonAppearance.swift */; }; F556F56726CD1F3900A80B83 /* SkeletonLayerBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_11 /* SkeletonLayerBuilder.swift */; }; F556F56826CD1F3900A80B83 /* SkeletonMultilineLayerBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_12 /* SkeletonMultilineLayerBuilder.swift */; }; - F556F56926CD1F3900A80B83 /* CollectionSkeletonProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_14 /* CollectionSkeletonProtocol.swift */; }; + F556F56926CD1F3900A80B83 /* CollectionSkeleton.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_14 /* CollectionSkeleton.swift */; }; F556F56A26CD1F3900A80B83 /* SkeletonCollectionViewProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_16 /* SkeletonCollectionViewProtocols.swift */; }; F556F56B26CD1F3900A80B83 /* UICollectionView+CollectionSkeleton.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_17 /* UICollectionView+CollectionSkeleton.swift */; }; - F556F56C26CD1F3900A80B83 /* GenericCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_19 /* GenericCollectionView.swift */; }; F556F56D26CD1F3900A80B83 /* SkeletonReusableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_20 /* SkeletonReusableCell.swift */; }; F556F56E26CD1F3900A80B83 /* SkeletonCollectionDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_21 /* SkeletonCollectionDataSource.swift */; }; F556F56F26CD1F3900A80B83 /* SkeletonCollectionDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_22 /* SkeletonCollectionDelegate.swift */; }; @@ -87,6 +86,8 @@ F556F6CD26CE2A7400A80B83 /* UITextView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F556F6CB26CE2A7400A80B83 /* UITextView+Extensions.swift */; }; F556F6CF26CE2AB800A80B83 /* SkeletonTextNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = F556F6CE26CE2AB800A80B83 /* SkeletonTextNode.swift */; }; F556F6D026CE2AB800A80B83 /* SkeletonTextNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = F556F6CE26CE2AB800A80B83 /* SkeletonTextNode.swift */; }; + F556F6D926CE315A00A80B83 /* UICollectionView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F556F6D826CE315A00A80B83 /* UICollectionView+Extensions.swift */; }; + F556F6DA26CE315A00A80B83 /* UICollectionView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F556F6D826CE315A00A80B83 /* UICollectionView+Extensions.swift */; }; OBJ_101 /* Int+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_31 /* Int+Extensions.swift */; }; OBJ_103 /* UIColor+Skeleton.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_33 /* UIColor+Skeleton.swift */; }; OBJ_104 /* UITableView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_34 /* UITableView+Extensions.swift */; }; @@ -109,10 +110,9 @@ OBJ_86 /* SkeletonAppearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_9 /* SkeletonAppearance.swift */; }; OBJ_87 /* SkeletonLayerBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_11 /* SkeletonLayerBuilder.swift */; }; OBJ_88 /* SkeletonMultilineLayerBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_12 /* SkeletonMultilineLayerBuilder.swift */; }; - OBJ_89 /* CollectionSkeletonProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_14 /* CollectionSkeletonProtocol.swift */; }; + OBJ_89 /* CollectionSkeleton.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_14 /* CollectionSkeleton.swift */; }; OBJ_90 /* SkeletonCollectionViewProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_16 /* SkeletonCollectionViewProtocols.swift */; }; OBJ_91 /* UICollectionView+CollectionSkeleton.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_17 /* UICollectionView+CollectionSkeleton.swift */; }; - OBJ_92 /* GenericCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_19 /* GenericCollectionView.swift */; }; OBJ_93 /* SkeletonReusableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_20 /* SkeletonReusableCell.swift */; }; OBJ_94 /* SkeletonCollectionDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_21 /* SkeletonCollectionDataSource.swift */; }; OBJ_95 /* SkeletonCollectionDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_22 /* SkeletonCollectionDelegate.swift */; }; @@ -191,12 +191,12 @@ F556F6C826CE2A4A00A80B83 /* UITextView+IBInspectable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITextView+IBInspectable.swift"; sourceTree = ""; }; F556F6CB26CE2A7400A80B83 /* UITextView+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITextView+Extensions.swift"; sourceTree = ""; }; F556F6CE26CE2AB800A80B83 /* SkeletonTextNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkeletonTextNode.swift; sourceTree = ""; }; + F556F6D826CE315A00A80B83 /* UICollectionView+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UICollectionView+Extensions.swift"; sourceTree = ""; }; OBJ_11 /* SkeletonLayerBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkeletonLayerBuilder.swift; sourceTree = ""; }; OBJ_12 /* SkeletonMultilineLayerBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkeletonMultilineLayerBuilder.swift; sourceTree = ""; }; - OBJ_14 /* CollectionSkeletonProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionSkeletonProtocol.swift; sourceTree = ""; }; + OBJ_14 /* CollectionSkeleton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionSkeleton.swift; sourceTree = ""; }; OBJ_16 /* SkeletonCollectionViewProtocols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkeletonCollectionViewProtocols.swift; sourceTree = ""; }; OBJ_17 /* UICollectionView+CollectionSkeleton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UICollectionView+CollectionSkeleton.swift"; sourceTree = ""; }; - OBJ_19 /* GenericCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenericCollectionView.swift; sourceTree = ""; }; OBJ_20 /* SkeletonReusableCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkeletonReusableCell.swift; sourceTree = ""; }; OBJ_21 /* SkeletonCollectionDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkeletonCollectionDataSource.swift; sourceTree = ""; }; OBJ_22 /* SkeletonCollectionDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkeletonCollectionDelegate.swift; sourceTree = ""; }; @@ -343,6 +343,7 @@ F556F64A26CD2CD100A80B83 /* API */ = { isa = PBXGroup; children = ( + F556F6D726CE30EE00A80B83 /* Collections */, F556F6B726CE25B100A80B83 /* Models */, F556F6B226CE24DA00A80B83 /* AnimationBuilder */, OBJ_8 /* Appearance */, @@ -357,15 +358,16 @@ F556F64B26CD2CD600A80B83 /* Internal */ = { isa = PBXGroup; children = ( - OBJ_54 /* SkeletonFlowHandler.swift */, + F556F6D326CE2F3700A80B83 /* Collections */, + F556F65226CD2E0A00A80B83 /* Debug */, + F556F67E26CD476300A80B83 /* FoundationExtensions */, + F556F6AD26CE241D00A80B83 /* Helpers */, F556F6C426CE284300A80B83 /* Models */, + F556F6A926CD5C3E00A80B83 /* SkeletonConfigs */, F556F6B326CE256D00A80B83 /* SkeletonExtensions */, + OBJ_54 /* SkeletonFlowHandler.swift */, F556F6B126CE246E00A80B83 /* SkeletonLayerBuilders */, - F556F6AD26CE241D00A80B83 /* Helpers */, - F556F6A926CD5C3E00A80B83 /* SkeletonConfigs */, - F556F67E26CD476300A80B83 /* FoundationExtensions */, F556F67D26CD475800A80B83 /* UIKitExtensions */, - F556F65226CD2E0A00A80B83 /* Debug */, ); path = Internal; sourceTree = ""; @@ -389,15 +391,18 @@ F556F67D26CD475800A80B83 /* UIKitExtensions */ = { isa = PBXGroup; children = ( - OBJ_61 /* UIView+Transitions.swift */, - OBJ_39 /* UIView+AppLifecycleNotifications.swift */, - OBJ_34 /* UITableView+Extensions.swift */, - F556F68226CD48F700A80B83 /* UIView+AssociatedObjects.swift */, - F556F69D26CD553B00A80B83 /* UIView+Extensions.swift */, F556F6A626CD5B0400A80B83 /* CALayer+Extensions.swift */, + OBJ_17 /* UICollectionView+CollectionSkeleton.swift */, OBJ_33 /* UIColor+Skeleton.swift */, F556F6BB26CE272600A80B83 /* UILabel+Extensions.swift */, + OBJ_25 /* UITableView+CollectionSkeleton.swift */, + OBJ_34 /* UITableView+Extensions.swift */, F556F6CB26CE2A7400A80B83 /* UITextView+Extensions.swift */, + OBJ_39 /* UIView+AppLifecycleNotifications.swift */, + F556F68226CD48F700A80B83 /* UIView+AssociatedObjects.swift */, + OBJ_26 /* UIView+CollectionSkeleton.swift */, + F556F69D26CD553B00A80B83 /* UIView+Extensions.swift */, + OBJ_61 /* UIView+Transitions.swift */, ); path = UIKitExtensions; sourceTree = ""; @@ -421,6 +426,7 @@ F556F6A026CD566C00A80B83 /* UIView+Debug.swift */, F556F6C526CE2A2100A80B83 /* UILabel+IBInspectable.swift */, F556F6C826CE2A4A00A80B83 /* UITextView+IBInspectable.swift */, + F556F6D826CE315A00A80B83 /* UICollectionView+Extensions.swift */, ); path = UIKitExtensions; sourceTree = ""; @@ -481,10 +487,10 @@ isa = PBXGroup; children = ( OBJ_58 /* SubviewsSkeletonables.swift */, - F556F6B426CE258300A80B83 /* GradientDirection+Animations.swift */, F556F6BE26CE277F00A80B83 /* PrepareViewForSkeleton.swift */, - OBJ_50 /* Recoverable.swift */, F556F6CE26CE2AB800A80B83 /* SkeletonTextNode.swift */, + OBJ_50 /* Recoverable.swift */, + F556F6B426CE258300A80B83 /* GradientDirection+Animations.swift */, ); path = SkeletonExtensions; sourceTree = ""; @@ -509,43 +515,38 @@ path = Models; sourceTree = ""; }; - OBJ_13 /* Collections */ = { + F556F6D326CE2F3700A80B83 /* Collections */ = { isa = PBXGroup; children = ( - OBJ_14 /* CollectionSkeletonProtocol.swift */, - OBJ_15 /* CollectionViews */, - OBJ_18 /* Generics */, OBJ_21 /* SkeletonCollectionDataSource.swift */, OBJ_22 /* SkeletonCollectionDelegate.swift */, - OBJ_23 /* TableViews */, - OBJ_26 /* UIView+CollectionSkeleton.swift */, + OBJ_20 /* SkeletonReusableCell.swift */, + OBJ_14 /* CollectionSkeleton.swift */, ); path = Collections; sourceTree = ""; }; - OBJ_15 /* CollectionViews */ = { + F556F6D726CE30EE00A80B83 /* Collections */ = { isa = PBXGroup; children = ( - OBJ_16 /* SkeletonCollectionViewProtocols.swift */, - OBJ_17 /* UICollectionView+CollectionSkeleton.swift */, + OBJ_23 /* TableViews */, + OBJ_15 /* CollectionViews */, ); - path = CollectionViews; + path = Collections; sourceTree = ""; }; - OBJ_18 /* Generics */ = { + OBJ_15 /* CollectionViews */ = { isa = PBXGroup; children = ( - OBJ_19 /* GenericCollectionView.swift */, - OBJ_20 /* SkeletonReusableCell.swift */, + OBJ_16 /* SkeletonCollectionViewProtocols.swift */, ); - path = Generics; + path = CollectionViews; sourceTree = ""; }; OBJ_23 /* TableViews */ = { isa = PBXGroup; children = ( OBJ_24 /* SkeletonTableViewProtocols.swift */, - OBJ_25 /* UITableView+CollectionSkeleton.swift */, ); path = TableViews; sourceTree = ""; @@ -588,7 +589,6 @@ F556F64B26CD2CD600A80B83 /* Internal */, F556F64A26CD2CD100A80B83 /* API */, F556F55F26CD1D4400A80B83 /* Supporting Files */, - OBJ_13 /* Collections */, OBJ_57 /* SkeletonView.swift */, ); name = Sources; @@ -770,12 +770,11 @@ F556F6D026CE2AB800A80B83 /* SkeletonTextNode.swift in Sources */, F556F65126CD2DFD00A80B83 /* PublicSkeletonView.swift in Sources */, F556F56826CD1F3900A80B83 /* SkeletonMultilineLayerBuilder.swift in Sources */, - F556F56926CD1F3900A80B83 /* CollectionSkeletonProtocol.swift in Sources */, + F556F56926CD1F3900A80B83 /* CollectionSkeleton.swift in Sources */, F556F56A26CD1F3900A80B83 /* SkeletonCollectionViewProtocols.swift in Sources */, F556F6C026CE277F00A80B83 /* PrepareViewForSkeleton.swift in Sources */, F556F6A826CD5B0400A80B83 /* CALayer+Extensions.swift in Sources */, F556F56B26CD1F3900A80B83 /* UICollectionView+CollectionSkeleton.swift in Sources */, - F556F56C26CD1F3900A80B83 /* GenericCollectionView.swift in Sources */, F556F56D26CD1F3900A80B83 /* SkeletonReusableCell.swift in Sources */, F556F56E26CD1F3900A80B83 /* SkeletonCollectionDataSource.swift in Sources */, F556F56F26CD1F3900A80B83 /* SkeletonCollectionDelegate.swift in Sources */, @@ -815,6 +814,7 @@ F556F68126CD47CF00A80B83 /* ProcessInfo+Extensions.swift in Sources */, F556F68826CD49F900A80B83 /* UIView+IBInspectable.swift in Sources */, F556F6C726CE2A2100A80B83 /* UILabel+IBInspectable.swift in Sources */, + F556F6DA26CE315A00A80B83 /* UICollectionView+Extensions.swift in Sources */, F556F64E26CD2D3D00A80B83 /* SkeletonDebug.swift in Sources */, F556F6A526CD5A9000A80B83 /* CALayer+Animations.swift in Sources */, F556F58F26CD1F3900A80B83 /* UIView+Transitions.swift in Sources */, @@ -847,12 +847,11 @@ F556F6CF26CE2AB800A80B83 /* SkeletonTextNode.swift in Sources */, F556F65026CD2DFD00A80B83 /* PublicSkeletonView.swift in Sources */, OBJ_88 /* SkeletonMultilineLayerBuilder.swift in Sources */, - OBJ_89 /* CollectionSkeletonProtocol.swift in Sources */, + OBJ_89 /* CollectionSkeleton.swift in Sources */, OBJ_90 /* SkeletonCollectionViewProtocols.swift in Sources */, F556F6BF26CE277F00A80B83 /* PrepareViewForSkeleton.swift in Sources */, F556F6A726CD5B0400A80B83 /* CALayer+Extensions.swift in Sources */, OBJ_91 /* UICollectionView+CollectionSkeleton.swift in Sources */, - OBJ_92 /* GenericCollectionView.swift in Sources */, OBJ_93 /* SkeletonReusableCell.swift in Sources */, OBJ_94 /* SkeletonCollectionDataSource.swift in Sources */, OBJ_95 /* SkeletonCollectionDelegate.swift in Sources */, @@ -892,6 +891,7 @@ F556F68026CD47CF00A80B83 /* ProcessInfo+Extensions.swift in Sources */, F556F68726CD49F900A80B83 /* UIView+IBInspectable.swift in Sources */, F556F6C626CE2A2100A80B83 /* UILabel+IBInspectable.swift in Sources */, + F556F6D926CE315A00A80B83 /* UICollectionView+Extensions.swift in Sources */, F556F64D26CD2CF800A80B83 /* SkeletonDebug.swift in Sources */, F556F6A426CD5A9000A80B83 /* CALayer+Animations.swift in Sources */, OBJ_127 /* UIView+Transitions.swift in Sources */, diff --git a/SkeletonViewCore/Sources/Collections/CollectionViews/SkeletonCollectionViewProtocols.swift b/SkeletonViewCore/Sources/API/Collections/CollectionViews/SkeletonCollectionViewProtocols.swift similarity index 100% rename from SkeletonViewCore/Sources/Collections/CollectionViews/SkeletonCollectionViewProtocols.swift rename to SkeletonViewCore/Sources/API/Collections/CollectionViews/SkeletonCollectionViewProtocols.swift diff --git a/SkeletonViewCore/Sources/Collections/TableViews/SkeletonTableViewProtocols.swift b/SkeletonViewCore/Sources/API/Collections/TableViews/SkeletonTableViewProtocols.swift similarity index 94% rename from SkeletonViewCore/Sources/Collections/TableViews/SkeletonTableViewProtocols.swift rename to SkeletonViewCore/Sources/API/Collections/TableViews/SkeletonTableViewProtocols.swift index c7e8648a..fa1f7faa 100644 --- a/SkeletonViewCore/Sources/Collections/TableViews/SkeletonTableViewProtocols.swift +++ b/SkeletonViewCore/Sources/API/Collections/TableViews/SkeletonTableViewProtocols.swift @@ -8,6 +8,12 @@ import UIKit +extension UITableView { + public static let automaticNumberOfSkeletonRows = -1 +} + +public typealias ReusableHeaderFooterIdentifier = String + public protocol SkeletonTableViewDataSource: UITableViewDataSource { func numSections(in collectionSkeletonView: UITableView) -> Int func collectionSkeletonView(_ skeletonView: UITableView, numberOfRowsInSection section: Int) -> Int diff --git a/SkeletonViewCore/Sources/API/UIKitExtensions/UICollectionView+Extensions.swift b/SkeletonViewCore/Sources/API/UIKitExtensions/UICollectionView+Extensions.swift new file mode 100644 index 00000000..b34361cd --- /dev/null +++ b/SkeletonViewCore/Sources/API/UIKitExtensions/UICollectionView+Extensions.swift @@ -0,0 +1,34 @@ +// +// Copyright SkeletonView. All Rights Reserved. +// +// Licensed under the MIT License (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://opensource.org/licenses/MIT +// +// UICollectionView+Extensions.swift +// +// Created by Juanpe Catalán on 19/8/21. + +import UIKit + +public extension UICollectionView { + + static let automaticNumberOfSkeletonItems = -1 + + func prepareSkeleton(completion: @escaping (Bool) -> Void) { + guard let originalDataSource = self.dataSource as? SkeletonCollectionViewDataSource, + !(originalDataSource is SkeletonCollectionDataSource) + else { return } + + let dataSource = SkeletonCollectionDataSource(collectionViewDataSource: originalDataSource, rowHeight: 0.0) + self.skeletonDataSource = dataSource + performBatchUpdates({ + self.reloadData() + }) { done in + completion(done) + + } + } +} diff --git a/SkeletonViewCore/Sources/Collections/Generics/GenericCollectionView.swift b/SkeletonViewCore/Sources/Collections/Generics/GenericCollectionView.swift deleted file mode 100644 index 23682cbe..00000000 --- a/SkeletonViewCore/Sources/Collections/Generics/GenericCollectionView.swift +++ /dev/null @@ -1,13 +0,0 @@ -// -// GenericCollectionView.swift -// SkeletonView-iOS -// -// Created by Juanpe Catalán on 30/03/2018. -// Copyright © 2018 SkeletonView. All rights reserved. -// - -import UIKit - -protocol GenericCollectionView { - var scrollView: UIScrollView { get } -} diff --git a/SkeletonViewCore/Sources/Collections/CollectionSkeletonProtocol.swift b/SkeletonViewCore/Sources/Internal/Collections/CollectionSkeleton.swift similarity index 98% rename from SkeletonViewCore/Sources/Collections/CollectionSkeletonProtocol.swift rename to SkeletonViewCore/Sources/Internal/Collections/CollectionSkeleton.swift index 9aff9706..578ad596 100644 --- a/SkeletonViewCore/Sources/Collections/CollectionSkeletonProtocol.swift +++ b/SkeletonViewCore/Sources/Internal/Collections/CollectionSkeleton.swift @@ -14,6 +14,7 @@ enum CollectionAssociatedKeys { } protocol CollectionSkeleton { + var skeletonDataSource: SkeletonCollectionDataSource? { get set } var skeletonDelegate: SkeletonCollectionDelegate? { get set } var estimatedNumberOfRows: Int { get } @@ -23,9 +24,11 @@ protocol CollectionSkeleton { func removeDummyDataSource(reloadAfter: Bool) func disableUserInteraction() func enableUserInteraction() + } extension CollectionSkeleton where Self: UIScrollView { + var estimatedNumberOfRows: Int { return 0 } func addDummyDataSource() {} func removeDummyDataSource(reloadAfter: Bool) {} @@ -43,4 +46,5 @@ extension CollectionSkeleton where Self: UIScrollView { isScrollEnabled = true } } + } diff --git a/SkeletonViewCore/Sources/Collections/SkeletonCollectionDataSource.swift b/SkeletonViewCore/Sources/Internal/Collections/SkeletonCollectionDataSource.swift similarity index 100% rename from SkeletonViewCore/Sources/Collections/SkeletonCollectionDataSource.swift rename to SkeletonViewCore/Sources/Internal/Collections/SkeletonCollectionDataSource.swift diff --git a/SkeletonViewCore/Sources/Collections/SkeletonCollectionDelegate.swift b/SkeletonViewCore/Sources/Internal/Collections/SkeletonCollectionDelegate.swift similarity index 100% rename from SkeletonViewCore/Sources/Collections/SkeletonCollectionDelegate.swift rename to SkeletonViewCore/Sources/Internal/Collections/SkeletonCollectionDelegate.swift diff --git a/SkeletonViewCore/Sources/Collections/Generics/SkeletonReusableCell.swift b/SkeletonViewCore/Sources/Internal/Collections/SkeletonReusableCell.swift similarity index 100% rename from SkeletonViewCore/Sources/Collections/Generics/SkeletonReusableCell.swift rename to SkeletonViewCore/Sources/Internal/Collections/SkeletonReusableCell.swift diff --git a/SkeletonViewCore/Sources/Collections/CollectionViews/UICollectionView+CollectionSkeleton.swift b/SkeletonViewCore/Sources/Internal/UIKitExtensions/UICollectionView+CollectionSkeleton.swift similarity index 74% rename from SkeletonViewCore/Sources/Collections/CollectionViews/UICollectionView+CollectionSkeleton.swift rename to SkeletonViewCore/Sources/Internal/UIKitExtensions/UICollectionView+CollectionSkeleton.swift index 701185d7..c5c9451b 100644 --- a/SkeletonViewCore/Sources/Collections/CollectionViews/UICollectionView+CollectionSkeleton.swift +++ b/SkeletonViewCore/Sources/Internal/UIKitExtensions/UICollectionView+CollectionSkeleton.swift @@ -9,7 +9,6 @@ import UIKit extension UICollectionView: CollectionSkeleton { - public static let automaticNumberOfSkeletonItems = -1 var estimatedNumberOfRows: Int { guard let flowlayout = collectionViewLayout as? UICollectionViewFlowLayout else { return 0 } @@ -63,25 +62,5 @@ extension UICollectionView: CollectionSkeleton { self.dataSource = dataSource.originalCollectionViewDataSource if reloadAfter { self.reloadData() } } -} - -extension UICollectionView: GenericCollectionView { - var scrollView: UIScrollView { return self } -} - -public extension UICollectionView { - func prepareSkeleton(completion: @escaping (Bool) -> Void) { - guard let originalDataSource = self.dataSource as? SkeletonCollectionViewDataSource, - !(originalDataSource is SkeletonCollectionDataSource) - else { return } - - let dataSource = SkeletonCollectionDataSource(collectionViewDataSource: originalDataSource, rowHeight: 0.0) - self.skeletonDataSource = dataSource - performBatchUpdates({ - self.reloadData() - }) { done in - completion(done) - - } - } + } diff --git a/SkeletonViewCore/Sources/Collections/TableViews/UITableView+CollectionSkeleton.swift b/SkeletonViewCore/Sources/Internal/UIKitExtensions/UITableView+CollectionSkeleton.swift similarity index 93% rename from SkeletonViewCore/Sources/Collections/TableViews/UITableView+CollectionSkeleton.swift rename to SkeletonViewCore/Sources/Internal/UIKitExtensions/UITableView+CollectionSkeleton.swift index ea280db0..132041ed 100644 --- a/SkeletonViewCore/Sources/Collections/TableViews/UITableView+CollectionSkeleton.swift +++ b/SkeletonViewCore/Sources/Internal/UIKitExtensions/UITableView+CollectionSkeleton.swift @@ -8,10 +8,7 @@ import UIKit -public typealias ReusableHeaderFooterIdentifier = String - extension UITableView: CollectionSkeleton { - public static let automaticNumberOfSkeletonRows = -1 var estimatedNumberOfRows: Int { return Int(ceil(frame.height / rowHeight)) @@ -74,14 +71,19 @@ extension UITableView: CollectionSkeleton { if reloadAfter { self.reloadData() } } + +} - private func restoreRowHeight() { +private extension UITableView { + + func restoreRowHeight() { guard let dataSource = self.dataSource as? SkeletonCollectionDataSource else { return } rowHeight = dataSource.originalRowHeight } - private func calculateRowHeight() -> CGFloat { + func calculateRowHeight() -> CGFloat { guard rowHeight == UITableView.automaticDimension else { return rowHeight } return estimatedRowHeight } + } diff --git a/SkeletonViewCore/Sources/Collections/UIView+CollectionSkeleton.swift b/SkeletonViewCore/Sources/Internal/UIKitExtensions/UIView+CollectionSkeleton.swift similarity index 99% rename from SkeletonViewCore/Sources/Collections/UIView+CollectionSkeleton.swift rename to SkeletonViewCore/Sources/Internal/UIKitExtensions/UIView+CollectionSkeleton.swift index c2efe903..112da1c1 100644 --- a/SkeletonViewCore/Sources/Collections/UIView+CollectionSkeleton.swift +++ b/SkeletonViewCore/Sources/Internal/UIKitExtensions/UIView+CollectionSkeleton.swift @@ -9,6 +9,7 @@ import UIKit extension UIView { + func addDummyDataSourceIfNeeded() { guard let collection = self as? CollectionSkeleton, !ProcessInfo.isRunningXCTest else { return } @@ -30,4 +31,5 @@ extension UIView { collection.removeDummyDataSource(reloadAfter: reload) collection.enableUserInteraction() } + }