Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d5b32602b |
@ -91,7 +91,7 @@ struct TopBarView: View {
|
|||||||
.padding()
|
.padding()
|
||||||
.frame(height: 50) // Стандартная высота для нав. бара
|
.frame(height: 50) // Стандартная высота для нав. бара
|
||||||
|
|
||||||
Divider()
|
// Divider()
|
||||||
}
|
}
|
||||||
.background(Color(UIColor.systemBackground))
|
.background(Color(UIColor.systemBackground))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -132,9 +132,16 @@ class PostService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchAllPosts(completion: @escaping ([Post]) -> Void) {
|
func fetchAllPosts(page: Int, limit: Int, completion: @escaping ([Post]) -> Void) {
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||||
completion(self.posts)
|
let start = page * limit
|
||||||
|
let end = min(start + limit, self.posts.count)
|
||||||
|
|
||||||
|
if start < end {
|
||||||
|
completion(Array(self.posts[start..<end]))
|
||||||
|
} else {
|
||||||
|
completion([])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,53 +0,0 @@
|
|||||||
import SwiftUI
|
|
||||||
|
|
||||||
// Enum to represent the three theme options
|
|
||||||
enum Theme: String, CaseIterable {
|
|
||||||
case system = "System"
|
|
||||||
case light = "Light"
|
|
||||||
case dark = "Dark"
|
|
||||||
|
|
||||||
var colorScheme: ColorScheme? {
|
|
||||||
switch self {
|
|
||||||
case .system:
|
|
||||||
return nil
|
|
||||||
case .light:
|
|
||||||
return .light
|
|
||||||
case .dark:
|
|
||||||
return .dark
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Observable class to manage the theme state
|
|
||||||
class ThemeManager: ObservableObject {
|
|
||||||
@AppStorage("selectedTheme") private var selectedThemeValue: String = Theme.system.rawValue
|
|
||||||
|
|
||||||
@Published var theme: Theme
|
|
||||||
|
|
||||||
init() {
|
|
||||||
// Read directly from UserDefaults to avoid using self before initialization is complete.
|
|
||||||
let storedThemeValue = UserDefaults.standard.string(forKey: "selectedTheme") ?? ""
|
|
||||||
self.theme = Theme(rawValue: storedThemeValue) ?? .system
|
|
||||||
}
|
|
||||||
|
|
||||||
func setTheme(_ theme: Theme) {
|
|
||||||
self.theme = theme
|
|
||||||
selectedThemeValue = theme.rawValue
|
|
||||||
}
|
|
||||||
|
|
||||||
// This will be called from the button
|
|
||||||
func toggleTheme(from currentSystemScheme: ColorScheme) {
|
|
||||||
let newTheme: Theme
|
|
||||||
|
|
||||||
switch theme {
|
|
||||||
case .system:
|
|
||||||
// If system is active, toggle to the opposite of the current system theme
|
|
||||||
newTheme = currentSystemScheme == .dark ? .light : .dark
|
|
||||||
case .light:
|
|
||||||
newTheme = .dark
|
|
||||||
case .dark:
|
|
||||||
newTheme = .light
|
|
||||||
}
|
|
||||||
setTheme(newTheme)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -5,26 +5,70 @@ class NewHomeTabViewModel: ObservableObject {
|
|||||||
@Published var posts: [Post] = []
|
@Published var posts: [Post] = []
|
||||||
@Published var isLoading = true
|
@Published var isLoading = true
|
||||||
@Published var isRefreshing = false
|
@Published var isRefreshing = false
|
||||||
|
@Published var isLoadingPage = false
|
||||||
|
|
||||||
private var hasLoadedData = false
|
@Published var canLoadMorePages = true
|
||||||
|
|
||||||
|
private var currentPage = 0
|
||||||
|
private let postsPerPage = 10
|
||||||
|
|
||||||
func fetchDataIfNeeded() {
|
func fetchDataIfNeeded() {
|
||||||
guard !hasLoadedData else { return }
|
guard posts.isEmpty else { return }
|
||||||
refreshData()
|
fetchPosts()
|
||||||
}
|
}
|
||||||
|
|
||||||
func refreshData() {
|
func refreshData() {
|
||||||
DispatchQueue.main.async {
|
guard !isRefreshing else { return }
|
||||||
self.isRefreshing = true
|
|
||||||
|
isRefreshing = true
|
||||||
|
currentPage = 0
|
||||||
|
canLoadMorePages = true
|
||||||
|
|
||||||
|
fetchPosts(isRefresh: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadMoreContentIfNeeded(currentItem item: Post?) {
|
||||||
|
guard let item = item else {
|
||||||
|
fetchPosts()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
PostService.shared.fetchAllPosts { [weak self] fetchedPosts in
|
let thresholdIndex = posts.index(posts.endIndex, offsetBy: -5)
|
||||||
|
if posts.firstIndex(where: { $0.id == item.id }) == thresholdIndex {
|
||||||
|
fetchPosts()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func fetchPosts(isRefresh: Bool = false) {
|
||||||
|
guard !isLoadingPage, canLoadMorePages else {
|
||||||
|
if isRefresh {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.isRefreshing = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
isLoadingPage = true
|
||||||
|
if isRefresh {
|
||||||
|
currentPage = 0
|
||||||
|
} else {
|
||||||
|
currentPage += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
PostService.shared.fetchAllPosts(page: currentPage, limit: postsPerPage) { [weak self] fetchedPosts in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.posts = fetchedPosts
|
if isRefresh {
|
||||||
|
self.posts = fetchedPosts
|
||||||
|
} else {
|
||||||
|
self.posts.append(contentsOf: fetchedPosts)
|
||||||
|
}
|
||||||
|
|
||||||
|
self.canLoadMorePages = !fetchedPosts.isEmpty
|
||||||
self.isLoading = false
|
self.isLoading = false
|
||||||
self.hasLoadedData = true
|
self.isLoadingPage = false
|
||||||
self.isRefreshing = false
|
self.isRefreshing = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,8 +33,8 @@ struct CustomTabBar: View {
|
|||||||
}
|
}
|
||||||
.padding(.horizontal)
|
.padding(.horizontal)
|
||||||
.padding(.top, 1)
|
.padding(.top, 1)
|
||||||
.padding(.bottom, 30) // Добавляем отступ снизу
|
.padding(.bottom, 18) // Добавляем отступ снизу
|
||||||
// .background(Color(.systemGray6))
|
.background(Color(.systemGray6))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -32,6 +32,25 @@ struct HomeTab: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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) {
|
private func fetchData(isInitialLoad: Bool = false) {
|
||||||
if isInitialLoad {
|
if isInitialLoad {
|
||||||
isLoading = true
|
isLoading = true
|
||||||
@ -39,14 +58,13 @@ struct HomeTab: View {
|
|||||||
isRefreshing = true
|
isRefreshing = true
|
||||||
}
|
}
|
||||||
|
|
||||||
PostService.shared.fetchAllPosts { fetchedPosts in
|
// Временный код вместо PostService
|
||||||
self.posts = fetchedPosts
|
self.posts = [] // или сюда можно подставить мок-данные
|
||||||
|
|
||||||
if isInitialLoad {
|
// Сбрасываем индикаторы загрузки
|
||||||
print("content updated")
|
if isInitialLoad {
|
||||||
self.isLoading = false
|
self.isLoading = false
|
||||||
}
|
|
||||||
self.isRefreshing = false
|
|
||||||
}
|
}
|
||||||
|
self.isRefreshing = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,9 +10,8 @@ struct MainView: View {
|
|||||||
@State private var accounts = ["@user1", "@user2", "@user3"]
|
@State private var accounts = ["@user1", "@user2", "@user3"]
|
||||||
@State private var sheetType: ProfileTab.SheetType? = nil
|
@State private var sheetType: ProfileTab.SheetType? = nil
|
||||||
|
|
||||||
// Состояния для бокового меню
|
// Состояние для бокового меню
|
||||||
@State private var isSideMenuPresented = false
|
@State private var isSideMenuPresented = false
|
||||||
@State private var menuOffset: CGFloat = 0
|
|
||||||
|
|
||||||
private var tabTitle: String {
|
private var tabTitle: String {
|
||||||
switch selectedTab {
|
switch selectedTab {
|
||||||
@ -24,13 +23,9 @@ struct MainView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var menuWidth: CGFloat {
|
|
||||||
UIScreen.main.bounds.width * 0.8
|
|
||||||
}
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView {
|
NavigationView {
|
||||||
ZStack(alignment: .leading) { // Выравниваем ZStack по левому краю
|
ZStack {
|
||||||
// Основной контент
|
// Основной контент
|
||||||
VStack(spacing: 0) {
|
VStack(spacing: 0) {
|
||||||
TopBarView(
|
TopBarView(
|
||||||
@ -61,70 +56,35 @@ struct MainView: View {
|
|||||||
print("Create button tapped")
|
print("Create button tapped")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.frame(maxWidth: .infinity, maxHeight: .infinity) // Убедимся, что основной контент занимает все пространство
|
|
||||||
.ignoresSafeArea(edges: .bottom)
|
.ignoresSafeArea(edges: .bottom)
|
||||||
.navigationBarHidden(true)
|
.navigationBarHidden(true)
|
||||||
.sheet(item: $sheetType) { type in
|
.sheet(item: $sheetType) { type in
|
||||||
// ... sheet presentation logic
|
// ... sheet presentation logic
|
||||||
}
|
}
|
||||||
|
// Затемнение фона при открытом меню
|
||||||
// Затемнение и закрытие по тапу
|
.background(isSideMenuPresented ? Color.black.opacity(0.4) : Color.clear)
|
||||||
Color.black
|
.onTapGesture {
|
||||||
.opacity(Double(menuOffset / menuWidth) * 0.4)
|
if isSideMenuPresented {
|
||||||
.ignoresSafeArea()
|
withAnimation {
|
||||||
.onTapGesture {
|
|
||||||
withAnimation(.easeInOut) {
|
|
||||||
isSideMenuPresented = false
|
isSideMenuPresented = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.allowsHitTesting(menuOffset > 0)
|
}
|
||||||
|
|
||||||
// Боковое меню
|
// Боковое меню
|
||||||
SideMenuView(isPresented: $isSideMenuPresented)
|
if isSideMenuPresented {
|
||||||
.frame(width: menuWidth)
|
HStack {
|
||||||
.offset(x: -menuWidth + menuOffset) // Новая логика смещения
|
SideMenuView(isPresented: $isSideMenuPresented)
|
||||||
.ignoresSafeArea(edges: .vertical)
|
.frame(width: UIScreen.main.bounds.width * 0.8)
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
.ignoresSafeArea(edges: .vertical) // Игнорируем safe area
|
||||||
|
.transition(.move(edge: .leading))
|
||||||
|
.zIndex(1) // Убедимся, что меню поверх всего
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.gesture(
|
|
||||||
DragGesture()
|
|
||||||
.onChanged { gesture in
|
|
||||||
if !isSideMenuPresented && gesture.startLocation.x > 60 { return }
|
|
||||||
|
|
||||||
let translation = gesture.translation.width
|
|
||||||
|
|
||||||
// Определяем базовое смещение в зависимости от того, открыто меню или нет
|
|
||||||
let baseOffset = isSideMenuPresented ? menuWidth : 0
|
|
||||||
|
|
||||||
// Новое смещение — это база плюс текущий свайп
|
|
||||||
let newOffset = baseOffset + translation
|
|
||||||
|
|
||||||
// Жестко ограничиваем итоговое смещение между 0 и шириной меню
|
|
||||||
self.menuOffset = max(0, min(menuWidth, newOffset))
|
|
||||||
}
|
|
||||||
.onEnded { gesture in
|
|
||||||
if !isSideMenuPresented && gesture.startLocation.x > 60 { return }
|
|
||||||
|
|
||||||
let threshold = menuWidth * 0.4
|
|
||||||
|
|
||||||
withAnimation(.easeInOut) {
|
|
||||||
if self.menuOffset > threshold {
|
|
||||||
isSideMenuPresented = true
|
|
||||||
} else {
|
|
||||||
isSideMenuPresented = false
|
|
||||||
}
|
|
||||||
// Устанавливаем финальное смещение после анимации
|
|
||||||
self.menuOffset = isSideMenuPresented ? menuWidth : 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
.navigationViewStyle(StackNavigationViewStyle())
|
.navigationViewStyle(StackNavigationViewStyle())
|
||||||
.onChange(of: isSideMenuPresented) { presented in
|
|
||||||
// Плавная анимация при нажатии на кнопку, а не только при жесте
|
|
||||||
withAnimation(.easeInOut) {
|
|
||||||
menuOffset = presented ? menuWidth : 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,6 +92,5 @@ struct MainView_Previews: PreviewProvider {
|
|||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let mockViewModel = LoginViewModel()
|
let mockViewModel = LoginViewModel()
|
||||||
MainView(viewModel: mockViewModel)
|
MainView(viewModel: mockViewModel)
|
||||||
.environmentObject(ThemeManager())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,19 +19,37 @@ struct NewHomeTab: View {
|
|||||||
RefreshableScrollView(isRefreshing: $viewModel.isRefreshing, onRefresh: {
|
RefreshableScrollView(isRefreshing: $viewModel.isRefreshing, onRefresh: {
|
||||||
viewModel.refreshData()
|
viewModel.refreshData()
|
||||||
}) {
|
}) {
|
||||||
HStack(alignment: .top, spacing: 6) {
|
VStack {
|
||||||
LazyVStack(spacing: 6) {
|
HStack(alignment: .top, spacing: 6) {
|
||||||
ForEach(column1Posts) { post in
|
LazyVStack(spacing: 6) {
|
||||||
PostGridItem(post: post)
|
ForEach(column1Posts) { post in
|
||||||
|
PostGridItem(post: post)
|
||||||
|
.onAppear {
|
||||||
|
viewModel.loadMoreContentIfNeeded(currentItem: post)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LazyVStack(spacing: 6) {
|
||||||
|
ForEach(column2Posts) { post in
|
||||||
|
PostGridItem(post: post)
|
||||||
|
.onAppear {
|
||||||
|
viewModel.loadMoreContentIfNeeded(currentItem: post)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LazyVStack(spacing: 6) {
|
.padding(.horizontal, 4)
|
||||||
ForEach(column2Posts) { post in
|
|
||||||
PostGridItem(post: post)
|
if viewModel.isLoadingPage {
|
||||||
}
|
ProgressView()
|
||||||
|
} else if !viewModel.canLoadMorePages {
|
||||||
|
Text(":(")
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
.padding()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Spacer()
|
||||||
}
|
}
|
||||||
.padding(.horizontal, 4)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -67,6 +67,7 @@ struct ProfileTab: View {
|
|||||||
self.selectedPostData = (post, posts)
|
self.selectedPostData = (post, posts)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
Spacer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,6 +80,23 @@ struct ProfileTab: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// private func fetchData(isInitialLoad: Bool = false) {
|
||||||
|
// if isInitialLoad {
|
||||||
|
// isLoading = true
|
||||||
|
// } else {
|
||||||
|
// isRefreshing = true
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// PostService.shared.fetchAllPosts { fetchedPosts in
|
||||||
|
// self.allPosts = fetchedPosts
|
||||||
|
//
|
||||||
|
// if isInitialLoad {
|
||||||
|
// self.isLoading = false
|
||||||
|
// }
|
||||||
|
// self.isRefreshing = false
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
private func fetchData(isInitialLoad: Bool = false) {
|
private func fetchData(isInitialLoad: Bool = false) {
|
||||||
if isInitialLoad {
|
if isInitialLoad {
|
||||||
isLoading = true
|
isLoading = true
|
||||||
@ -86,14 +104,14 @@ struct ProfileTab: View {
|
|||||||
isRefreshing = true
|
isRefreshing = true
|
||||||
}
|
}
|
||||||
|
|
||||||
PostService.shared.fetchAllPosts { fetchedPosts in
|
// Временный код вместо PostService
|
||||||
self.allPosts = fetchedPosts
|
self.allPosts = [] // или сюда можно подставить мок-данные
|
||||||
|
|
||||||
if isInitialLoad {
|
// Сбрасываем индикаторы загрузки
|
||||||
self.isLoading = false
|
if isInitialLoad {
|
||||||
}
|
self.isLoading = false
|
||||||
self.isRefreshing = false
|
|
||||||
}
|
}
|
||||||
|
self.isRefreshing = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Шапка профиля
|
// MARK: - Шапка профиля
|
||||||
|
|||||||
@ -1,21 +1,78 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
// --- HELPER STRUCTS & EXTENSIONS ---
|
struct SideMenuView: View {
|
||||||
|
@Binding var isPresented: Bool
|
||||||
|
|
||||||
// Dummy data for the account list
|
var body: some View {
|
||||||
struct Account: Identifiable {
|
VStack(alignment: .leading, spacing: 0) {
|
||||||
let id = UUID()
|
// Header
|
||||||
let name: String
|
VStack(alignment: .leading) {
|
||||||
let username: String
|
Image(systemName: "person.circle.fill")
|
||||||
let isCurrent: Bool
|
.resizable()
|
||||||
}
|
.frame(width: 60, height: 60)
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
Text("Your Name")
|
||||||
|
.font(.title2).bold()
|
||||||
|
Text("@yourusername")
|
||||||
|
.font(.subheadline)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
}
|
||||||
|
.padding(20)
|
||||||
|
|
||||||
// Custom Transition for older Xcode versions
|
// Menu Items
|
||||||
extension AnyTransition {
|
ScrollView {
|
||||||
static var slideAndFade: AnyTransition {
|
VStack(alignment: .leading, spacing: 20) {
|
||||||
let insertion = AnyTransition.move(edge: .top).combined(with: .opacity)
|
// Section 1
|
||||||
let removal = AnyTransition.move(edge: .top).combined(with: .opacity)
|
VStack(alignment: .leading, spacing: 15) {
|
||||||
return .asymmetric(insertion: insertion, removal: removal)
|
SideMenuButton(icon: "person.2.fill", title: "People You May Like", action: {})
|
||||||
|
SideMenuButton(icon: "star.fill", title: "Fun Fest", action: {})
|
||||||
|
SideMenuButton(icon: "lightbulb.fill", title: "Creator Center", action: {})
|
||||||
|
}
|
||||||
|
|
||||||
|
Divider()
|
||||||
|
|
||||||
|
// Section 2
|
||||||
|
VStack(alignment: .leading, spacing: 15) {
|
||||||
|
Text("CATEGORY").font(.caption).foregroundColor(.secondary)
|
||||||
|
SideMenuButton(icon: "doc.text", title: "Drafts", action: {})
|
||||||
|
SideMenuButton(icon: "bubble.left", title: "My Comments", action: {})
|
||||||
|
SideMenuButton(icon: "clock", title: "History", action: {})
|
||||||
|
SideMenuButton(icon: "arrow.down.circle", title: "My Downloads", action: {})
|
||||||
|
}
|
||||||
|
|
||||||
|
Divider()
|
||||||
|
|
||||||
|
// Section 3
|
||||||
|
VStack(alignment: .leading, spacing: 15) {
|
||||||
|
Text("SERVICES").font(.caption).foregroundColor(.secondary)
|
||||||
|
SideMenuButton(icon: "shippingbox", title: "Orders", action: {})
|
||||||
|
SideMenuButton(icon: "cart", title: "Cart", action: {})
|
||||||
|
SideMenuButton(icon: "wallet.pass", title: "Wallet", action: {})
|
||||||
|
}
|
||||||
|
|
||||||
|
Divider()
|
||||||
|
|
||||||
|
// Section 4
|
||||||
|
VStack(alignment: .leading, spacing: 15) {
|
||||||
|
SideMenuButton(icon: "square.grid.2x2", title: "Applets", action: {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
// Footer
|
||||||
|
HStack(spacing: 20) {
|
||||||
|
Spacer()
|
||||||
|
SideMenuFooterButton(icon: "qrcode.viewfinder", title: "Scan", action: {})
|
||||||
|
SideMenuFooterButton(icon: "questionmark.circle", title: "Help Center", action: {})
|
||||||
|
SideMenuFooterButton(icon: "gear", title: "Settings", action: {})
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
.background(Color(UIColor.systemBackground))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +89,7 @@ struct SideMenuButton: View {
|
|||||||
.font(.title3)
|
.font(.title3)
|
||||||
.frame(width: 30)
|
.frame(width: 30)
|
||||||
Text(title)
|
Text(title)
|
||||||
.font(.subheadline)
|
.font(.headline)
|
||||||
}
|
}
|
||||||
.foregroundColor(.primary)
|
.foregroundColor(.primary)
|
||||||
.padding(.vertical, 8)
|
.padding(.vertical, 8)
|
||||||
@ -51,209 +108,9 @@ struct SideMenuFooterButton: View {
|
|||||||
Image(systemName: icon)
|
Image(systemName: icon)
|
||||||
.font(.title2)
|
.font(.title2)
|
||||||
Text(title)
|
Text(title)
|
||||||
.font(.caption2)
|
.font(.caption)
|
||||||
}
|
}
|
||||||
.foregroundColor(.primary)
|
.foregroundColor(.primary)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --- MAIN VIEW ---
|
|
||||||
|
|
||||||
struct SideMenuView: View {
|
|
||||||
@EnvironmentObject var themeManager: ThemeManager
|
|
||||||
@Environment(\.colorScheme) var colorScheme
|
|
||||||
@Binding var isPresented: Bool
|
|
||||||
@State private var isAccountListExpanded = false
|
|
||||||
|
|
||||||
// Adjustable paddings
|
|
||||||
private let topPadding: CGFloat = 66
|
|
||||||
private let bottomPadding: CGFloat = 34
|
|
||||||
|
|
||||||
// Dummy account data
|
|
||||||
private let accounts: [Account] = [
|
|
||||||
Account(name: "Your Name", username: "@yourusername", isCurrent: true),
|
|
||||||
Account(name: "Second Account", username: "@second", isCurrent: false),
|
|
||||||
Account(name: "Another One", username: "@another", isCurrent: false),
|
|
||||||
Account(name: "Test User", username: "@test", isCurrent: false),
|
|
||||||
Account(name: "Creative Profile", username: "@creative", isCurrent: false)
|
|
||||||
]
|
|
||||||
|
|
||||||
private var themeToggleButton: some View {
|
|
||||||
Button(action: {
|
|
||||||
themeManager.toggleTheme(from: colorScheme)
|
|
||||||
}) {
|
|
||||||
Image(systemName: iconName)
|
|
||||||
.font(.title2)
|
|
||||||
.foregroundColor(.primary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private var iconName: String {
|
|
||||||
let effectiveScheme: ColorScheme
|
|
||||||
switch themeManager.theme {
|
|
||||||
case .system:
|
|
||||||
effectiveScheme = colorScheme
|
|
||||||
case .light:
|
|
||||||
effectiveScheme = .light
|
|
||||||
case .dark:
|
|
||||||
effectiveScheme = .dark
|
|
||||||
}
|
|
||||||
|
|
||||||
return effectiveScheme == .dark ? "sun.max.fill" : "moon.fill"
|
|
||||||
}
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
VStack(alignment: .leading, spacing: 0) {
|
|
||||||
ScrollView {
|
|
||||||
VStack(alignment: .leading, spacing: 0) { // Parent VStack
|
|
||||||
|
|
||||||
// --- Header ---
|
|
||||||
HStack(alignment: .top) {
|
|
||||||
Button(action: { }) {
|
|
||||||
Image(systemName: "person.circle.fill")
|
|
||||||
.resizable()
|
|
||||||
.frame(width: 60, height: 60)
|
|
||||||
.foregroundColor(.gray)
|
|
||||||
}
|
|
||||||
Spacer()
|
|
||||||
themeToggleButton
|
|
||||||
}
|
|
||||||
.padding(.horizontal, 20)
|
|
||||||
.padding(.top, topPadding)
|
|
||||||
.padding(.bottom, 10)
|
|
||||||
|
|
||||||
// --- Header Button ---
|
|
||||||
Button(action: {
|
|
||||||
withAnimation(.spring()) {
|
|
||||||
isAccountListExpanded.toggle()
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
HStack {
|
|
||||||
VStack(alignment: .leading) {
|
|
||||||
Text("Your Name")
|
|
||||||
.font(.title3).bold()
|
|
||||||
Text("@yourusername")
|
|
||||||
.font(.footnote)
|
|
||||||
}
|
|
||||||
.foregroundColor(.primary)
|
|
||||||
|
|
||||||
Spacer()
|
|
||||||
|
|
||||||
Image(systemName: isAccountListExpanded ? "chevron.up" : "chevron.down")
|
|
||||||
.font(.headline)
|
|
||||||
.foregroundColor(.secondary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding(.horizontal, 20)
|
|
||||||
.padding(.bottom, 10)
|
|
||||||
|
|
||||||
// --- Collapsible Account List in a clipped container ---
|
|
||||||
VStack {
|
|
||||||
if isAccountListExpanded {
|
|
||||||
VStack(alignment: .leading, spacing: 15) {
|
|
||||||
ForEach(accounts) { account in
|
|
||||||
HStack {
|
|
||||||
Button(action: { }) {
|
|
||||||
ZStack {
|
|
||||||
Image(systemName: "person.circle.fill")
|
|
||||||
.resizable()
|
|
||||||
.frame(width: 32, height: 32) // Smaller icon
|
|
||||||
.foregroundColor(.secondary)
|
|
||||||
|
|
||||||
if account.isCurrent {
|
|
||||||
Image(systemName: "checkmark.circle.fill")
|
|
||||||
.foregroundColor(.blue)
|
|
||||||
.background(Circle().fill(Color(UIColor.systemBackground)))
|
|
||||||
.font(.body) // Smaller checkmark
|
|
||||||
.offset(x: 11, y: 11) // Adjusted offset
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VStack(alignment: .leading) {
|
|
||||||
Text(account.name).font(.footnote).bold() // Smaller text
|
|
||||||
Text(account.username).font(.caption2) // Smaller text
|
|
||||||
}
|
|
||||||
.foregroundColor(.primary)
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding(.horizontal, 20)
|
|
||||||
.padding(.vertical, 10)
|
|
||||||
.transition(.slideAndFade)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.clipped()
|
|
||||||
|
|
||||||
// Menu Items
|
|
||||||
VStack(alignment: .leading, spacing: 20) {
|
|
||||||
// Section 1
|
|
||||||
VStack(alignment: .leading, spacing: 7) {
|
|
||||||
SideMenuButton(icon: "person.2.fill", title: "People You May Like", action: {})
|
|
||||||
SideMenuButton(icon: "star.fill", title: "Fun Fest", action: {})
|
|
||||||
SideMenuButton(icon: "lightbulb.fill", title: "Creator Center", action: {})
|
|
||||||
}
|
|
||||||
|
|
||||||
Divider()
|
|
||||||
|
|
||||||
// Section 2
|
|
||||||
VStack(alignment: .leading, spacing: 7) {
|
|
||||||
Text("CATEGORY").font(.caption2).foregroundColor(.secondary)
|
|
||||||
SideMenuButton(icon: "doc.text", title: "Drafts", action: {})
|
|
||||||
SideMenuButton(icon: "bubble.left", title: "My Comments", action: {})
|
|
||||||
SideMenuButton(icon: "clock", title: "History", action: {})
|
|
||||||
SideMenuButton(icon: "arrow.down.circle", title: "My Downloads", action: {})
|
|
||||||
}
|
|
||||||
|
|
||||||
Divider()
|
|
||||||
|
|
||||||
// Section 3
|
|
||||||
VStack(alignment: .leading, spacing: 7) {
|
|
||||||
Text("SERVICES").font(.caption2).foregroundColor(.secondary)
|
|
||||||
SideMenuButton(icon: "shippingbox", title: "Orders", action: {})
|
|
||||||
SideMenuButton(icon: "cart", title: "Cart", action: {})
|
|
||||||
SideMenuButton(icon: "wallet.pass", title: "Wallet", action: {})
|
|
||||||
}
|
|
||||||
|
|
||||||
Divider()
|
|
||||||
|
|
||||||
// Section 4
|
|
||||||
VStack(alignment: .leading, spacing: 15) {
|
|
||||||
SideMenuButton(icon: "square.grid.2x2", title: "Applets", action: {})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding()
|
|
||||||
}
|
|
||||||
.frame(maxWidth: .infinity, alignment: .leading) // Align to the left
|
|
||||||
}
|
|
||||||
.clipped()
|
|
||||||
|
|
||||||
Spacer()
|
|
||||||
|
|
||||||
// Footer
|
|
||||||
HStack(spacing: 20) {
|
|
||||||
Spacer()
|
|
||||||
SideMenuFooterButton(icon: "qrcode.viewfinder", title: "Scan", action: {})
|
|
||||||
SideMenuFooterButton(icon: "questionmark.circle", title: "Help Center", action: {})
|
|
||||||
SideMenuFooterButton(icon: "gear", title: "Settings", action: {})
|
|
||||||
Spacer()
|
|
||||||
}
|
|
||||||
.padding()
|
|
||||||
.padding(.bottom, bottomPadding)
|
|
||||||
}
|
|
||||||
.background(Color(UIColor.systemBackground))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- PREVIEW ---
|
|
||||||
|
|
||||||
struct SideMenuView_Previews: PreviewProvider {
|
|
||||||
static var previews: some View {
|
|
||||||
SideMenuView(isPresented: .constant(true))
|
|
||||||
.environmentObject(ThemeManager())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -7,24 +7,31 @@
|
|||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
|
//@AppStorage("isLoggedIn") var isLoggedIn: Bool = false
|
||||||
|
//@AppStorage("isDarkMode") private var isDarkMode: Bool = false
|
||||||
|
//@AppStorage("currentUser") var currentUser: String = ""
|
||||||
|
|
||||||
@main
|
@main
|
||||||
struct volnahubApp: App {
|
struct volnahubApp: App {
|
||||||
@StateObject private var themeManager = ThemeManager()
|
@AppStorage("isDarkMode") private var isDarkMode: Bool = true
|
||||||
@StateObject private var viewModel = LoginViewModel()
|
@StateObject private var viewModel = LoginViewModel()
|
||||||
|
|
||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
WindowGroup {
|
WindowGroup {
|
||||||
Group {
|
ZStack {
|
||||||
if viewModel.isLoading {
|
Color(isDarkMode ? .black : .white) // ✅ Фон в зависимости от темы
|
||||||
|
|
||||||
|
if viewModel.isLoading{
|
||||||
SplashScreenView()
|
SplashScreenView()
|
||||||
} else if viewModel.isLoggedIn {
|
}else{
|
||||||
MainView(viewModel: viewModel)
|
if viewModel.isLoggedIn {
|
||||||
} else {
|
MainView(viewModel: viewModel)
|
||||||
LoginView(viewModel: viewModel)
|
} else {
|
||||||
|
LoginView(viewModel: viewModel)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.environmentObject(themeManager)
|
.preferredColorScheme(isDarkMode ? .dark : .light)
|
||||||
.preferredColorScheme(themeManager.theme.colorScheme)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,7 +36,6 @@
|
|||||||
1A9B01662E4BFA3600887E0B /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1A9B01652E4BFA3600887E0B /* Media.xcassets */; };
|
1A9B01662E4BFA3600887E0B /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1A9B01652E4BFA3600887E0B /* Media.xcassets */; };
|
||||||
1A9B016E2E4BFB9000887E0B /* NewHomeTabViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A9B016D2E4BFB9000887E0B /* NewHomeTabViewModel.swift */; };
|
1A9B016E2E4BFB9000887E0B /* NewHomeTabViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A9B016D2E4BFB9000887E0B /* NewHomeTabViewModel.swift */; };
|
||||||
1A9B017C2E4C087F00887E0B /* SideMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A9B017B2E4C087F00887E0B /* SideMenuView.swift */; };
|
1A9B017C2E4C087F00887E0B /* SideMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A9B017B2E4C087F00887E0B /* SideMenuView.swift */; };
|
||||||
1A9E4FB32E4D6A67002249D6 /* ThemeManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A9E4FB22E4D6A67002249D6 /* ThemeManager.swift */; };
|
|
||||||
1AB4F8CD2E22E341002B6E40 /* AccountShareSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AB4F8CC2E22E341002B6E40 /* AccountShareSheet.swift */; };
|
1AB4F8CD2E22E341002B6E40 /* AccountShareSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AB4F8CC2E22E341002B6E40 /* AccountShareSheet.swift */; };
|
||||||
1AB4F8F32E22EC9F002B6E40 /* FollowersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AB4F8F22E22EC9F002B6E40 /* FollowersView.swift */; };
|
1AB4F8F32E22EC9F002B6E40 /* FollowersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AB4F8F22E22EC9F002B6E40 /* FollowersView.swift */; };
|
||||||
1AB4F8F72E22ECAC002B6E40 /* FollowingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AB4F8F62E22ECAC002B6E40 /* FollowingView.swift */; };
|
1AB4F8F72E22ECAC002B6E40 /* FollowingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AB4F8F62E22ECAC002B6E40 /* FollowingView.swift */; };
|
||||||
@ -91,7 +90,6 @@
|
|||||||
1A9B01652E4BFA3600887E0B /* Media.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Media.xcassets; sourceTree = "<group>"; };
|
1A9B01652E4BFA3600887E0B /* Media.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Media.xcassets; sourceTree = "<group>"; };
|
||||||
1A9B016D2E4BFB9000887E0B /* NewHomeTabViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NewHomeTabViewModel.swift; sourceTree = "<group>"; };
|
1A9B016D2E4BFB9000887E0B /* NewHomeTabViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NewHomeTabViewModel.swift; sourceTree = "<group>"; };
|
||||||
1A9B017B2E4C087F00887E0B /* SideMenuView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SideMenuView.swift; sourceTree = "<group>"; };
|
1A9B017B2E4C087F00887E0B /* SideMenuView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SideMenuView.swift; sourceTree = "<group>"; };
|
||||||
1A9E4FB22E4D6A67002249D6 /* ThemeManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ThemeManager.swift; sourceTree = "<group>"; };
|
|
||||||
1AB4F8CC2E22E341002B6E40 /* AccountShareSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountShareSheet.swift; sourceTree = "<group>"; };
|
1AB4F8CC2E22E341002B6E40 /* AccountShareSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountShareSheet.swift; sourceTree = "<group>"; };
|
||||||
1AB4F8F22E22EC9F002B6E40 /* FollowersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FollowersView.swift; sourceTree = "<group>"; };
|
1AB4F8F22E22EC9F002B6E40 /* FollowersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FollowersView.swift; sourceTree = "<group>"; };
|
||||||
1AB4F8F62E22ECAC002B6E40 /* FollowingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FollowingView.swift; sourceTree = "<group>"; };
|
1AB4F8F62E22ECAC002B6E40 /* FollowingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FollowingView.swift; sourceTree = "<group>"; };
|
||||||
@ -229,7 +227,6 @@
|
|||||||
1A7940E52DF7B341002569DA /* Services */ = {
|
1A7940E52DF7B341002569DA /* Services */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
1A9E4FB22E4D6A67002249D6 /* ThemeManager.swift */,
|
|
||||||
1A7940E12DF7B1C5002569DA /* KeychainService.swift */,
|
1A7940E12DF7B1C5002569DA /* KeychainService.swift */,
|
||||||
);
|
);
|
||||||
path = Services;
|
path = Services;
|
||||||
@ -453,7 +450,6 @@
|
|||||||
1A7940E22DF7B1C5002569DA /* KeychainService.swift in Sources */,
|
1A7940E22DF7B1C5002569DA /* KeychainService.swift in Sources */,
|
||||||
1A7940A62DF77DF5002569DA /* User.swift in Sources */,
|
1A7940A62DF77DF5002569DA /* User.swift in Sources */,
|
||||||
1A7940A22DF77DE9002569DA /* AuthService.swift in Sources */,
|
1A7940A22DF77DE9002569DA /* AuthService.swift in Sources */,
|
||||||
1A9E4FB32E4D6A67002249D6 /* ThemeManager.swift in Sources */,
|
|
||||||
1AEE5EB32E21A85800A3DCA3 /* SearchTab.swift in Sources */,
|
1AEE5EB32E21A85800A3DCA3 /* SearchTab.swift in Sources */,
|
||||||
1ACE61152E22FE2000B37AC5 /* PostDetailView.swift in Sources */,
|
1ACE61152E22FE2000B37AC5 /* PostDetailView.swift in Sources */,
|
||||||
1ACE61192E22FF1400B37AC5 /* Post.swift in Sources */,
|
1ACE61192E22FF1400B37AC5 /* Post.swift in Sources */,
|
||||||
|
|||||||
Reference in New Issue
Block a user