0

I have made a list in SwiftUI and I want to make the element views of list able to resize to show more information. Currently when I change the height they just start overlapping each other though. How can I make it so that when the view's height changes it updates the padding between list elements to keep it consistent. Below I have a screen shot of the overlap I am talking about and the relevant code:

enter image description here

here is where I create the list:

List{
      //loop through task cards
      ForEach(self.tasks, id: \.id) { task in
          task
      }
} 

and here is the body code for the task cards that are shown in the list:


var height : CGFloat = 105

var body: some View {
            RoundedRectangle(cornerRadius: 10)
                .foregroundColor(Color.white)
                .frame(height: self.completedLongPress ? self.height + 50 : self.height) // here is where height is changed
                .overlay(
                      //content added in here (I don't think it's particularly important for the problem, but will edit if it's needed)
                    )
            .gesture(self.longPress)

        }
3
  • Does this answer your question stackoverflow.com/a/62482773/12299030 or stackoverflow.com/a/61913880/12299030? Commented Sep 17, 2020 at 17:14
  • @Asperi interesting, in both of those examples the cell height is being changed automatically it seems (even in the question). That is the effect I want. In my situation the space for the cell in the list isn't changing when I change the height, so the cells end up overlapping Commented Sep 17, 2020 at 17:47
  • 1
    Overlay does not change the frame of parent view. Commented Sep 17, 2020 at 17:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.