Skip to content

Commit

Permalink
Added a flag that determines which version of the inset updating code…
Browse files Browse the repository at this point in the history
… is run.
  • Loading branch information
willspurgeon-wayfair committed Oct 5, 2017
1 parent c995810 commit e6d3c6d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Source/Cells/BrickCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,23 @@ open class BrickCell: BaseBrickCell {
return UIEdgeInsetsMake(defaultTopConstraintConstant, defaultLeftConstraintConstant, defaultBottomConstraintConstant, defaultRightConstraintConstant)
}

open var needsLegacyEdgeInsetFunctionality = false
private var didUpdateEdgeInsets: Bool = false
@objc open dynamic var edgeInsets: UIEdgeInsets = UIEdgeInsets.zero {
didSet {

if edgeInsets == oldValue && needsLegacyEdgeInsetFunctionality {
return
}

self.topSpaceConstraint?.constant = edgeInsets.top
self.bottomSpaceConstraint?.constant = edgeInsets.bottom
self.leftSpaceConstraint?.constant = edgeInsets.left
self.rightSpaceConstraint?.constant = edgeInsets.right

if needsLegacyEdgeInsetFunctionality {
didUpdateEdgeInsets = true
}
}
}

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

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

let preferred = layoutAttributes

Expand Down

0 comments on commit e6d3c6d

Please sign in to comment.