Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't recreate pill buttons when the pill button bar's bounds change #2108

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading