@@ -146,7 +146,7 @@ public class CommandBar: UIView, Shadowable, TokenizedControl {
146146 // MARK: Overrides
147147
148148 public override var intrinsicContentSize : CGSize {
149- . zero
149+ shouldCalculateIntrinsicHeight ? CGSize ( width : UIView . noIntrinsicMetric , height : intrinsicHeight ) : . zero
150150 }
151151
152152 public override func layoutSubviews( ) {
@@ -197,6 +197,7 @@ public class CommandBar: UIView, Shadowable, TokenizedControl {
197197 }
198198 set {
199199 mainCommandGroupsView. itemGroups = newValue
200+ invalidateIntrinsicContentSize ( )
200201 }
201202 }
202203
@@ -207,6 +208,7 @@ public class CommandBar: UIView, Shadowable, TokenizedControl {
207208 }
208209 set {
209210 setupGroupsView ( leadingCommandGroupsView, with: newValue)
211+ invalidateIntrinsicContentSize ( )
210212 }
211213 }
212214
@@ -217,6 +219,7 @@ public class CommandBar: UIView, Shadowable, TokenizedControl {
217219 }
218220 set {
219221 setupGroupsView ( trailingCommandGroupsView, with: newValue)
222+ invalidateIntrinsicContentSize ( )
220223 }
221224 }
222225
@@ -240,6 +243,15 @@ public class CommandBar: UIView, Shadowable, TokenizedControl {
240243 }
241244 }
242245
246+ /// Controls whether intrinsic height should be calculated. When false, intrinsicContentSize.height returns 0.
247+ @objc public var shouldCalculateIntrinsicHeight : Bool = true {
248+ didSet {
249+ if shouldCalculateIntrinsicHeight != oldValue {
250+ invalidateIntrinsicContentSize ( )
251+ }
252+ }
253+ }
254+
243255 /// Delegate object that notifies consumers of events occuring inside the `CommandBar`
244256 public weak var delegate : CommandBarDelegate ?
245257
@@ -259,6 +271,24 @@ public class CommandBar: UIView, Shadowable, TokenizedControl {
259271
260272 private var mainCommandGroupsViewConstraints : [ NSLayoutConstraint ] = [ ]
261273
274+ private var intrinsicHeight : CGFloat {
275+ var maxButtonHeight : CGFloat = 0
276+
277+ let allGroups = ( leadingItemGroups ?? [ ] ) + itemGroups + ( trailingItemGroups ?? [ ] )
278+ for group in allGroups {
279+ for item in group where !item. isHidden {
280+ if let button = leadingCommandGroupsView. button ( for: item) ??
281+ mainCommandGroupsView. button ( for: item) ??
282+ trailingCommandGroupsView. button ( for: item) {
283+ let buttonHeight = button. intrinsicContentSize. height
284+ maxButtonHeight = max ( maxButtonHeight, buttonHeight)
285+ }
286+ }
287+ }
288+
289+ return maxButtonHeight + CommandBarTokenSet. barInsets * 2
290+ }
291+
262292 // MARK: Views and Layers
263293
264294 private lazy var containerView : CommandBarContainerView = {
0 commit comments