-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
How to fit ScrollView to content in SwiftUI #769
Comments
Thnaks alot |
Thanks a lot for this solution. Just one question: Why is it necessary to use DispatchQueue.main.async to set the scrollViewContentSize value? Is this assingment done in background? I do not understand the need of that dispatch |
Leaving it out causes runtime warning: "Modifying state during view update, this will cause undefined behavior." I am not exactly sure why because I agreed with you until trying this, will figure this out if I got some spare time on my hands... |
something like this is a bit cleaner |
.background(
GeometryReader { geo in
Color.clear.task { scrollViewContentSize = geo.size }
}
) Maybe maybe maybe... |
If we place
ScrollView
inside HStack or VStack, it takes all remaining space. To fit ScrollView to its content, we need to get its content size and constrain ScrollView size.Use a
GeometryReader
as Scrollview content background, and get the local frameThe text was updated successfully, but these errors were encountered: