Skip to content

Commit

Permalink
Ondex TableView Changes
Browse files Browse the repository at this point in the history
   - Give support  Placeholder Data to custom XIB
   - if the tableview is empty hide automatically to loading data placeholder
  • Loading branch information
VishalPethani99 committed Sep 14, 2020
1 parent 18ccd88 commit bb26d00
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 43 deletions.
3 changes: 2 additions & 1 deletion Example/HGPlaceholders.xcodeproj/project.pbxproj
Expand Up @@ -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 = "<group>"; };
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 = "<group>"; };
0913B562CE0DD4319C2FEC31 /* HGPlaceholders.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = HGPlaceholders.podspec; path = ../HGPlaceholders.podspec; sourceTree = "<group>"; };
0913B562CE0DD4319C2FEC31 /* HGPlaceholders.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = HGPlaceholders.podspec; path = ../HGPlaceholders.podspec; sourceTree = "<group>"; 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 = "<group>"; };
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; };
Expand Down Expand Up @@ -280,6 +280,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down
9 changes: 7 additions & 2 deletions Example/HGPlaceholders/PlaceholdersProvider.swift
Expand Up @@ -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)!
Expand Down Expand Up @@ -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)

Expand Down
Expand Up @@ -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
}
}
}
56 changes: 44 additions & 12 deletions Example/HGPlaceholders/TableViewExample/ExampleTableViewCell.xib
@@ -1,39 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12121" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="CustomPlaceholderCell" id="KGk-i7-Jjw" customClass="ExampleTableViewCell" customModule="HGPlaceholders_Example" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="CustomPlaceholderCell" rowHeight="342" id="KGk-i7-Jjw" customClass="ExampleTableViewCell" customModule="HGPlaceholders_Example" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="320" height="342"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="320" height="43.5"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="342"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Gpt-4x-Zox">
<rect key="frame" x="136" y="7" width="48" height="30"/>
<rect key="frame" x="136" y="237" width="48" height="30"/>
<state key="normal" title="Action!">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="sendPlaceholderAction:" destination="KGk-i7-Jjw" eventType="touchUpInside" id="hgQ-Ct-rjF"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="JaH-BO-vhN">
<rect key="frame" x="20" y="150" width="280" height="32.5"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="27"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="9UV-Gy-bEu">
<rect key="frame" x="110" y="20" width="100" height="100"/>
<constraints>
<constraint firstAttribute="width" secondItem="9UV-Gy-bEu" secondAttribute="height" multiplier="1:1" id="5fk-e9-vNH"/>
<constraint firstAttribute="height" constant="100" id="R1s-eg-nCc"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Xxf-xF-w4O">
<rect key="frame" x="20" y="192.5" width="280" height="14.5"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="0.1897330284" green="0.38077324629999998" blue="0.87199062110000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="Gpt-4x-Zox" firstAttribute="centerX" secondItem="H2p-sc-9uM" secondAttribute="centerX" id="Zq9-TI-yDI"/>
<constraint firstItem="Gpt-4x-Zox" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="gm8-7q-V6k"/>
<constraint firstItem="Xxf-xF-w4O" firstAttribute="leading" secondItem="JaH-BO-vhN" secondAttribute="leading" id="7Er-3x-yy5"/>
<constraint firstItem="Xxf-xF-w4O" firstAttribute="top" secondItem="JaH-BO-vhN" secondAttribute="bottom" constant="10" id="8ar-mS-oyN"/>
<constraint firstItem="9UV-Gy-bEu" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="20" id="DOj-hB-1Et"/>
<constraint firstItem="Gpt-4x-Zox" firstAttribute="top" secondItem="Xxf-xF-w4O" secondAttribute="bottom" constant="30" id="DRc-yk-xcJ"/>
<constraint firstAttribute="trailing" secondItem="JaH-BO-vhN" secondAttribute="trailing" constant="20" id="Keh-t1-bbq"/>
<constraint firstItem="JaH-BO-vhN" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="20" id="qAf-hq-58K"/>
<constraint firstItem="JaH-BO-vhN" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="150" id="rgo-IU-yGa"/>
<constraint firstItem="Gpt-4x-Zox" firstAttribute="centerX" secondItem="JaH-BO-vhN" secondAttribute="centerX" id="uK5-Ht-Idj"/>
<constraint firstItem="Xxf-xF-w4O" firstAttribute="trailing" secondItem="JaH-BO-vhN" secondAttribute="trailing" id="wtw-hK-npn"/>
<constraint firstItem="9UV-Gy-bEu" firstAttribute="centerX" secondItem="H2p-sc-9uM" secondAttribute="centerX" id="xzS-QG-ylY"/>
</constraints>
</tableViewCellContentView>
<point key="canvasLocation" x="-121" y="51"/>
<connections>
<outlet property="actionButton" destination="Gpt-4x-Zox" id="BB1-YK-pIB"/>
<outlet property="placeholderImageView" destination="9UV-Gy-bEu" id="Sc8-3n-UVj"/>
<outlet property="subtitleLabel" destination="Xxf-xF-w4O" id="aST-uq-anp"/>
<outlet property="titleLabel" destination="JaH-BO-vhN" id="rr4-7q-tvF"/>
</connections>
<point key="canvasLocation" x="-121.59999999999999" y="184.40779610194903"/>
</tableViewCell>
</objects>
</document>
3 changes: 2 additions & 1 deletion HGPlaceholders/Classes/Placeholder/Placeholder.swift
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion HGPlaceholders/Classes/Placeholder/PlaceholderData.swift
Expand Up @@ -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
Expand Down
Expand Up @@ -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
}

Expand Down
5 changes: 0 additions & 5 deletions HGPlaceholders/Classes/Views/TableView.swift
Expand Up @@ -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()
Expand Down
7 changes: 6 additions & 1 deletion README.md
Expand Up @@ -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)

Expand Down

0 comments on commit bb26d00

Please sign in to comment.