swift-cross-ui icon indicating copy to clipboard operation
swift-cross-ui copied to clipboard

Propagate preference values up the view hierarchy when they change

Open stackotter opened this issue 1 month ago • 0 comments

I don't really know how SwiftUI detects when preference values have changed, given that they aren't required to be equatable. Things are declarative so we can't just listen for a didSet or something similar. All we get is the bundle of preferences produced by a view, with no way to detect identity when preferences (such as onOpenURL) aren't equatable.

I think SwiftUI must instead just track exactly which views depend on a given preference, and then propagate non-equatable preferences every single time? (but surgically using its dependency data to avoid unnecessary updates). Still not exactly sure how that would work without impacting performance too much, but I guess we'll have to experiment and find out.

A good way to test whether a change addresses this issue is to add a way for users to configure presentation preferences within one of the sheets in WindowingExample. At the moment, changing presentation preferences after a sheet has been presented doesn't have any effect (if the state changes that cause the presentation preferences to change occur at a scope within the sheet presentation rather than outside the presentation).

stackotter avatar Nov 27 '25 01:11 stackotter