I am learning SwiftUI. And I come across to \"GeometryReader\". And I want to know why and when to use it?
Reader in The SwiftUI?In addition to the kontiki's answer, Readers are container views that define their content as a function. So they can have some access and abilities about their parent. They are generic structs if you look more closely and there is 2 readers available now in SwiftUI 2.0:
Note that it's just a convention, they're not conforming special protocl more of the View protocl.
struct GeometryReader : View
This is A container view that defines its content as a function of its own size and coordinate space. So you can detect frame and position changes and the current state of any view withing a GeometryReader. One of the popular usage of this reader that when you need separate views in separate stacks have the same (or relative) sizes.
struct ScrollViewReader : View
This is view whose child is defined as a function of a ScrollViewProxy targeting the scrollable views within the child. So you can have some access to the scrollview like scrolling to a specific item in a list or similar stuff.
To minimalizing the duplication, I didn't post examples, you can check the link for more information if you want