0

I have a view with a WrappingHStack in it. The view has withAnimation when it is displayed, with .transition(.move(edge: .bottom)) as the transition on it.

WrappingHStack: https://github.com/dkk/WrappingHStack

In the following code, everything in the view (e.g. the Text("Lorem ipsum")) correctly transitions with the slide. Except for the WrappingHStack. I added .transition(.slide), still nothing. It just appears instantly in place while everything around it slides in. Why is this, and how do I get it to slide alongside the other content?

VStack {
    Text("Lorem ipsum")
        .font(.system(size: 18, weight: .medium, design: .rounded))
        .foregroundStyle(.black)
    
    WrappingHStack(0..<self.words.count, id:\.self, alignment: .center) { i in
        Button(action: {
            //
        }) {
            Text(words[i])
                .font(.system(size: 18, weight: .bold, design: .rounded))
                .foregroundColor(.white)
        }
        .padding(.bottom, 10)
    }
    .transition(.slide)
}
Joseph
  • 691
  • 4
  • 18
  • What's a `WrappingHStack`? – Ashley Mills Feb 11 '23 at 12:59
  • Sorry, I should have clarified that. It's this: https://github.com/dkk/WrappingHStack – Joseph Feb 11 '23 at 13:03
  • 2
    I looked at the code and it is overly complex , I would suggest looking on SO for a simpler solution that would work with animations. You can also create your own with SwiftUI.Layout that would be more compatible. – lorem ipsum Feb 11 '23 at 14:02
  • @loremipsum I would not say that it is overly complex. It is as simple as it can be when working with unspecified Views and content types. However, you could obviously create a simpler solution when creating it for a specific case. – Daniel Mar 06 '23 at 08:38
  • @Daniel I am assuming that is your product? You should watch “Demystify SwiftUI” if I remember correctly it is overly complex because you are fighting SwiftUI instead of working with it, I don’t remember details but the video should give you some clues. – lorem ipsum Mar 06 '23 at 11:56
  • By "Working with SwiftUI", there are quite a few problems you cannot solve. But I am open for improvement if you have anything specific in mind. Note that this project came into being because nobody else was able to solve it in a generic way (you may search for a better or similar solution, I wasn't able to find any) ;) and it is a task that is not completely straight forward to solve for specific cases either. There are some tutorials, but nothing that works for all cases. E.g. mixing different types of view is almost never supported. – Daniel Mar 06 '23 at 12:54

1 Answers1

0

My issue was with self.words.count in the loop — the words array only got populated from an onAppear inside the view. Seems like anything that isn't present at the init of the view does not get animated in. If I populate the array before loading the view, everything slides in as expected.

Joseph
  • 691
  • 4
  • 18