Add initState for Expandable

This commit is contained in:
Ivan Zinovyev 2018-12-12 19:06:50 +03:00
parent e22ec03990
commit 6ef5ad504e
1 changed files with 18 additions and 2 deletions

View File

@ -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),