LazyVStack определен как показано ниже:
Код: Выделить всё
struct FeedView: View {
var body: some View {
NavigationStack {
ScrollView {
LazyVStack(spacing: 8) {
ForEach(Post.MOCK_POSTS) { post in
FeedPostView(post: post)
}
}
.padding(.top, 10)
}
.navigationTitle("Feed")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Image(systemName: "message")
.imageScale(.large)
}
}
}
}
}
[img]https://i .sstatic.net/AJQ7FUr8.png[/img]
и структура FeedPostView следующая:
Код: Выделить всё
struct FeedPostView: View {
let post: Post
var body: some View {
NavigationStack {
ZStack {
NavigationLink(destination: PostDetailsView(post: post)) {
Image(post.images[0])
.resizable()
.aspectRatio(contentMode: .fit)
.scaledToFill()
}
}
.frame(maxWidth: .infinity, maxHeight: 450)
.clipShape(RoundedRectangle(cornerRadius: 15.0))
.overlay(PostHeaderView(post: post), alignment: .top)
.overlay(PostCaptionView(post: post), alignment: .bottom)
.padding([.leading, .trailing])
.padding(.bottom, 15)
}
}
}
- Заголовок медленно перемещается в верхнюю часть экрана.
- Изображение перемещается под заголовок.
Затем я добавлю новый раздел ниже.
видео
Подробнее здесь: https://stackoverflow.com/questions/790 ... -lazystack
Мобильная версия