Skip to content

Instantly share code, notes, and snippets.

@gwennguihal
Last active February 27, 2019 08:13
Show Gist options
  • Save gwennguihal/65a21f14a381b285cda1d231e7041bfe to your computer and use it in GitHub Desktop.
Save gwennguihal/65a21f14a381b285cda1d231e7041bfe to your computer and use it in GitHub Desktop.
override open func prepare() {
super.prepare()
//...
let decorationBlocks = collectionViewData.sections
.compactMap { $0 as? SectionDescriptor }
.flatMap { $0.decorationBlocks }
// ...
// after computing vertical spaces
decorationBlocks.forEach { decorationBlock in
guard let firstIndexPath = decorationBlock.firstIndexPath,
let endIndexPath = decorationBlock.endIndexPath else {
return
}
guard let firstCellAttributes = layoutAttributesForItem(at: firstIndexPath),
let endCellAttributes = layoutAttributesForItem(at: endIndexPath) else {
return
}
switch decorationBlock.type {
case .whiteBordered:
addWhiteBorderedDecoration(decorationBlock: decorationBlock,
firstIndexPath: firstIndexPath,
endIndexPath: endIndexPath,
firstCellAttributes: firstCellAttributes,
endCellAttributes: endCellAttributes,
in: collectionView)
}
}
}
private func addWhiteBorderedDecoration(decorationBlock: DecorationBlock,
firstIndexPath: IndexPath,
endIndexPath: IndexPath,
firstCellAttributes: UICollectionViewLayoutAttributes,
endCellAttributes: UICollectionViewLayoutAttributes,
in collectionView: UICollectionView) {
let decorationAttributes = UICollectionViewLayoutAttributes(forDecorationViewOfKind: Kind.whiteBordered.rawValue,
with: firstIndexPath)
let offsetX: CGFloat = 10
let origin = CGPoint(x: offsetX,
y: firstCellAttributes.frame.origin.y)
let width = collectionView.frame.width - 2 * offsetX
let height = endCellAttributes.frame.maxY - origin.y
decorationAttributes.zIndex = -1
decorationAttributes.frame = CGRect(x: origin.x,
y: origin.y,
width: width,
height: height)
// using DecorationViewsHandler from Collor
decorationViewHandler.add(attributes: decorationAttributes)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment