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 {
|
struct IndexMainView: View {
|
||||||
@Environment(\.modelContext) private var modelContext
|
@Environment(\.modelContext) private var modelContext
|
||||||
|
@EnvironmentObject var appNavigation: AppNavigation
|
||||||
@AppStorage("userId") private var userId: String = Utils.defaultUserId()
|
@AppStorage("userId") private var userId: String = Utils.defaultUserId()
|
||||||
|
|
||||||
@State var indexModel = IndexModel()
|
@State var indexModel = IndexModel()
|
||||||
@ -31,26 +32,26 @@ struct IndexMainView: View {
|
|||||||
VStack(alignment: .center) {
|
VStack(alignment: .center) {
|
||||||
|
|
||||||
HStack(alignment: .center) {
|
HStack(alignment: .center) {
|
||||||
Color.clear
|
Text("亚次元")
|
||||||
.overlay {
|
.font(.system(size: 18, weight: .bold))
|
||||||
HStack(alignment: .center) {
|
.padding([.top, .bottom], 5)
|
||||||
Text("亚次元")
|
Spacer()
|
||||||
.font(.system(size: 18, weight: .bold))
|
|
||||||
.padding([.top, .bottom], 5)
|
Button(action: {
|
||||||
Spacer()
|
appNavigation.append(dest: .followList)
|
||||||
|
}) {
|
||||||
NavigationLink(destination: FollowListView()) {
|
HStack {
|
||||||
HStack {
|
Text("♡ \(indexModel.follow_num)")
|
||||||
Text("♡ \(indexModel.follow_num)")
|
.font(.system(size: 17))
|
||||||
.font(.system(size: 17))
|
.foregroundColor(.black)
|
||||||
.foregroundColor(.black)
|
.padding([.top, .bottom], 5)
|
||||||
.padding([.top, .bottom], 5)
|
.padding(.leading, 10)
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding([.leading, .trailing], 15)
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
.contentShape(Rectangle())
|
||||||
|
.zIndex(1)
|
||||||
}
|
}
|
||||||
|
.padding([.leading, .trailing], 15)
|
||||||
.frame(height: 50)
|
.frame(height: 50)
|
||||||
.background(Color(hex: "#F2F2F2"), ignoresSafeAreaEdges: .top)
|
.background(Color(hex: "#F2F2F2"), ignoresSafeAreaEdges: .top)
|
||||||
|
|
||||||
@ -71,6 +72,9 @@ struct IndexMainView: View {
|
|||||||
ProgressView()
|
ProgressView()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rectangle()
|
||||||
|
.frame(width: 0, height: 15)
|
||||||
|
|
||||||
// 基于日期的更新列表
|
// 基于日期的更新列表
|
||||||
LazyVStack(alignment: .center, spacing: 10) {
|
LazyVStack(alignment: .center, spacing: 10) {
|
||||||
ForEach(indexModel.updateDramaGroups, id: \.group_id) { group in
|
ForEach(indexModel.updateDramaGroups, id: \.group_id) { group in
|
||||||
@ -104,13 +108,13 @@ struct IndexMainView: View {
|
|||||||
.coordinateSpace(name: "indexScrollView")
|
.coordinateSpace(name: "indexScrollView")
|
||||||
.overlay(alignment: .topTrailing) {
|
.overlay(alignment: .topTrailing) {
|
||||||
HStack(alignment: .center) {
|
HStack(alignment: .center) {
|
||||||
NavigationLink {
|
Button(action: {
|
||||||
SearchView()
|
appNavigation.append(dest: .search)
|
||||||
} label: {
|
}) {
|
||||||
Image(systemName: "magnifyingglass")
|
Image(systemName: "magnifyingglass")
|
||||||
.font(.system(size: 20))
|
.font(.system(size: 20))
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
if let fixedDramaGroup = indexModel.fixedDramaGroup {
|
if let fixedDramaGroup = indexModel.fixedDramaGroup {
|
||||||
Text(fixedDramaGroup.group_name)
|
Text(fixedDramaGroup.group_name)
|
||||||
@ -151,8 +155,11 @@ struct IndexMainView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension IndexMainView {
|
extension IndexMainView {
|
||||||
|
|
||||||
// 显示分组信息
|
// 显示分组信息
|
||||||
struct DramaGroupView: View {
|
struct DramaGroupView: View {
|
||||||
|
@EnvironmentObject var appNav: AppNavigation
|
||||||
|
|
||||||
let group: IndexModel.UpdateDramaGroup
|
let group: IndexModel.UpdateDramaGroup
|
||||||
let model: IndexModel
|
let model: IndexModel
|
||||||
|
|
||||||
@ -171,7 +178,9 @@ extension IndexMainView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ForEach(group.items, id: \.id) { item in
|
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
|
AsyncImage(url: URL(string: item.thumb)) { phase in
|
||||||
switch phase {
|
switch phase {
|
||||||
case .empty:
|
case .empty:
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import Observation
|
|||||||
@main
|
@main
|
||||||
struct dimensionhubApp: App {
|
struct dimensionhubApp: App {
|
||||||
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
|
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
|
||||||
@State var appNav = AppNavigation.shared
|
@StateObject var appNav = AppNavigation()
|
||||||
|
|
||||||
var sharedModelContainer: ModelContainer = {
|
var sharedModelContainer: ModelContainer = {
|
||||||
let schema = Schema([
|
let schema = Schema([
|
||||||
@ -48,11 +48,16 @@ struct dimensionhubApp: App {
|
|||||||
switch dest {
|
switch dest {
|
||||||
case .detail(id: let id):
|
case .detail(id: let id):
|
||||||
DetailView(id: id)
|
DetailView(id: id)
|
||||||
|
case .followList:
|
||||||
|
FollowListView()
|
||||||
|
case .search:
|
||||||
|
SearchView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.navigationViewStyle(.stack)
|
.navigationViewStyle(.stack)
|
||||||
.tint(.black)
|
.tint(.black)
|
||||||
|
.environmentObject(appNav)
|
||||||
}
|
}
|
||||||
.modelContainer(sharedModelContainer)
|
.modelContainer(sharedModelContainer)
|
||||||
}
|
}
|
||||||
@ -167,7 +172,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
|||||||
private func handleRemoteNotification(userInfo: [AnyHashable: Any]) {
|
private func handleRemoteNotification(userInfo: [AnyHashable: Any]) {
|
||||||
if let customData = userInfo["custom_data"] as? [String: AnyObject],
|
if let customData = userInfo["custom_data"] as? [String: AnyObject],
|
||||||
let dramaId = customData["drama_id"] as? Int {
|
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