From 78a63cdc3ecb8e9a1cd2623a09399d93f3c724fd Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Tue, 13 Feb 2024 23:18:40 +0530 Subject: [PATCH] Added Publisher for layoutHeight to update collectionViewHeight dynamically --- VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift | 6 ++++++ .../Buttons/ButtonGroup/ButtonGroupPositionLayout.swift | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift index 1fdbc56d..296a5224 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift @@ -64,6 +64,8 @@ open class ButtonGroup: View { private var _childWidth: ChildWidth? + private var anyCancellable: AnyCancellable? + /// If provided, width of Button components will be rendered based on this value. If omitted, default button widths are rendered. open var childWidth: ChildWidth? { get { _childWidth } @@ -134,6 +136,10 @@ open class ButtonGroup: View { collectionView.pinToSuperView() collectionViewHeight = heightAnchor.constraint(equalToConstant: VDS.Button.Size.large.height) collectionViewHeight?.activate() + anyCancellable = positionLayout.$layoutHeight.receive(on: RunLoop.main).sink { [weak self] _ in + guard let self else { return } + self.collectionViewHeight?.constant = self.collectionView.intrinsicContentSize.height + } } //-------------------------------------------------- diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift index c1a315eb..7c099a7c 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift @@ -149,7 +149,7 @@ class ButtonGroupPositionLayout: UICollectionViewLayout { weak var delegate: ButtongGroupPositionLayoutDelegate? // Total height of the content. Will be used to configure the scrollview content - var layoutHeight: CGFloat = 0.0 + @Published var layoutHeight: CGFloat = 0.0 var position: ButtonGroup.Alignment = .left var rowQuantity: Int = 0 var buttonPercentage: CGFloat?