Use PreferenceKeys to pass images up the view hieararchy.#32
Use PreferenceKeys to pass images up the view hieararchy.#32maciekish wants to merge 1 commit intoJake-Short:masterfrom
Conversation
| /// Allows this view to display images as requested by child views further down in the view hierarchy, without having to manually pass the image throught the view hierarchy. | ||
| /// | ||
| /// For example, you can attach this modifier to a `NavigationView` and use the `viewImage(image: UIImage?)`modifier on any view further down in the hierarchy. | ||
| public func imageViewier() -> some View { |
There was a problem hiding this comment.
Typo, change imageViewier to imageViewer.
|
Thanks for working on this addition, it looks great so far! One comment I left above is just a small typo ( |
Jake-Short
left a comment
There was a problem hiding this comment.
Fix typo (see comment) and change UIImage to Image
|
This is a great idea! Sometime it will open the image after scrolling ! not when I tap on the image the great think about this solution, I can get the image from cardView |
Hi,
Thanks for making this great library. I have used it a lot but always face the same issue. I have a complex view hiearachy and more often than not the image i want to display lives in code several view hiearchies away from the nearest
NavigationView. This makes it a pain to pass it upp all the way using$bindings. So i created some support that usesPreferenceKeys to bubble the image up the view hiearchy.Usage
Where you have your image for display, you would use the
.viewImage(image: UIImage?)modifier to request an image to be displayed like so:And anywhere higher up in the view hiearchy (in a different file) you can just attach the
.imageViewier()modifier to display that image.And that's it. No more passing images around manually.