Added Publisher for layoutHeight to update collectionViewHeight dynamically

This commit is contained in:
Krishna Kishore Bandaru 2024-02-13 23:18:40 +05:30
parent e8a03cbea2
commit 78a63cdc3e
2 changed files with 7 additions and 1 deletions

View File

@ -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
}
}
//--------------------------------------------------

View File

@ -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?