fix index view

This commit is contained in:
anlicheng 2025-04-01 11:27:13 +08:00
parent 7255bb3c5a
commit a9d306225a
4 changed files with 64 additions and 15 deletions

View File

@ -420,8 +420,7 @@
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 17.6; IPHONEOS_DEPLOYMENT_TARGET = 17.6;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
@ -455,8 +454,7 @@
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 17.6; IPHONEOS_DEPLOYMENT_TARGET = 17.6;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",

View File

@ -84,6 +84,13 @@ final class IndexModel {
self.isLoaded = true self.isLoaded = true
} }
func setFixedDrameGroup(groupId: String) {
if let newFixedDramaGroup = self.updateDramaGroups.first(where: {$0.group_id == groupId}),
newFixedDramaGroup.group_id != self.fixedDramaGroup?.group_id {
self.fixedDramaGroup = newFixedDramaGroup
}
}
@MainActor @MainActor
func loadMoreUpdateDramas(userId: String, mode: API.LoadMode) async { func loadMoreUpdateDramas(userId: String, mode: API.LoadMode) async {
// id // id
@ -132,6 +139,7 @@ final class IndexModel {
let response = await API.loadDateUpdateDramas(userId: userId, date: date, as: [UpdateDramaGroup].self) let response = await API.loadDateUpdateDramas(userId: userId, date: date, as: [UpdateDramaGroup].self)
if case let .result(groups) = response { if case let .result(groups) = response {
self.updateDramaGroups = groups self.updateDramaGroups = groups
self.fixedDramaGroup = groups.first
} }
} }
@ -379,8 +387,14 @@ extension IndexView {
self.isPrevLoading = false self.isPrevLoading = false
} }
.overlay(alignment: .topTrailing) { .overlay(alignment: .topTrailing) {
HStack { HStack(alignment: .center) {
Text("🔍") NavigationLink {
SearchView()
} label: {
Image(systemName: "magnifyingglass")
.font(.system(size: 20))
}
Spacer() Spacer()
if let fixedDramaGroup = indexModel.fixedDramaGroup { if let fixedDramaGroup = indexModel.fixedDramaGroup {
Text(fixedDramaGroup.group_name) Text(fixedDramaGroup.group_name)
@ -393,7 +407,7 @@ extension IndexView {
} }
} }
} }
.padding(8) .padding([.top, .bottom], 8)
.background(.white) .background(.white)
} }
} }
@ -411,6 +425,12 @@ extension IndexView {
.task { .task {
await self.indexModel.loadData(userId: self.userId) await self.indexModel.loadData(userId: self.userId)
} }
.onPreferenceChange(DramaGroupElementPreferenceKey.self) { frames in
let visibleFrames = frames.filter { $0.value >= 0}
if let minFrame = visibleFrames.min(by: { $0.value <= $1.value}) {
indexModel.setFixedDrameGroup(groupId: minFrame.key)
}
}
} }
} }
@ -432,14 +452,6 @@ extension IndexView {
onTap() onTap()
} }
} }
.background(GeometryReader {
geometry in
Color.clear.onChange(of: geometry.frame(in: .named("indexScrollView")).minY) {_, y in
if abs(y) <= 5 {
model.fixedDramaGroup = group
}
}
})
ForEach(group.items, id: \.id) { item in ForEach(group.items, id: \.id) { item in
NavigationLink(destination: DetailView(id: item.id)) { NavigationLink(destination: DetailView(id: item.id)) {
@ -481,12 +493,32 @@ extension IndexView {
.cornerRadius(5) .cornerRadius(5)
.padding(8) .padding(8)
} }
.background(GeometryReader {
geometry in
let height = geometry.size.height
let minY = geometry.frame(in: .named("indexScrollView")).minY
let y = minY >= 0 ? minY : minY + height
Color.clear
.preference(key: DramaGroupElementPreferenceKey.self, value: [ group.group_id : y])
})
} }
} }
} }
} }
} }
// , [groupId : minY]
struct DramaGroupElementPreferenceKey: PreferenceKey {
static var defaultValue: [String: CGFloat] = [:]
static func reduce(value: inout [String: CGFloat], nextValue: () -> [String: CGFloat]) {
value.merge(nextValue()) { $1 }
}
}
} }
#Preview { #Preview {

View File

@ -0,0 +1,18 @@
//
// SearchView.swift
// dimensionhub
//
// Created by on 2025/4/1.
//
import SwiftUI
struct SearchView: View {
var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
}
}
#Preview {
SearchView()
}

View File

@ -44,5 +44,6 @@ struct dimensionhubApp: App {
.tint(.black) .tint(.black)
} }
.modelContainer(sharedModelContainer) .modelContainer(sharedModelContainer)
} }
} }