fix indexView
This commit is contained in:
parent
22b74a9b36
commit
d00703f8c5
26
dimensionhub/Core/AppNavigation.swift
Normal file
26
dimensionhub/Core/AppNavigation.swift
Normal file
@ -0,0 +1,26 @@
|
||||
//
|
||||
// AppNavigation.swift
|
||||
// dimensionhub
|
||||
//
|
||||
// Created by 安礼成 on 2025/4/9.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
final class AppNavigation: ObservableObject {
|
||||
static var shared = AppNavigation()
|
||||
|
||||
enum Destination: Hashable {
|
||||
case detail(id: Int)
|
||||
case followList
|
||||
case search
|
||||
}
|
||||
|
||||
@Published var path = NavigationPath()
|
||||
|
||||
func append(dest: Destination) {
|
||||
path.append(dest)
|
||||
}
|
||||
|
||||
}
|
||||
@ -10,6 +10,7 @@ import Refresh
|
||||
// 首页的主要窗口
|
||||
struct IndexMainView: View {
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
@EnvironmentObject var appNavigation: AppNavigation
|
||||
@AppStorage("userId") private var userId: String = Utils.defaultUserId()
|
||||
|
||||
@State var indexModel = IndexModel()
|
||||
@ -31,26 +32,26 @@ struct IndexMainView: View {
|
||||
VStack(alignment: .center) {
|
||||
|
||||
HStack(alignment: .center) {
|
||||
Color.clear
|
||||
.overlay {
|
||||
HStack(alignment: .center) {
|
||||
Text("亚次元")
|
||||
.font(.system(size: 18, weight: .bold))
|
||||
.padding([.top, .bottom], 5)
|
||||
Spacer()
|
||||
|
||||
NavigationLink(destination: FollowListView()) {
|
||||
HStack {
|
||||
Text("♡ \(indexModel.follow_num)")
|
||||
.font(.system(size: 17))
|
||||
.foregroundColor(.black)
|
||||
.padding([.top, .bottom], 5)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding([.leading, .trailing], 15)
|
||||
Text("亚次元")
|
||||
.font(.system(size: 18, weight: .bold))
|
||||
.padding([.top, .bottom], 5)
|
||||
Spacer()
|
||||
|
||||
Button(action: {
|
||||
appNavigation.append(dest: .followList)
|
||||
}) {
|
||||
HStack {
|
||||
Text("♡ \(indexModel.follow_num)")
|
||||
.font(.system(size: 17))
|
||||
.foregroundColor(.black)
|
||||
.padding([.top, .bottom], 5)
|
||||
.padding(.leading, 10)
|
||||
}
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.zIndex(1)
|
||||
}
|
||||
.padding([.leading, .trailing], 15)
|
||||
.frame(height: 50)
|
||||
.background(Color(hex: "#F2F2F2"), ignoresSafeAreaEdges: .top)
|
||||
|
||||
@ -71,6 +72,9 @@ struct IndexMainView: View {
|
||||
ProgressView()
|
||||
}
|
||||
|
||||
Rectangle()
|
||||
.frame(width: 0, height: 15)
|
||||
|
||||
// 基于日期的更新列表
|
||||
LazyVStack(alignment: .center, spacing: 10) {
|
||||
ForEach(indexModel.updateDramaGroups, id: \.group_id) { group in
|
||||
@ -104,13 +108,13 @@ struct IndexMainView: View {
|
||||
.coordinateSpace(name: "indexScrollView")
|
||||
.overlay(alignment: .topTrailing) {
|
||||
HStack(alignment: .center) {
|
||||
NavigationLink {
|
||||
SearchView()
|
||||
} label: {
|
||||
Button(action: {
|
||||
appNavigation.append(dest: .search)
|
||||
}) {
|
||||
Image(systemName: "magnifyingglass")
|
||||
.font(.system(size: 20))
|
||||
}
|
||||
|
||||
|
||||
Spacer()
|
||||
if let fixedDramaGroup = indexModel.fixedDramaGroup {
|
||||
Text(fixedDramaGroup.group_name)
|
||||
@ -151,8 +155,11 @@ struct IndexMainView: View {
|
||||
}
|
||||
|
||||
extension IndexMainView {
|
||||
|
||||
// 显示分组信息
|
||||
struct DramaGroupView: View {
|
||||
@EnvironmentObject var appNav: AppNavigation
|
||||
|
||||
let group: IndexModel.UpdateDramaGroup
|
||||
let model: IndexModel
|
||||
|
||||
@ -171,7 +178,9 @@ extension IndexMainView {
|
||||
}
|
||||
|
||||
ForEach(group.items, id: \.id) { item in
|
||||
NavigationLink(destination: DetailView(id: item.id)) {
|
||||
Button(action: {
|
||||
appNav.append(dest: .detail(id: item.id))
|
||||
}) {
|
||||
AsyncImage(url: URL(string: item.thumb)) { phase in
|
||||
switch phase {
|
||||
case .empty:
|
||||
|
||||
@ -12,7 +12,7 @@ import Observation
|
||||
@main
|
||||
struct dimensionhubApp: App {
|
||||
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
|
||||
@State var appNav = AppNavigation.shared
|
||||
@StateObject var appNav = AppNavigation()
|
||||
|
||||
var sharedModelContainer: ModelContainer = {
|
||||
let schema = Schema([
|
||||
@ -48,11 +48,16 @@ struct dimensionhubApp: App {
|
||||
switch dest {
|
||||
case .detail(id: let id):
|
||||
DetailView(id: id)
|
||||
case .followList:
|
||||
FollowListView()
|
||||
case .search:
|
||||
SearchView()
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationViewStyle(.stack)
|
||||
.tint(.black)
|
||||
.environmentObject(appNav)
|
||||
}
|
||||
.modelContainer(sharedModelContainer)
|
||||
}
|
||||
@ -167,7 +172,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
||||
private func handleRemoteNotification(userInfo: [AnyHashable: Any]) {
|
||||
if let customData = userInfo["custom_data"] as? [String: AnyObject],
|
||||
let dramaId = customData["drama_id"] as? Int {
|
||||
AppNavigation.shared.path.append(AppNavigation.Destination.detail(id: dramaId))
|
||||
AppNavigation.shared.append(dest: .detail(id: dramaId))
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,18 +183,3 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Observable
|
||||
final class AppNavigation {
|
||||
static var shared = AppNavigation()
|
||||
|
||||
enum Destination: Hashable {
|
||||
case detail(id: Int)
|
||||
}
|
||||
|
||||
private init() {
|
||||
|
||||
}
|
||||
|
||||
var path = NavigationPath()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user