50 lines
1.2 KiB
Swift
50 lines
1.2 KiB
Swift
//
|
|
// 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()
|
|
|
|
@Published var targetDetailId: Int = 0
|
|
|
|
func append(dest: Destination) {
|
|
path.append(dest)
|
|
}
|
|
|
|
func handleNotification(_ userInfo: [AnyHashable: Any]) {
|
|
guard let customData = userInfo["custom_data"] as? [String: AnyObject],
|
|
let target = customData["target"] as? String,
|
|
let params = customData["params"] as? [String : AnyObject] else {
|
|
return
|
|
}
|
|
|
|
path = NavigationPath()
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [self] in
|
|
switch target {
|
|
case "detail":
|
|
if let dramaId = params["drama_id"] as? Int {
|
|
self.targetDetailId = dramaId
|
|
}
|
|
default:
|
|
()
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|