Skip to content

Instantly share code, notes, and snippets.

@Thomvis
Created February 6, 2020 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Thomvis/cf4d492ee7352d64825bc3d5767d15d2 to your computer and use it in GitHub Desktop.
Save Thomvis/cf4d492ee7352d64825bc3d5767d15d2 to your computer and use it in GitHub Desktop.
It seems that `onPreferenceChange` is not always called. I have an override using `overlayPreferenceValue` and `View.id`. I suspect the fact this view is inside a `ScrollView` matters.
content
.onPreferenceChange(SizeKey.self, perform: { sizes in
// this is not always called
})
.overlayPreferenceValue(SizeKey.self) { sizes in
EmptyView().onAppear {
// this is called more reliably
// the view's id controls for which changes this is called
}.id(sizes.map { $0.width*1000+$0.height })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment