Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ExpandableCell.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
19EF95001F37580B00085BCA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 19EF94FE1F37580B00085BCA /* Main.storyboard */; };
19EF95021F37580B00085BCA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 19EF95011F37580B00085BCA /* Assets.xcassets */; };
19EF950B1F3758C300085BCA /* ExpandableTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19EF950A1F3758C300085BCA /* ExpandableTableView.swift */; };
AB3919EF22E89D080041AD58 /* ExpandableCellDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB3919EE22E89D080041AD58 /* ExpandableCellDelegate.swift */; };
BF790BC021A3E5DF00BF5B66 /* InitiallyExpandedExpandableCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = BF790BBE21A3E5DF00BF5B66 /* InitiallyExpandedExpandableCell.xib */; };
BF9048D521776DE100BE514F /* ExpandableCell.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 19EF94E91F3757AC00085BCA /* ExpandableCell.framework */; };
BF9048DF21776E1400BE514F /* MemoryLeakTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF9048DE21776E1400BE514F /* MemoryLeakTest.swift */; };
Expand Down Expand Up @@ -90,6 +91,7 @@
19EF95011F37580B00085BCA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
19EF95061F37580B00085BCA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
19EF950A1F3758C300085BCA /* ExpandableTableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExpandableTableView.swift; sourceTree = "<group>"; };
AB3919EE22E89D080041AD58 /* ExpandableCellDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExpandableCellDelegate.swift; sourceTree = "<group>"; };
BF790BBE21A3E5DF00BF5B66 /* InitiallyExpandedExpandableCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = InitiallyExpandedExpandableCell.xib; sourceTree = "<group>"; };
BF9048D021776DE100BE514F /* ExpandableCellTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ExpandableCellTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
BF9048D421776DE100BE514F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -169,6 +171,7 @@
19E5B2661F39DD9400E7D311 /* ExpandableProcessor.swift */,
19EF94EC1F3757AC00085BCA /* ExpandableCell.h */,
19EF94ED1F3757AC00085BCA /* Info.plist */,
AB3919EE22E89D080041AD58 /* ExpandableCellDelegate.swift */,
);
path = ExpandableCell;
sourceTree = "<group>";
Expand Down Expand Up @@ -355,6 +358,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
AB3919EF22E89D080041AD58 /* ExpandableCellDelegate.swift in Sources */,
19E5B2671F39DD9400E7D311 /* ExpandableProcessor.swift in Sources */,
1921BF6E1F37FF2700BFD528 /* ExpandableDelegate.swift in Sources */,
196801921F3EB97B002DFC73 /* ExpandableStyle.swift in Sources */,
Expand Down
6 changes: 5 additions & 1 deletion ExpandableCell/ExpandableCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ open class ExpandableCell: UITableViewCell {
open var highlightAnimation = HighlightAnimation.animated
private var isOpen = false
private var initialExpansionAllowed = true


public var expandableDelegate: ExpandableCellDelegate?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may cause a potential leak, i think it would be better to make this one weak


public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)

Expand Down Expand Up @@ -49,6 +51,7 @@ open class ExpandableCell: UITableViewCell {
func open() {
self.isOpen = true
self.initialExpansionAllowed = false
self.expandableDelegate?.expandableCell(expandedCell: self)
if highlightAnimation == .animated {
UIView.animate(withDuration: 0.3) {[weak self] in
self?.arrowImageView.layer.transform = CATransform3DMakeRotation(CGFloat(Double.pi), 1.0, 0.0, 0.0)
Expand All @@ -58,6 +61,7 @@ open class ExpandableCell: UITableViewCell {

func close() {
self.isOpen = false
self.expandableDelegate?.expandableCell(collapsedCell: self)
if highlightAnimation == .animated {
UIView.animate(withDuration: 0.3) {[weak self] in
self?.arrowImageView.layer.transform = CATransform3DMakeRotation(CGFloat(Double.pi), 0.0, 0.0, 0.0)
Expand Down
18 changes: 18 additions & 0 deletions ExpandableCell/ExpandableCellDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// ExpandableCellDelegate.swift
// ExpandableCell
//
// Created by Jonathan Gomes on 24/07/19.
// Copyright © 2019 SeungyounYi. All rights reserved.
//

import Foundation

import UIKit

public protocol ExpandableCellDelegate {

func expandableCell(expandedCell expandableCell: ExpandableCell)
func expandableCell(collapsedCell expandableCell: ExpandableCell)

}
16 changes: 16 additions & 0 deletions ExpandableCellDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ extension ViewController: ExpandableDelegate {

func expandableTableView(_ expandableTableView: ExpandableTableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = expandableTableView.dequeueReusableCell(withIdentifier: parentCells[indexPath.section][indexPath.row]) else { return UITableViewCell() }
if let cellExp = cell as? ExpandableCell {
cellExp.expandableDelegate = self
return cellExp
}
return cell
}

Expand Down Expand Up @@ -261,3 +265,15 @@ extension ViewController: ExpandableDelegate {
// return 33
// }
}
extension ViewController: ExpandableCellDelegate {
func expandableCell(expandedCell expandableCell: ExpandableCell) {
print("expandedCell")
}

func expandableCell(collapsedCell expandableCell: ExpandableCell) {
print("collapsedCell")
}


}