This commit is contained in:
anlicheng 2025-06-10 18:33:04 +08:00
parent 46bf943d4c
commit e784d46299
2 changed files with 84 additions and 30 deletions

View File

@ -29,6 +29,9 @@ struct IndexMainView: View {
@State private var footerRefreshing: Bool = false @State private var footerRefreshing: Bool = false
@State private var noMore: Bool = false @State private var noMore: Bool = false
@State private var scrollOffset: CGFloat = 0
@State private var showFloatGroupLabel: Bool = false
var body: some View { var body: some View {
VStack(alignment: .center) { VStack(alignment: .center) {
@ -61,8 +64,16 @@ struct IndexMainView: View {
.background(Color(hex: "#F2F2F2"), ignoresSafeAreaEdges: .top) .background(Color(hex: "#F2F2F2"), ignoresSafeAreaEdges: .top)
ScrollView(.vertical, showsIndicators: false) { ScrollView(.vertical, showsIndicators: false) {
Rectangle() ScrollViewOffsetReader(offset: $scrollOffset)
.frame(width: 0, height: 38)
MixGroupLabelView(fixedDramaGroup: indexModel.fixedDramaGroup) {
if let groupId = indexModel.fixedDramaGroup?.group_id {
selectGroupId = groupId
indexModel.selectedDate = groupId
showDateNavPopover = true
}
}
.opacity(!showFloatGroupLabel ? 1 : 0)
// //
LazyVStack(alignment: .center, spacing: 10) { LazyVStack(alignment: .center, spacing: 10) {
@ -87,6 +98,9 @@ struct IndexMainView: View {
.frame(width: 370) .frame(width: 370)
.coordinateSpace(name: "indexScrollView") .coordinateSpace(name: "indexScrollView")
.scrollPosition(id: $scrollID) .scrollPosition(id: $scrollID)
.onChange(of: scrollOffset) {
self.showFloatGroupLabel = scrollOffset < 0
}
.refreshable { .refreshable {
guard !self.showDateNavPopover && !self.headerRefreshing else { guard !self.showDateNavPopover && !self.headerRefreshing else {
return return
@ -107,37 +121,15 @@ struct IndexMainView: View {
} }
} }
.overlay(alignment: .topTrailing) { .overlay(alignment: .topTrailing) {
HStack(alignment: .center) { MixGroupLabelView(fixedDramaGroup: indexModel.fixedDramaGroup) {
Button(action: { if let groupId = indexModel.fixedDramaGroup?.group_id {
appNavigation.append(dest: .search) selectGroupId = groupId
}) { indexModel.selectedDate = groupId
Image(systemName: "magnifyingglass")
.font(.system(size: 20))
}
Spacer()
if let fixedDramaGroup = indexModel.fixedDramaGroup {
Text(fixedDramaGroup.group_name)
.font(.system(size: 18))
.fontWeight(.regular)
.onTapGesture {
selectGroupId = fixedDramaGroup.group_id
indexModel.selectedDate = fixedDramaGroup.group_id
showDateNavPopover = true showDateNavPopover = true
} }
} }
} .opacity(showFloatGroupLabel ? 1 : 0)
.padding([.top, .bottom], 8)
.background(.white)
.background(
GeometryReader { geometry in
Color.clear
.onAppear {
print("hstack height is: \(geometry.size.height)")
}
}
)
} }
} }
.ignoresSafeArea(edges: .bottom) .ignoresSafeArea(edges: .bottom)
@ -156,10 +148,69 @@ struct IndexMainView: View {
} }
} }
struct ScrollViewOffsetReader: View {
@Binding var offset: CGFloat
var body: some View {
GeometryReader { geometry in
Color.clear
.preference(
key: ScrollOffsetPreferenceKey.self,
value: geometry.frame(in: .named("indexScrollView")).origin.y
)
}
.frame(height: 0)
.onPreferenceChange(ScrollOffsetPreferenceKey.self) { value in
DispatchQueue.main.async {
self.offset = value
}
}
}
}
struct ScrollOffsetPreferenceKey: PreferenceKey {
static var defaultValue: CGFloat = 0
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
value = nextValue()
}
}
} }
extension IndexMainView { extension IndexMainView {
struct MixGroupLabelView: View {
@EnvironmentObject var appNav: AppNavigation
let fixedDramaGroup: IndexModel.UpdateDramaGroup?
let onTap: () -> Void
var body: some View {
HStack(alignment: .center) {
Button(action: {
appNav.append(dest: .search)
}) {
Image(systemName: "magnifyingglass")
.font(.system(size: 20))
}
Spacer()
if let fixedDramaGroup {
Text(fixedDramaGroup.group_name)
.font(.system(size: 18))
.fontWeight(.regular)
.onTapGesture {
onTap()
}
}
}
.padding([.top, .bottom], 8)
.background(.white)
}
}
// //
struct DramaGroupLabelView: View { struct DramaGroupLabelView: View {
let group_name: String let group_name: String

View File

@ -65,6 +65,9 @@ final class IndexModel {
// , 便 // , 便
var dramaGroupElements: [GroupElement] = [] var dramaGroupElements: [GroupElement] = []
// GroupLabel
var showFloatGroupLabel: Bool = false
var follow_num: String = "0" var follow_num: String = "0"
// group_name // group_name