Questions tagged [geometryreader]

A container view that defines its content as a function of its own size and coordinate space. Returns a flexible preferred size to its parent layout.

It's a component of Apple's SwiftUI language.

Learn more from Apple's documentation

184 questions
2
votes
3 answers

Infinite loop when using a GeometryReader and Padding

I have a two Text components inside a VStack and I'm using GeometryReader to match their widths. The problem is if I apply padding AFTER setting frame to the Text with the shorter content, I run into an infinite loop. I want to understand why this…
meowmeowmeow
  • 713
  • 7
  • 17
2
votes
1 answer

SwiftUI center align a view except if another view "pushes" it up

Here is a breakdown. I have a zstack that contains 2 vstacks. first vstack has a spacer and an image second has a text and button. ZStack { VStack { Spacer() Image("some image") } VStack { Text("press the…
2
votes
1 answer

onPreferenceChange not called on geometryReader frame change

PreferenceKey definition struct ScrollPrefKey: PreferenceKey { static var defaultValue: CGFloat = 0 static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) { value = nextValue() } } Main Code ScrollView { …
royB
  • 12,779
  • 15
  • 58
  • 80
2
votes
1 answer

SwiftUI - Attempted to scroll the collection view to an out-of-bounds item

My App is getting crashed immediately after navigating to the screen in iOS>16.0 devices by saying *** Assertion failure in -[_TtC7SwiftUIP33_8825076C2763A50452A210CBE1FA4AF020PagingCollectionView _validateScrollingTargetIndexPath:],…
Bhanuteja
  • 771
  • 2
  • 8
  • 18
2
votes
1 answer

GeometryReader acting weird when presenting a modal on iOS 16. Bug or new behavior?

I'm seeing a weird behavior that is affecting one of my views in SwiftUI after upgrading to iOS 16. Just to give some context, here is the stack: Xcode 14 Simulator or real device on iOS 15.5 and 16 Considering the minimum reproducible code…
bguidolim
  • 367
  • 2
  • 9
2
votes
1 answer

Odd animation with .matchedGeometryEffect and NavigationView

I'm working on creating a view which uses matchedGeometryEffect, embedded within a NavigationView, and when presenting the second view another NavigationView. The animation "works" and it matches correctly, however when it toggles from view to view…
markb
  • 1,100
  • 1
  • 15
  • 40
2
votes
1 answer

Alignment for GeometryReader and .frame

I'm using GeometryReader() and .frame() to show their comparability and playing with their width. However the object wrapped in GeometryReader() doesn't have center alignment when width is less than minimum. Please refer to attached gifs for…
Kate Sychenko
  • 33
  • 1
  • 6
2
votes
1 answer

How to align properly with GeometryReader in SwiftUI

So I am making an app and I had a problem with GeometryReader. I created a test file and cannot figure out what I a doing wrong. I am trying to align all Text views to leading. However only two of them actually move. I have a VStack embedded in a…
Tomas
  • 135
  • 1
  • 6
2
votes
1 answer

SwiftUI linear gauge

UPDATE I was able to get something closer to what I'm trying to achieve. Still needs work. I attempted to use a rounded rectangle for the mask but doesn't look good. Any suggestions would be greatly appreciated. GeometryReader { geometry in …
cole
  • 1,039
  • 1
  • 8
  • 35
2
votes
1 answer

GeometryReader with NavigationView in SwiftUI is initially giving .zero for size

I have a GeometryReader in a NavigationView and initially the size is 0 when the view first displayed. I'm not sure if it's a bug or the correct behavior but I'm looking for a way to solve this as my child views are not rendering correctly. This…
alionthego
  • 8,508
  • 9
  • 52
  • 125
2
votes
1 answer

SwiftUI: How can I get the frame of a view in a dynamic List or LazyVStack

I would like to get the frame of a view in a LazyVStack. The LazyVStack embedded in a ScrollView displays chat messages (Text and Images). Because the content is dynamically sized I am not able to use a GeometryReader Proxy. Putting a…
alionthego
  • 8,508
  • 9
  • 52
  • 125
2
votes
1 answer

SwiftUI: how can to calculate the width of a Text view?

I have unknown number of Text views I need to account for (as many hours that pass during sleep). Each Text view is just a single hour e.g. Text("12"), Text("1") etc. I need to know the width of all the combined hour Text Views so I can subtract…
GarySabo
  • 5,806
  • 5
  • 49
  • 124
2
votes
3 answers

Display SwiftUI view only if it has enough space

Here is the contents of my view: HStack { Banner(items: items) .layoutPriority(100) OptionalView() } I want to only display the OptionalView if there is a minimum amount of width left over for it after displaying…
Jeff G
  • 1,996
  • 1
  • 13
  • 22
2
votes
0 answers

How to use .firstTextBaseline alignment with a view that contains GeometryReader

I have two views in a HStack - the left one is a simple Text view. For the right view, i'm experimenting with using GeometryReader. I cannot get the baselines of the text aligned when I use geometry reader, but I can when I don't use it. Here is…
tng
  • 4,286
  • 5
  • 21
  • 30
2
votes
1 answer

SwiftUI HStack elements with equal height

I want both the buttons to have equal height similar to Equal Height constraint in UIKit. Don't want to specify the frame, let SwiftUI handle it but the elements in HStack should be of the same height. Buttons should have equal width and height and…
Pablo Dev
  • 317
  • 5
  • 16