From a477ce2f78666376a09dc852989c75158ef74e9a Mon Sep 17 00:00:00 2001 From: cheykrym Date: Wed, 16 Jul 2025 07:24:32 +0300 Subject: [PATCH] add post scroll --- Shared/Views/Tab/Profile/PostDetailView.swift | 160 ++++++++---------- Shared/Views/Tab/Profile/PostFeedView.swift | 23 +++ .../Tab/Profile/ProfileContentGrid.swift | 2 +- yobble.xcodeproj/project.pbxproj | 4 + 4 files changed, 102 insertions(+), 87 deletions(-) create mode 100644 Shared/Views/Tab/Profile/PostFeedView.swift diff --git a/Shared/Views/Tab/Profile/PostDetailView.swift b/Shared/Views/Tab/Profile/PostDetailView.swift index d2108e3..5a1fb34 100644 --- a/Shared/Views/Tab/Profile/PostDetailView.swift +++ b/Shared/Views/Tab/Profile/PostDetailView.swift @@ -1,97 +1,85 @@ import SwiftUI struct PostDetailView: View { - let postID: UUID - @State private var post: Post? + let post: Post var body: some View { VStack(alignment: .leading, spacing: 0) { - if let post = post { - // Шапка поста - HStack { - Image(systemName: "person.crop.circle.fill") - .resizable() - .frame(width: 36, height: 36) - .foregroundColor(.gray) - Text(post.authorUsername) - .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) - + // Шапка поста + HStack { + Image(systemName: "person.crop.circle.fill") + .resizable() + .frame(width: 36, height: 36) + .foregroundColor(.gray) + Text(post.authorUsername) + .font(.headline) Spacer() - - } else { - ProgressView("Загрузка...") - .onAppear { - // Симуляция загрузки поста - PostService.shared.fetchPost(by: postID) { fetchedPost in - self.post = fetchedPost - } - } + 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: "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") } } diff --git a/Shared/Views/Tab/Profile/PostFeedView.swift b/Shared/Views/Tab/Profile/PostFeedView.swift new file mode 100644 index 0000000..fa9c4fc --- /dev/null +++ b/Shared/Views/Tab/Profile/PostFeedView.swift @@ -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) + } + } + } +} diff --git a/Shared/Views/Tab/Profile/ProfileContentGrid.swift b/Shared/Views/Tab/Profile/ProfileContentGrid.swift index 781f31d..f3add88 100644 --- a/Shared/Views/Tab/Profile/ProfileContentGrid.swift +++ b/Shared/Views/Tab/Profile/ProfileContentGrid.swift @@ -28,7 +28,7 @@ struct ProfileContentGrid: View { } else { LazyVGrid(columns: Array(repeating: .init(.flexible()), count: 3), spacing: 2) { ForEach(filteredPosts) { post in - NavigationLink(destination: PostDetailView(postID: post.id)) { + NavigationLink(destination: PostFeedView(posts: filteredPosts, selectedPostID: post.id)) { Rectangle() .fill(Color.gray.opacity(0.2)) .aspectRatio(1, contentMode: .fit) diff --git a/yobble.xcodeproj/project.pbxproj b/yobble.xcodeproj/project.pbxproj index b42ece3..9a28ca7 100644 --- a/yobble.xcodeproj/project.pbxproj +++ b/yobble.xcodeproj/project.pbxproj @@ -37,6 +37,7 @@ 1ACE61152E22FE2000B37AC5 /* PostDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ACE61142E22FE2000B37AC5 /* PostDetailView.swift */; }; 1ACE61192E22FF1400B37AC5 /* Post.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ACE61182E22FF1400B37AC5 /* Post.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 */; }; 1AE587252E23337000254F06 /* ProfileContentGrid.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AE587242E23337000254F06 /* ProfileContentGrid.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 = ""; }; 1ACE61182E22FF1400B37AC5 /* Post.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Post.swift; sourceTree = ""; }; 1ACE61202E22FFD000B37AC5 /* ProfileContentTabbedGrid.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileContentTabbedGrid.swift; sourceTree = ""; }; + 1AD757CC2E27608C0069C1FD /* PostFeedView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PostFeedView.swift; sourceTree = ""; }; 1AE587042E23264800254F06 /* PostService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostService.swift; sourceTree = ""; }; 1AE587242E23337000254F06 /* ProfileContentGrid.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileContentGrid.swift; sourceTree = ""; }; 1AEE5EAA2E21A83200A3DCA3 /* HomeTab.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeTab.swift; sourceTree = ""; }; @@ -256,6 +258,7 @@ 1AEE5ECC2E21C9D100A3DCA3 /* Profile */ = { isa = PBXGroup; children = ( + 1AD757CC2E27608C0069C1FD /* PostFeedView.swift */, 1ACE60FF2E22F54700B37AC5 /* Settings */, 1A7940CD2DF7A9AA002569DA /* ProfileTab.swift */, 1AB4F8CC2E22E341002B6E40 /* AccountShareSheet.swift */, @@ -369,6 +372,7 @@ files = ( 1AEE5EAB2E21A83200A3DCA3 /* HomeTab.swift in Sources */, 1ACE60F82E22F3DC00B37AC5 /* SettingsView.swift in Sources */, + 1AD757CD2E27608C0069C1FD /* PostFeedView.swift in Sources */, 1A7940C62DF7A98E002569DA /* ContactsTab.swift in Sources */, 1ACE61092E22F57100B37AC5 /* AppPreferencesView.swift in Sources */, 1ACE61052E22F56800B37AC5 /* SecuritySettingsView.swift in Sources */,