fix index view
This commit is contained in:
parent
7255bb3c5a
commit
a9d306225a
@ -420,8 +420,7 @@
|
||||
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
|
||||
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
|
||||
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 17.6;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
@ -455,8 +454,7 @@
|
||||
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
|
||||
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
|
||||
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 17.6;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
|
||||
@ -84,6 +84,13 @@ final class IndexModel {
|
||||
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
|
||||
func loadMoreUpdateDramas(userId: String, mode: API.LoadMode) async {
|
||||
// 按照id来判断不一定正确,需要借助其他值
|
||||
@ -132,6 +139,7 @@ final class IndexModel {
|
||||
let response = await API.loadDateUpdateDramas(userId: userId, date: date, as: [UpdateDramaGroup].self)
|
||||
if case let .result(groups) = response {
|
||||
self.updateDramaGroups = groups
|
||||
self.fixedDramaGroup = groups.first
|
||||
}
|
||||
}
|
||||
|
||||
@ -379,8 +387,14 @@ extension IndexView {
|
||||
self.isPrevLoading = false
|
||||
}
|
||||
.overlay(alignment: .topTrailing) {
|
||||
HStack {
|
||||
Text("🔍")
|
||||
HStack(alignment: .center) {
|
||||
NavigationLink {
|
||||
SearchView()
|
||||
} label: {
|
||||
Image(systemName: "magnifyingglass")
|
||||
.font(.system(size: 20))
|
||||
}
|
||||
|
||||
Spacer()
|
||||
if let fixedDramaGroup = indexModel.fixedDramaGroup {
|
||||
Text(fixedDramaGroup.group_name)
|
||||
@ -393,7 +407,7 @@ extension IndexView {
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(8)
|
||||
.padding([.top, .bottom], 8)
|
||||
.background(.white)
|
||||
}
|
||||
}
|
||||
@ -411,6 +425,12 @@ extension IndexView {
|
||||
.task {
|
||||
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()
|
||||
}
|
||||
}
|
||||
.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
|
||||
NavigationLink(destination: DetailView(id: item.id)) {
|
||||
@ -481,12 +493,32 @@ extension IndexView {
|
||||
.cornerRadius(5)
|
||||
.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 {
|
||||
|
||||
18
dimensionhub/Views/SearchView.swift
Normal file
18
dimensionhub/Views/SearchView.swift
Normal 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()
|
||||
}
|
||||
@ -44,5 +44,6 @@ struct dimensionhubApp: App {
|
||||
.tint(.black)
|
||||
}
|
||||
.modelContainer(sharedModelContainer)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user