This repository has been archived on 2025-11-05. You can view files and clone it, but cannot push or open issues or pull requests.
ios_app/Shared/Views/Tab/HomeTab.swift
2025-08-14 02:09:38 +03:00

71 lines
1.9 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import SwiftUI
struct HomeTab: View {
@State private var posts: [Post] = []
@State private var isLoading = true
@State private var isRefreshing = false
var onScroll: ((CGPoint) -> Void)?
var body: some View {
VStack {
if isLoading {
ProgressView("Загрузка ленты...")
} else {
RefreshableScrollView(
isRefreshing: $isRefreshing,
onRefresh: { fetchData() },
onScroll: onScroll
) {
LazyVStack(spacing: 24) {
ForEach(posts) { post in
PostDetailView(post: post)
}
}
}
}
}
.onAppear {
if posts.isEmpty {
fetchData(isInitialLoad: true)
}
}
}
// private func fetchData(isInitialLoad: Bool = false) {
// if isInitialLoad {
// isLoading = true
// } else {
// isRefreshing = true
// }
//
// PostService.shared.fetchAllPosts { fetchedPosts in
// self.posts = fetchedPosts
//
// if isInitialLoad {
// print("content updated")
// self.isLoading = false
// }
// self.isRefreshing = false
// }
// }
private func fetchData(isInitialLoad: Bool = false) {
if isInitialLoad {
isLoading = true
} else {
isRefreshing = true
}
// Временный код вместо PostService
self.posts = [] // или сюда можно подставить мок-данные
// Сбрасываем индикаторы загрузки
if isInitialLoad {
self.isLoading = false
}
self.isRefreshing = false
}
}