add post scroll
This commit is contained in:
parent
cca9dd3ce3
commit
a477ce2f78
@ -1,97 +1,85 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct PostDetailView: View {
|
struct PostDetailView: View {
|
||||||
let postID: UUID
|
let post: Post
|
||||||
@State private var post: Post?
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(alignment: .leading, spacing: 0) {
|
VStack(alignment: .leading, spacing: 0) {
|
||||||
if let post = post {
|
// Шапка поста
|
||||||
// Шапка поста
|
HStack {
|
||||||
HStack {
|
Image(systemName: "person.crop.circle.fill")
|
||||||
Image(systemName: "person.crop.circle.fill")
|
.resizable()
|
||||||
.resizable()
|
.frame(width: 36, height: 36)
|
||||||
.frame(width: 36, height: 36)
|
.foregroundColor(.gray)
|
||||||
.foregroundColor(.gray)
|
Text(post.authorUsername)
|
||||||
Text(post.authorUsername)
|
.font(.headline)
|
||||||
.font(.headline)
|
|
||||||
Spacer()
|
|
||||||
Button(action: {}) {
|
|
||||||
Image(systemName: "ellipsis")
|
|
||||||
.foregroundColor(.primary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding(.horizontal)
|
|
||||||
.padding(.vertical, 8)
|
|
||||||
|
|
||||||
// Изображение поста
|
|
||||||
Rectangle()
|
|
||||||
.fill(Color.gray.opacity(0.3))
|
|
||||||
.aspectRatio(1, contentMode: .fit)
|
|
||||||
.frame(maxWidth: .infinity)
|
|
||||||
|
|
||||||
// Панель действий
|
|
||||||
HStack(spacing: 16) {
|
|
||||||
Button(action: {}) {
|
|
||||||
Image(systemName: "heart")
|
|
||||||
.font(.system(size: 24))
|
|
||||||
}
|
|
||||||
Button(action: {}) {
|
|
||||||
Image(systemName: "message")
|
|
||||||
.font(.system(size: 24))
|
|
||||||
}
|
|
||||||
Button(action: {}) {
|
|
||||||
Image(systemName: "paperplane")
|
|
||||||
.font(.system(size: 24))
|
|
||||||
}
|
|
||||||
Spacer()
|
|
||||||
Button(action: {}) {
|
|
||||||
Image(systemName: "bookmark")
|
|
||||||
.font(.system(size: 24))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.foregroundColor(.primary)
|
|
||||||
.padding(.horizontal)
|
|
||||||
.padding(.top, 8)
|
|
||||||
|
|
||||||
// Лайки и описание
|
|
||||||
VStack(alignment: .leading, spacing: 4) {
|
|
||||||
Text("\(post.likes) likes")
|
|
||||||
.font(.headline)
|
|
||||||
|
|
||||||
Text(post.description ?? "")
|
|
||||||
.font(.subheadline)
|
|
||||||
}
|
|
||||||
.padding(.horizontal)
|
|
||||||
.padding(.top, 8)
|
|
||||||
|
|
||||||
// Комментарии
|
|
||||||
VStack(alignment: .leading, spacing: 4) {
|
|
||||||
Text("View all \(post.commentsCount) comments")
|
|
||||||
.font(.caption)
|
|
||||||
.foregroundColor(.secondary)
|
|
||||||
.padding(.top, 4)
|
|
||||||
|
|
||||||
Text("2 hours ago")
|
|
||||||
.font(.caption2)
|
|
||||||
.foregroundColor(.secondary)
|
|
||||||
.padding(.top, 4)
|
|
||||||
}
|
|
||||||
.padding(.horizontal)
|
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
Button(action: {}) {
|
||||||
} else {
|
Image(systemName: "ellipsis")
|
||||||
ProgressView("Загрузка...")
|
.foregroundColor(.primary)
|
||||||
.onAppear {
|
}
|
||||||
// Симуляция загрузки поста
|
|
||||||
PostService.shared.fetchPost(by: postID) { fetchedPost in
|
|
||||||
self.post = fetchedPost
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
.padding(.horizontal)
|
||||||
|
.padding(.vertical, 8)
|
||||||
|
|
||||||
|
// Изображение поста
|
||||||
|
Rectangle()
|
||||||
|
.fill(Color.gray.opacity(0.3))
|
||||||
|
.aspectRatio(1, contentMode: .fit)
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
|
||||||
|
// Панель действий
|
||||||
|
HStack(spacing: 16) {
|
||||||
|
Button(action: {}) {
|
||||||
|
Image(systemName: "heart")
|
||||||
|
.font(.system(size: 24))
|
||||||
|
}
|
||||||
|
Button(action: {}) {
|
||||||
|
Image(systemName: "message")
|
||||||
|
.font(.system(size: 24))
|
||||||
|
}
|
||||||
|
Button(action: {}) {
|
||||||
|
Image(systemName: "paperplane")
|
||||||
|
.font(.system(size: 24))
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
Button(action: {}) {
|
||||||
|
Image(systemName: "square.and.arrow.down")
|
||||||
|
.font(.system(size: 24))
|
||||||
|
}
|
||||||
|
Button(action: {}) {
|
||||||
|
Image(systemName: "bookmark")
|
||||||
|
.font(.system(size: 24))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.foregroundColor(.primary)
|
||||||
|
.padding(.horizontal)
|
||||||
|
.padding(.top, 8)
|
||||||
|
|
||||||
|
// Лайки и описание
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
Text("\(post.likes) likes")
|
||||||
|
.font(.headline)
|
||||||
|
|
||||||
|
Text(post.description ?? "")
|
||||||
|
.font(.subheadline)
|
||||||
|
}
|
||||||
|
.padding(.horizontal)
|
||||||
|
.padding(.top, 8)
|
||||||
|
|
||||||
|
// Комментарии
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
Text("View all \(post.commentsCount) comments")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
.padding(.top, 4)
|
||||||
|
|
||||||
|
Text("2 hours ago")
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
.padding(.top, 4)
|
||||||
|
}
|
||||||
|
.padding(.horizontal)
|
||||||
}
|
}
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
|
||||||
.navigationTitle("Post")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
23
Shared/Views/Tab/Profile/PostFeedView.swift
Normal file
23
Shared/Views/Tab/Profile/PostFeedView.swift
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct PostFeedView: View {
|
||||||
|
let posts: [Post]
|
||||||
|
let selectedPostID: UUID
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
ScrollViewReader { proxy in
|
||||||
|
ScrollView {
|
||||||
|
LazyVStack(spacing: 24) {
|
||||||
|
ForEach(posts) { post in
|
||||||
|
PostDetailView(post: post)
|
||||||
|
.id(post.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.navigationBarTitle("Feed", displayMode: .inline)
|
||||||
|
.onAppear {
|
||||||
|
proxy.scrollTo(selectedPostID, anchor: .center)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -28,7 +28,7 @@ struct ProfileContentGrid: View {
|
|||||||
} else {
|
} else {
|
||||||
LazyVGrid(columns: Array(repeating: .init(.flexible()), count: 3), spacing: 2) {
|
LazyVGrid(columns: Array(repeating: .init(.flexible()), count: 3), spacing: 2) {
|
||||||
ForEach(filteredPosts) { post in
|
ForEach(filteredPosts) { post in
|
||||||
NavigationLink(destination: PostDetailView(postID: post.id)) {
|
NavigationLink(destination: PostFeedView(posts: filteredPosts, selectedPostID: post.id)) {
|
||||||
Rectangle()
|
Rectangle()
|
||||||
.fill(Color.gray.opacity(0.2))
|
.fill(Color.gray.opacity(0.2))
|
||||||
.aspectRatio(1, contentMode: .fit)
|
.aspectRatio(1, contentMode: .fit)
|
||||||
|
|||||||
@ -37,6 +37,7 @@
|
|||||||
1ACE61152E22FE2000B37AC5 /* PostDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ACE61142E22FE2000B37AC5 /* PostDetailView.swift */; };
|
1ACE61152E22FE2000B37AC5 /* PostDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ACE61142E22FE2000B37AC5 /* PostDetailView.swift */; };
|
||||||
1ACE61192E22FF1400B37AC5 /* Post.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ACE61182E22FF1400B37AC5 /* Post.swift */; };
|
1ACE61192E22FF1400B37AC5 /* Post.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ACE61182E22FF1400B37AC5 /* Post.swift */; };
|
||||||
1ACE61212E22FFD000B37AC5 /* ProfileContentTabbedGrid.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ACE61202E22FFD000B37AC5 /* ProfileContentTabbedGrid.swift */; };
|
1ACE61212E22FFD000B37AC5 /* ProfileContentTabbedGrid.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ACE61202E22FFD000B37AC5 /* ProfileContentTabbedGrid.swift */; };
|
||||||
|
1AD757CD2E27608C0069C1FD /* PostFeedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AD757CC2E27608C0069C1FD /* PostFeedView.swift */; };
|
||||||
1AE587052E23264800254F06 /* PostService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AE587042E23264800254F06 /* PostService.swift */; };
|
1AE587052E23264800254F06 /* PostService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AE587042E23264800254F06 /* PostService.swift */; };
|
||||||
1AE587252E23337000254F06 /* ProfileContentGrid.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AE587242E23337000254F06 /* ProfileContentGrid.swift */; };
|
1AE587252E23337000254F06 /* ProfileContentGrid.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AE587242E23337000254F06 /* ProfileContentGrid.swift */; };
|
||||||
1AEE5EAB2E21A83200A3DCA3 /* HomeTab.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AEE5EAA2E21A83200A3DCA3 /* HomeTab.swift */; };
|
1AEE5EAB2E21A83200A3DCA3 /* HomeTab.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AEE5EAA2E21A83200A3DCA3 /* HomeTab.swift */; };
|
||||||
@ -79,6 +80,7 @@
|
|||||||
1ACE61142E22FE2000B37AC5 /* PostDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostDetailView.swift; sourceTree = "<group>"; };
|
1ACE61142E22FE2000B37AC5 /* PostDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostDetailView.swift; sourceTree = "<group>"; };
|
||||||
1ACE61182E22FF1400B37AC5 /* Post.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Post.swift; sourceTree = "<group>"; };
|
1ACE61182E22FF1400B37AC5 /* Post.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Post.swift; sourceTree = "<group>"; };
|
||||||
1ACE61202E22FFD000B37AC5 /* ProfileContentTabbedGrid.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileContentTabbedGrid.swift; sourceTree = "<group>"; };
|
1ACE61202E22FFD000B37AC5 /* ProfileContentTabbedGrid.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileContentTabbedGrid.swift; sourceTree = "<group>"; };
|
||||||
|
1AD757CC2E27608C0069C1FD /* PostFeedView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PostFeedView.swift; sourceTree = "<group>"; };
|
||||||
1AE587042E23264800254F06 /* PostService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostService.swift; sourceTree = "<group>"; };
|
1AE587042E23264800254F06 /* PostService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostService.swift; sourceTree = "<group>"; };
|
||||||
1AE587242E23337000254F06 /* ProfileContentGrid.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileContentGrid.swift; sourceTree = "<group>"; };
|
1AE587242E23337000254F06 /* ProfileContentGrid.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileContentGrid.swift; sourceTree = "<group>"; };
|
||||||
1AEE5EAA2E21A83200A3DCA3 /* HomeTab.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeTab.swift; sourceTree = "<group>"; };
|
1AEE5EAA2E21A83200A3DCA3 /* HomeTab.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeTab.swift; sourceTree = "<group>"; };
|
||||||
@ -256,6 +258,7 @@
|
|||||||
1AEE5ECC2E21C9D100A3DCA3 /* Profile */ = {
|
1AEE5ECC2E21C9D100A3DCA3 /* Profile */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
1AD757CC2E27608C0069C1FD /* PostFeedView.swift */,
|
||||||
1ACE60FF2E22F54700B37AC5 /* Settings */,
|
1ACE60FF2E22F54700B37AC5 /* Settings */,
|
||||||
1A7940CD2DF7A9AA002569DA /* ProfileTab.swift */,
|
1A7940CD2DF7A9AA002569DA /* ProfileTab.swift */,
|
||||||
1AB4F8CC2E22E341002B6E40 /* AccountShareSheet.swift */,
|
1AB4F8CC2E22E341002B6E40 /* AccountShareSheet.swift */,
|
||||||
@ -369,6 +372,7 @@
|
|||||||
files = (
|
files = (
|
||||||
1AEE5EAB2E21A83200A3DCA3 /* HomeTab.swift in Sources */,
|
1AEE5EAB2E21A83200A3DCA3 /* HomeTab.swift in Sources */,
|
||||||
1ACE60F82E22F3DC00B37AC5 /* SettingsView.swift in Sources */,
|
1ACE60F82E22F3DC00B37AC5 /* SettingsView.swift in Sources */,
|
||||||
|
1AD757CD2E27608C0069C1FD /* PostFeedView.swift in Sources */,
|
||||||
1A7940C62DF7A98E002569DA /* ContactsTab.swift in Sources */,
|
1A7940C62DF7A98E002569DA /* ContactsTab.swift in Sources */,
|
||||||
1ACE61092E22F57100B37AC5 /* AppPreferencesView.swift in Sources */,
|
1ACE61092E22F57100B37AC5 /* AppPreferencesView.swift in Sources */,
|
||||||
1ACE61052E22F56800B37AC5 /* SecuritySettingsView.swift in Sources */,
|
1ACE61052E22F56800B37AC5 /* SecuritySettingsView.swift in Sources */,
|
||||||
|
|||||||
Reference in New Issue
Block a user