Dynamic height

I'm having a problem with the height of my objects being to big on small devices.

It looks great on bigger devices like the iPhone 13 or basically anything over iPhone 11. But on iPhone 8 it's to big

I have my code broken into parts

This shows just the part I want (my seconds object)

Which I reference into a new screen here

  • Combining all of the other views which are also their own file

Finally I then combine that to my main view.

  • See the bottom there. It's being cut off.

Now, I can hear you thinking "use geometry reader". I did that. and the result promising, but still not right.

Looks great on the object screen itself

But then when I add it to my parent screen it turns to this.

Now I'm like well crap.... any thoughts on what I can look into? I can post some code too so you can see what I'm doing there, but I figured I'd start with the screenshots and answer some questions with code as they come in.

I'd really appreciate some help

Aim

  • To find the size (height) of a view

Approach

  • Use the GeometryReader on the .background of the view you want to calculate the size, that way GeometryReader wouldn't tamper the view's dimensions
  • Send the size (height) determined to the parent view using @Binding or Preferences

Binding

  • A reference to a value type

Preferences

  • You could read a bit about Preferences, it is used to send value to the parent views (opposite of what environment value does)
  • Create a PreferenceKey
  • Set the preference using .preference modifier
  • Detect the value change using onPreferenceChange
Dynamic height
 
 
Q