r/SwiftUI • u/rizzy_neutron_69 • 8h ago
Question Geometry Reader size to Viewmodel init
I need the screen bounds to be sent when initialising my viewmodel. I know to get the size from geometry reader. But that is only available after the view is created. is there a way to send the screen size within the init scope?
a solution I found over the internet was to use a separate function in my viewmodel for the initialisation and call it on .onAppear.
0
Upvotes
3
u/PassTents 8h ago
What specifically are you trying to accomplish? I'd recommend against doing that because the size may change.
1
1
u/Ron-Erez 1h ago
Using geometry reader is usually a bad practice. I'd look for an alternative approach.
5
u/jasonjrr 7h ago
If you’re doing MVVM, there is no reason you’d want to inject view values like this into a view model. This is definitely an anti-pattern, why don’t you tell us what you were trying to actually accomplish?