-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ViewModifier increases height of view on load. #4
Comments
The above code is encapsulated in a VStack which also has a list above this HStack. Applying the ViewModifier on the Top Level View works perfectly. Why's that? Also, Is there a way to account for the height of TabBarView in this? As My app is based on Tab View, the field goes higher than expected because of tab view. |
@sethi-ishmeet When you apply the modifier to the HStack it actually wraps your HStack in a GeometryReader. GeometryReader always tries to fill all available space, and it centers its content (your HStack) – that's why your view has increased in size. |
@Coffeemate What would be the alternative? Pass the frameSize to the keyboardAdaptive? |
@ercillagorka I observed that when you apply this ViewModifier to the parent view, it works as expected. However, I think that it should be applied to specific text field and not the whole view. |
@Coffeemate many thanks for your explanation. I've added a note to the article based on your comment. |
@V8tr Thanks for updating the article. It might also be worth mentioning that the View Modifier should be applied to the parent view vs. the Text Field or child view. For example, I changed where I was applying the View Modifier which fixed the issue. Below is the working code:
|
@V8tr Loved the article. Well written and allowed me to understand all. I'm still a beginner and really can appreciate when subtle things are explained well. If the texfield is buried down the view Hierarchy it messes the geometry.frame(in: .global) as it doesn't seem to return the top level but the parent one. |
I applied the View Modifier on a HStack that includes a TextField and a Button. Although the keyboard adaptivity works fine, the initial height has increased and my content has been centred automatically.
The text was updated successfully, but these errors were encountered: