0

I have this so far:

                .background(
                    GeometryReader { geo in
                        Color.clear
                            .onAppear {
                                profileViewHeight = geo.size.height
                            }
                    }
                )

I need to update profileViewHeight also as soon as the height of this view changes.

I tried:

                .background(
                    GeometryReader { geo in
                        Color.clear
                            .onAppear {
                                profileViewHeight = geo.size.height
                            }
                            .onChange(of: , perform: {
                                profileViewHeight = geo.size.height
                            })
                    }
                )

But I don't know what is expected for of

I'm new to ios/swiftui and don't know how exactly to use this

user19559647
  • 191
  • 1
  • 1
  • 7
  • It is not clear what is the error you are getting, in which line. Your code is also not [reproducible](https://stackoverflow.com/help/minimal-reproducible-example), as you have shown only a small part of it and the `.onChange` modifier can't work if you don't pass a value to `of:` and a parameter to the closure. Please complete your question. – HunterLion Oct 31 '22 at 20:05
  • I already mentioned "But I don't know what is expected for of" – user19559647 Oct 31 '22 at 20:09
  • There is 'Equatable' expected and I don't know what this is and how to use it – user19559647 Oct 31 '22 at 20:11
  • Take a look at the [documentation](https://developer.apple.com/documentation/swiftui/view/onchange(of:perform:)) and do some search on the Internet, there are examples around on how it's used. But that's probably not what you're looking for here, but without more context, it's hard to answer to your question. – HunterLion Oct 31 '22 at 20:40
  • Thanks, that gives me an idea how else it can be done besides my answer – user19559647 Oct 31 '22 at 21:06

1 Answers1

0

I solved it this way:

    .background(
        GeometryReader { geo in
            Color.clear
                .onAppear {
                    profileViewHeight = geo.size.height
                }

                .onChange(of: geo.size.height) { _ in
                    if(geo.size.height > profileViewHeight){
                        profileViewHeight = geo.size.height
                    }
                }
            
        }
    )
user19559647
  • 191
  • 1
  • 1
  • 7