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

kick off updateScrollViewHeight after layout pass completes #183

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion Sources/SnapshotPreviewsCore/ExpandingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public final class ExpandingViewController: UIHostingController<EmergeModifierVi

public override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't viewDidLayoutSubviews only called after the layout pass has completed? viewWillLayoutSubviews is called before it's completed, but we aren't using that here

Copy link
Collaborator Author

@NicoHinderling NicoHinderling Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I find it confusing too... I guess there's an additional layout pass that happens after the one that completed that kicked off the viewDidLayoutSubviews call... but it's pretty conclusive whether it works or not based on this from testing.

Either way, the cause of the issue is some sort of race condition and I think the layoutIfNeeded approach might be more straightforward (and achieve the same thing)

self.updateScrollViewHeight()
updateScrollViewHeight()
}

public func updateScrollViewHeight() {
Expand All @@ -87,6 +87,11 @@ public final class ExpandingViewController: UIHostingController<EmergeModifierVi
return
}

// Verify scrollview has no pending layout updates
if let firstScrollView = firstScrollView as? UIScrollView {
firstScrollView.layoutIfNeeded()
}

updateHeight {
runCallback()
}
Expand Down
Loading