Skip to content

Commit

Permalink
Don't recreate pill buttons when the pill button bar's bounds change (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
laminesm authored Nov 20, 2024
1 parent 8b6ed6d commit 29d8c31
Showing 1 changed file with 0 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,6 @@ open class PillButtonBar: UIScrollView {
}
}

public override var bounds: CGRect {
didSet {
if bounds.width > 0, lastKnownScrollFrameWidth > 0, bounds.width != lastKnownScrollFrameWidth {
// Frame changes can happen because of rotation, split view or adding the view for the first
// time into a superview. First time layout already has buttons in default sizes, recreate
// them so that the next time we layout subviews we'll recalculate their optimal sizes.
recreateButtons()
stackView.spacing = Constants.minButtonsSpacing
}

lastKnownScrollFrameWidth = bounds.width
}
}

/// Initializes the PillButtonBar using the provided style.
///
/// - Parameters:
Expand Down Expand Up @@ -207,8 +193,6 @@ open class PillButtonBar: UIScrollView {

private var buttons = [PillButton]()

private var lastKnownScrollFrameWidth: CGFloat = 0.0

private var needsButtonSizeReconfiguration: Bool = false

private var selectedButton: PillButton? {
Expand Down Expand Up @@ -394,19 +378,6 @@ open class PillButtonBar: UIScrollView {
return nil
}

private func recreateButtons() {
let selectedItem = selectedButton?.pillBarItem
selectedButton = nil

let currentItems = items
items = nil
items = currentItems

if let selectedItem = selectedItem {
selectItem(selectedItem)
}
}

private func setupScrollView() {
if effectiveUserInterfaceLayoutDirection == .rightToLeft {
transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi))
Expand Down

0 comments on commit 29d8c31

Please sign in to comment.