From 6ef5ad504eb3305db32ba98377bd896474914943 Mon Sep 17 00:00:00 2001 From: Ivan Zinovyev Date: Wed, 12 Dec 2018 19:06:50 +0300 Subject: [PATCH] Add initState for Expandable --- Sources/Expandable.swift | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Sources/Expandable.swift b/Sources/Expandable.swift index a2ca692..847965f 100644 --- a/Sources/Expandable.swift +++ b/Sources/Expandable.swift @@ -12,6 +12,23 @@ public protocol Expandable { extension Expandable where Self: UITableViewCell & ConfigurableCell { + public func initState() { + guard let viewModel = viewModel else { + return + } + + changeState(isCollapsed: viewModel.isCollapsed) + } + + private func changeState(isCollapsed: Bool) { + // layout to get right frames, frame of bottom subview can be used to get expanded height + layoutIfNeeded() + + // apply changes + configureAppearance(isCollapsed: isCollapsed) + layoutIfNeeded() + } + public func toggleState(animated: Bool = true, animationDuration: TimeInterval = 0.3) { @@ -41,8 +58,7 @@ extension Expandable where Self: UITableViewCell & ConfigurableCell { } private func applyChanges(isCollapsed: Bool) { - configureAppearance(isCollapsed: isCollapsed) - layoutIfNeeded() + changeState(isCollapsed: isCollapsed) if let indexPath = indexPath, let tableDirector = (tableView?.delegate as? TableDirector),