From c05f35de03fac1d66ec6a72ec672112a1cbfeccd Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 31 Aug 2022 16:12:19 -0500 Subject: [PATCH] updated width/height for collectionview Signed-off-by: Matt Bruce --- .../RadioSwatch/RadioSwatchGroup.swift | 41 +++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift index 6340d613..59bcbbd4 100644 --- a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift +++ b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift @@ -62,8 +62,12 @@ public class RadioSwatchGroupBase.self, forCellWithReuseIdentifier: "collectionViewCell") } @@ -105,15 +110,45 @@ public class RadioSwatchGroupBase 0 else { + collectionViewHeight?.constant = 0 + return + } + + // Calculate the height + let swatchesInRow = floor(CGFloat(collectionView.bounds.width/(cellSize + itemSpacing))) + let numberOfRows = ceil(CGFloat(swatches.count)/swatchesInRow) + let height = (numberOfRows * cellSize) + (itemSpacing * (numberOfRows-1)) + + collectionViewHeight?.constant = CGFloat(height) + } + open override func shouldUpdateView(viewModel: ModelType) -> Bool { return viewModel != model }