Skip to content

Commit

Permalink
Fix infinite loop with contentSize changes
Browse files Browse the repository at this point in the history
  • Loading branch information
PimCoumans committed Feb 19, 2024
1 parent ff2d519 commit 23165b5
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,13 @@ extension PanelPresentationController {
}
scrollView.contentInsetAdjustmentBehavior = .always
contentScrollViewObserver.scrollView = scrollView
contentHeightConstraint = presentedViewController.view.heightAnchor
contentHeightConstraint = contentView.heightAnchor
.constraint(lessThanOrEqualTo: containerScrollView.heightAnchor)

// Create constraint that can be updated with the contentScrollView’s content height
contentScrollViewHeightConstraint = scrollView.safeAreaLayoutGuide.heightAnchor
.constraint(equalToConstant: 10)
.constraint(equalToConstant: scrollView.contentSize.height)
.withPriority(.defaultHigh)
NSLayoutConstraint.build {
contentHeightConstraint!
contentScrollViewHeightConstraint!
}
}

private func updateKeyboardBottomInsetIfNeeded() {
Expand Down Expand Up @@ -478,10 +476,12 @@ extension PanelPresentationController {

private func contentScrollViewDidUpdate(_ scrollView: UIScrollView) {
if scrollView.contentExceedsBounds {
scrollView.isScrollEnabled = true
// Setting `isScrollEnabled` directly changes the contentSize
// Potentially leading to an infinite back and forth here
scrollView.panGestureRecognizer.isEnabled = true
containerScrollView.alwaysBounceVertical = false
} else {
scrollView.isScrollEnabled = false
scrollView.panGestureRecognizer.isEnabled = false
containerScrollView.alwaysBounceVertical = true
}
contentScrollViewHeightConstraint?.constant = scrollView.contentSize.height
Expand Down

0 comments on commit 23165b5

Please sign in to comment.