Sometimes we just want to use modifiers but don't have a view to draw to the screen, for example an .overlay {}
modifier on a view needs a view inside it before you can add modifiers on to that overlay view.
The current approach for this type of thing seems to be Color.clear
and while I've seen this almost everywhere I'm not sure if this is
a) the officially recommended way to do this in SwiftUI and
b) the only way to do this in SwiftUI?
I have the following custom view in my project just to avoid the explicit use of Color.clear
import SwiftUI
struct ClearView: View {
var body: some View {
Color.clear
}
}
Are there any other ways to do this?
Note - this is of course not the same as EmptyView()
- where Color.clear
renders a view with a transparent colour and EmptyView
which doesn't render anything at all.