Skip to content

Commit

Permalink
Calculate Bottom Commanding header height instead of using constant (#…
Browse files Browse the repository at this point in the history
…2041)

* calculate header height instead of using constant

* remove headerHeight var

* update comment
  • Loading branch information
joannaquu authored Jun 7, 2024
1 parent 32d5cf1 commit d298dac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class BottomCommandingDemoController: DemoController {

private lazy var heroItems: [CommandingItem] = {
return Array(1...25).map {
let item = CommandingItem(title: "Item " + String($0), image: homeImage, action: commandAction)
let title = ($0 == 4) ? "Two line item" : "Item"
let item = CommandingItem(title: title + String($0), image: homeImage, action: commandAction)
item.selectedImage = homeSelectedImage
item.isOn = ($0 % 3 == 1)
item.isEnabled = ($0 % 2 == 1)
Expand Down
15 changes: 9 additions & 6 deletions ios/FluentUI/Bottom Commanding/BottomCommandingController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ open class BottomCommandingController: UIViewController, TokenizedControlInterna
headerView.addSubview(heroCommandStack)

let sheetController = BottomSheetController(headerContentView: headerView, expandedContentView: makeSheetExpandedContent(with: tableView))
sheetController.headerContentHeight = Constants.BottomSheet.headerHeight
sheetController.hostedScrollView = tableView
sheetController.isHidden = isHidden
sheetController.shouldAlwaysFillWidth = sheetShouldAlwaysFillWidth
Expand Down Expand Up @@ -534,6 +533,7 @@ open class BottomCommandingController: UIViewController, TokenizedControlInterna
} else {
tableView.tableHeaderView = nil
}
calculateHeaderHeight()
}

private func reloadHeroCommandOverflowStack() {
Expand Down Expand Up @@ -563,6 +563,13 @@ open class BottomCommandingController: UIViewController, TokenizedControlInterna
}
}

@discardableResult
private func calculateHeaderHeight() -> CGFloat {
let headerHeight = heroCommandStack.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height + BottomSheetController.resizingHandleHeight
bottomSheetController?.headerContentHeight = headerHeight
return headerHeight
}

private func updateAppearance() {
guard isViewLoaded else {
return
Expand Down Expand Up @@ -923,7 +930,7 @@ open class BottomCommandingController: UIViewController, TokenizedControlInterna
let headerHeightWithoutBottomWhitespace = BottomCommandingTokenSet.handleHeaderHeight + maxHeroItemHeight

// How much more whitespace is required at the bottom of the sheet header
let requiredBottomWhitespace = max(0, Constants.BottomSheet.headerHeight - headerHeightWithoutBottomWhitespace)
let requiredBottomWhitespace = max(0, calculateHeaderHeight() - headerHeightWithoutBottomWhitespace)

// The safe area inset can fulfill some or all of our bottom whitespace requirement.
// This is how much more we need, taking the inset into account.
Expand Down Expand Up @@ -1118,10 +1125,6 @@ open class BottomCommandingController: UIViewController, TokenizedControlInterna
static let moreButtonIcon: UIImage? = UIImage.staticImageNamed("more-24x24")
static let moreButtonTitle: String = "CommandingBottomBar.More".localized
}

struct BottomSheet {
static let headerHeight: CGFloat = 66
}
}
}

Expand Down

0 comments on commit d298dac

Please sign in to comment.