Following is the animation i want to achieve, when the view appears until the scrollview is scrolled the views are stacked one behind the other, and when they are scrolled it appears side by side.
struct ContentView: View {
private let colors: [Color] = [.red, .green, .blue, .yellow, .purple, .black, .brown, .cyan, .gray, .indigo, .orange, .pink, .mint, .teal]
var body: some View {
VStack {
ScrollView(.horizontal) {
LazyHStack(spacing: 10.0) {
ForEach(colors, id: \.self) { color in
RoundedRectangle(cornerRadius: 25.0)
.foregroundStyle(color)
.containerRelativeFrame(.horizontal)
.scrollTransition { content, phase in
content
.opacity(phase.isIdentity ? 1: 0.2)
.scaleEffect(y: phase.isIdentity ? 1.0 : 0.8)
}
}
}
.scrollTargetLayout()
}
.contentMargins(60.0, for: .scrollContent)
.scrollTargetBehavior(.viewAligned)
.scrollIndicators(.hidden)
.frame(maxHeight: 400.0)
Spacer()
}
}
}
I am able to get the views side by side, but how to get the views arranged one behind and then smoothly transition to side by side when scrolled.