I encountered a really weird animation subject in SwiftUI. I’m utilizing a customized animation with transition + uneven + removing ViewModifier. As proven within the footage, after I add an HStack component contained in the physique of FoldUpModifier, the animation works completely. Nevertheless, as soon as this seemingly meaningless HStack component is eliminated, the animation breaks—the view immediately disappears, and the animation slowly collapses into nothingness. May any senior iOS improvement engineers or Apple inside builders clarify what’s inflicting this?
import SwiftUI
struct NoticeMessageBarView: View {
var messages: [String]?
@State personal var present: Bool = true
var physique: some View {
if let msgs = messages, present {
HStack {
VerticalMessageCarousel(
messages: msgs,
scrollInterval: 3.5
)
Spacer()
Button {
withAnimation(.easeOut(length: 3)) {
present.toggle()
}
} label: {
Picture(systemName: "xmark")
}
}
.padding(.horizontal, 16)
.background(.tipsBackground)
.foregroundStyle(.tipsForeground)
.lineLimit(1)
.clipShape(RoundedRectangle(cornerRadius: 8))
.transition(
.uneven(
insertion: .opacity,
removing: .modifier(
energetic: FoldUpModifier(progress: 1),
identification: FoldUpModifier(progress: 0)
)
)
)
}
}
}
struct FoldUpModifier: ViewModifier {
var progress: CGFloat
func physique(content material: Content material) -> some View {
HStack {}
content material
.body(top: (1 - progress) * 40, alignment: .prime)
.clipped()
}
}
#Preview {
NoticeMessageBarView(messages: [
"🎉 Welcome!",
"🌟 Hello!",
])
Textual content("Different block")
Spacer()
}


