From bb26d0038c7511ab0787d18b82aa29324b030b7f Mon Sep 17 00:00:00 2001 From: VishalPethani Date: Fri, 21 Aug 2020 23:52:20 +0530 Subject: [PATCH] Ondex TableView Changes - Give support Placeholder Data to custom XIB - if the tableview is empty hide automatically to loading data placeholder --- .../HGPlaceholders.xcodeproj/project.pbxproj | 3 +- .../HGPlaceholders/PlaceholdersProvider.swift | 9 ++- .../AppIcon.appiconset/Contents.json | 43 +++++++------- .../TableViewExample/ExampleTableViewCell.xib | 56 +++++++++++++++---- .../Classes/Placeholder/Placeholder.swift | 3 +- .../Classes/Placeholder/PlaceholderData.swift | 2 +- .../PlaceholderDataSourceDelegate.swift | 2 +- HGPlaceholders/Classes/Views/TableView.swift | 5 -- README.md | 7 ++- 9 files changed, 87 insertions(+), 43 deletions(-) diff --git a/Example/HGPlaceholders.xcodeproj/project.pbxproj b/Example/HGPlaceholders.xcodeproj/project.pbxproj index ab00de9..416ebcc 100644 --- a/Example/HGPlaceholders.xcodeproj/project.pbxproj +++ b/Example/HGPlaceholders.xcodeproj/project.pbxproj @@ -35,7 +35,7 @@ /* Begin PBXFileReference section */ 078B3A00236AA8566A1BDE71 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; 089FFFAA5455B1FAC176F3A6 /* Pods-HGPlaceholders_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HGPlaceholders_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-HGPlaceholders_Tests/Pods-HGPlaceholders_Tests.release.xcconfig"; sourceTree = ""; }; - 0913B562CE0DD4319C2FEC31 /* HGPlaceholders.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = HGPlaceholders.podspec; path = ../HGPlaceholders.podspec; sourceTree = ""; }; + 0913B562CE0DD4319C2FEC31 /* HGPlaceholders.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = HGPlaceholders.podspec; path = ../HGPlaceholders.podspec; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; 576F9853BBED6C018D85C27A /* Pods-HGPlaceholders_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HGPlaceholders_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-HGPlaceholders_Example/Pods-HGPlaceholders_Example.debug.xcconfig"; sourceTree = ""; }; 607FACD01AFB9204008FA782 /* HGPlaceholders_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HGPlaceholders_Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 607FACE51AFB9204008FA782 /* HGPlaceholders_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = HGPlaceholders_Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -280,6 +280,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); diff --git a/Example/HGPlaceholders/PlaceholdersProvider.swift b/Example/HGPlaceholders/PlaceholdersProvider.swift index 168d5cd..0b3fd9d 100644 --- a/Example/HGPlaceholders/PlaceholdersProvider.swift +++ b/Example/HGPlaceholders/PlaceholdersProvider.swift @@ -15,7 +15,7 @@ extension PlaceholdersProvider { commonStyle.actionBackgroundColor = .black commonStyle.actionTitleColor = .white commonStyle.titleColor = .black - commonStyle.isAnimated = false + commonStyle.isAnimated = true commonStyle.titleFont = UIFont(name: "AvenirNextCondensed-HeavyItalic", size: 19)! commonStyle.subtitleFont = UIFont(name: "AvenirNextCondensed-Italic", size: 19)! @@ -43,7 +43,12 @@ extension PlaceholdersProvider { let placeholdersProvider = PlaceholdersProvider(loading: loading, error: error, noResults: noResults, noConnection: noConnection) - let xibPlaceholder = Placeholder(cellIdentifier: "CustomPlaceholderCell", key: PlaceholderKey.custom(key: "XIB")) + var xibData = PlaceholderData() + xibData.title = "This is a xib title, \n It is awsome\"" + xibData.subtitle = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." + xibData.image = #imageLiteral(resourceName: "list") + xibData.action = "Ok" + let xibPlaceholder = Placeholder(cellIdentifier: "CustomPlaceholderCell", key: PlaceholderKey.custom(key: "XIB"), data: xibData) placeholdersProvider.add(placeholders: PlaceholdersProvider.starWarsPlaceholder, xibPlaceholder) diff --git a/Example/HGPlaceholders/Resources/Images.xcassets/AppIcon.appiconset/Contents.json b/Example/HGPlaceholders/Resources/Images.xcassets/AppIcon.appiconset/Contents.json index b8236c6..8121323 100644 --- a/Example/HGPlaceholders/Resources/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/Example/HGPlaceholders/Resources/Images.xcassets/AppIcon.appiconset/Contents.json @@ -2,47 +2,52 @@ "images" : [ { "idiom" : "iphone", - "size" : "20x20", - "scale" : "2x" + "scale" : "2x", + "size" : "20x20" }, { "idiom" : "iphone", - "size" : "20x20", - "scale" : "3x" + "scale" : "3x", + "size" : "20x20" }, { "idiom" : "iphone", - "size" : "29x29", - "scale" : "2x" + "scale" : "2x", + "size" : "29x29" }, { "idiom" : "iphone", - "size" : "29x29", - "scale" : "3x" + "scale" : "3x", + "size" : "29x29" }, { "idiom" : "iphone", - "size" : "40x40", - "scale" : "2x" + "scale" : "2x", + "size" : "40x40" }, { "idiom" : "iphone", - "size" : "40x40", - "scale" : "3x" + "scale" : "3x", + "size" : "40x40" }, { "idiom" : "iphone", - "size" : "60x60", - "scale" : "2x" + "scale" : "2x", + "size" : "60x60" }, { "idiom" : "iphone", - "size" : "60x60", - "scale" : "3x" + "scale" : "3x", + "size" : "60x60" + }, + { + "idiom" : "ios-marketing", + "scale" : "1x", + "size" : "1024x1024" } ], "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 } -} \ No newline at end of file +} diff --git a/Example/HGPlaceholders/TableViewExample/ExampleTableViewCell.xib b/Example/HGPlaceholders/TableViewExample/ExampleTableViewCell.xib index a25edd1..7dda318 100644 --- a/Example/HGPlaceholders/TableViewExample/ExampleTableViewCell.xib +++ b/Example/HGPlaceholders/TableViewExample/ExampleTableViewCell.xib @@ -1,24 +1,23 @@ - - - - + + - + + - - + + - + + + + + + + + + + - - + + + + + + + + + + - + + + + + + + diff --git a/HGPlaceholders/Classes/Placeholder/Placeholder.swift b/HGPlaceholders/Classes/Placeholder/Placeholder.swift index d83ef00..df808b8 100644 --- a/HGPlaceholders/Classes/Placeholder/Placeholder.swift +++ b/HGPlaceholders/Classes/Placeholder/Placeholder.swift @@ -44,7 +44,8 @@ public struct Placeholder { /// - Parameters: /// - cellIdentifier: The identifier of the cell to use as a placeholder /// - key: the unique key of the placeholder - public init(cellIdentifier: String, key: PlaceholderKey) { + public init(cellIdentifier: String, key: PlaceholderKey, data: PlaceholderData) { + self.data = data self.key = key self.cellIdentifier = cellIdentifier } diff --git a/HGPlaceholders/Classes/Placeholder/PlaceholderData.swift b/HGPlaceholders/Classes/Placeholder/PlaceholderData.swift index 98f0544..d9f233e 100644 --- a/HGPlaceholders/Classes/Placeholder/PlaceholderData.swift +++ b/HGPlaceholders/Classes/Placeholder/PlaceholderData.swift @@ -64,7 +64,7 @@ public struct PlaceholderData { var errorStyle = PlaceholderData() errorStyle.image = PlaceholdersProvider.image(named: "hg_default-error") errorStyle.title = NSLocalizedString("Whoops!", comment: "") - errorStyle.subtitle = NSLocalizedString("We tried, but something went\nteriblly wrong", comment: "") + errorStyle.subtitle = NSLocalizedString("We tried, but something went\nterrible wrong", comment: "") errorStyle.action = NSLocalizedString("Try Again!", comment: "") return errorStyle diff --git a/HGPlaceholders/Classes/PlaceholdersProvider/PlaceholderDataSourceDelegate.swift b/HGPlaceholders/Classes/PlaceholdersProvider/PlaceholderDataSourceDelegate.swift index 9e278c6..14c173c 100644 --- a/HGPlaceholders/Classes/PlaceholdersProvider/PlaceholderDataSourceDelegate.swift +++ b/HGPlaceholders/Classes/PlaceholdersProvider/PlaceholderDataSourceDelegate.swift @@ -161,7 +161,7 @@ extension PlaceholderDataSourceDelegate: UITableViewDelegate { // animate the cell func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { - if placeholder.style?.isAnimated == false { + if placeholder.style == nil || placeholder.style?.isAnimated == false { return } diff --git a/HGPlaceholders/Classes/Views/TableView.swift b/HGPlaceholders/Classes/Views/TableView.swift index 553cced..82b60c1 100644 --- a/HGPlaceholders/Classes/Views/TableView.swift +++ b/HGPlaceholders/Classes/Views/TableView.swift @@ -232,11 +232,6 @@ open class TableView: UITableView { If the number of rows == 0 it shows no results placeholder */ open override func reloadData() { - // if the tableview is empty we switch automatically to no data placeholder - if numberOfRowsInAllSections() == 0 { - showLoadingPlaceholder() - return - } // if the data source is in no data placeholder, and the user tries to reload data, we will switch automatically to default if dataSource is PlaceholderDataSourceDelegate { showDefault() diff --git a/README.md b/README.md index b5579b3..de17379 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,12 @@ static var summer: PlaceholdersProvider { let placeholdersProvider = PlaceholdersProvider(loading: loading, error: error, noResults: noResults, noConnection: noConnection) - let xibPlaceholder = Placeholder(cellIdentifier: "CustomPlaceholderCell", key: PlaceholderKey.custom(key: "XIB")) + var xibData = PlaceholderData() + xibData.title = "This is a xib title, \n It is awsome\"" + xibData.subtitle = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." + xibData.image = #imageLiteral(resourceName: "list") + xibData.action = "Ok" + let xibPlaceholder = Placeholder(cellIdentifier: "CustomPlaceholderCell", key: PlaceholderKey.custom(key: "XIB"), data: xibData) placeholdersProvider.add(placeholders: xibPlaceholder)