Skip to content

Commit

Permalink
Added update edgeInsets logic (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcheung16 authored and jay18001 committed Sep 28, 2017
1 parent c4922c5 commit 99a323c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Source/Cells/BrickCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,17 @@ open class BrickCell: BaseBrickCell {
return UIEdgeInsetsMake(defaultTopConstraintConstant, defaultLeftConstraintConstant, defaultBottomConstraintConstant, defaultRightConstraintConstant)
}

private var didUpdateEdgeInsets: Bool = false
@objc open dynamic var edgeInsets: UIEdgeInsets = UIEdgeInsets.zero {
didSet {
if edgeInsets == oldValue {
return
}
self.topSpaceConstraint?.constant = edgeInsets.top
self.bottomSpaceConstraint?.constant = edgeInsets.bottom
self.leftSpaceConstraint?.constant = edgeInsets.left
self.rightSpaceConstraint?.constant = edgeInsets.right
didUpdateEdgeInsets = true
}
}

Expand Down Expand Up @@ -226,7 +231,14 @@ open class BrickCell: BaseBrickCell {
guard self._brick.height.isEstimate(withValue: nil) else {
return layoutAttributes
}


if !didUpdateEdgeInsets {
guard let brickAttributes = layoutAttributes as? BrickLayoutAttributes, brickAttributes.isEstimateSize else {
return layoutAttributes
}
}
didUpdateEdgeInsets = false

let preferred = layoutAttributes

// We're inverting the frame because the given frame is already transformed
Expand Down

0 comments on commit 99a323c

Please sign in to comment.