修改跳转的逻辑

This commit is contained in:
anlicheng 2025-06-30 17:32:23 +08:00
parent b11362b912
commit 72d73f9a2f
4 changed files with 31 additions and 32 deletions

View File

@ -23,4 +23,25 @@ final class AppNavigation: ObservableObject {
path.append(dest)
}
func handleNotification(_ userInfo: [AnyHashable: Any]) {
print(userInfo)
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 {
path.append(Destination.detail(id: dramaId))
}
default:
()
}
}
}
}

View File

@ -29,7 +29,6 @@ struct SearchBar: View {
if !searchText.isEmpty {
doSearch()
isFirstResponder = false
print("isFirstResponder is set false")
}
} label: {
Text("搜索")
@ -71,7 +70,6 @@ struct ControlledTextField: UIViewRepresentable {
uiView.text = text
context.coordinator.isUpdatingFromBinding = false
}
print("call me update UIView: \(isFirstResponder)")
// 2.
if isFirstResponder {
@ -113,12 +111,16 @@ struct ControlledTextField: UIViewRepresentable {
//
func textFieldDidEndEditing(_ textField: UITextField, reason: UITextField.DidEndEditingReason) {
self.isFirstResponder = false
DispatchQueue.main.async {
self.isFirstResponder = false
}
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
onCommit()
self.isFirstResponder = false
DispatchQueue.main.async {
self.isFirstResponder = false
}
return true
}

View File

@ -19,13 +19,9 @@ struct SearchView: View {
//
@State private var showSearchResult: Bool = false
//
@State private var showKeyboard: Bool = true
@State private var toolbarID = UUID()
//
@State private var toolbarID = UUID()
@State private var isFocused: Bool = true
var body: some View {
@ -69,16 +65,13 @@ struct SearchView: View {
SearchBar(isFirstResponder: $isFocused, searchText: $searchText) {
doSearch()
}
.frame(width: UIScreen.main.bounds.width * 0.8)
.id(toolbarID)
.onAppear {
print("searchBar appear")
}
}
}
.padding(.horizontal, 12)
.ignoresSafeArea(.keyboard, edges: .bottom) //
.onAppear {
print("main appear")
toolbarID = UUID()
}
}
@ -94,9 +87,6 @@ struct SearchView: View {
}
}
//
self.showKeyboard = false
//
// let history = SearchHistory(keyword: trimmed, timestamp: Date())
// modelContext.insert(history)

View File

@ -12,7 +12,7 @@ import Observation
@main
struct dimensionhubApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@StateObject var appNav = AppNavigation()
@StateObject var appNav = AppNavigation.shared
var sharedModelContainer: ModelContainer = {
let schema = Schema([
@ -167,22 +167,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
}
// MARK:
private func handleRemoteNotification(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
}
switch target {
case "detail":
if let dramaId = params["drama_id"] as? Int {
AppNavigation.shared.append(dest: .detail(id: dramaId))
}
default:
()
}
AppNavigation.shared.handleNotification(userInfo)
}
private func handleDeepLink(_ link: String) {