fix
This commit is contained in:
parent
46bf943d4c
commit
e784d46299
@ -29,6 +29,9 @@ struct IndexMainView: View {
|
||||
@State private var footerRefreshing: Bool = false
|
||||
@State private var noMore: Bool = false
|
||||
|
||||
@State private var scrollOffset: CGFloat = 0
|
||||
@State private var showFloatGroupLabel: Bool = false
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .center) {
|
||||
|
||||
@ -61,8 +64,16 @@ struct IndexMainView: View {
|
||||
.background(Color(hex: "#F2F2F2"), ignoresSafeAreaEdges: .top)
|
||||
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
Rectangle()
|
||||
.frame(width: 0, height: 38)
|
||||
ScrollViewOffsetReader(offset: $scrollOffset)
|
||||
|
||||
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) {
|
||||
@ -87,6 +98,9 @@ struct IndexMainView: View {
|
||||
.frame(width: 370)
|
||||
.coordinateSpace(name: "indexScrollView")
|
||||
.scrollPosition(id: $scrollID)
|
||||
.onChange(of: scrollOffset) {
|
||||
self.showFloatGroupLabel = scrollOffset < 0
|
||||
}
|
||||
.refreshable {
|
||||
guard !self.showDateNavPopover && !self.headerRefreshing else {
|
||||
return
|
||||
@ -107,37 +121,15 @@ struct IndexMainView: View {
|
||||
}
|
||||
}
|
||||
.overlay(alignment: .topTrailing) {
|
||||
HStack(alignment: .center) {
|
||||
Button(action: {
|
||||
appNavigation.append(dest: .search)
|
||||
}) {
|
||||
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
|
||||
MixGroupLabelView(fixedDramaGroup: indexModel.fixedDramaGroup) {
|
||||
if let groupId = indexModel.fixedDramaGroup?.group_id {
|
||||
selectGroupId = groupId
|
||||
indexModel.selectedDate = groupId
|
||||
showDateNavPopover = true
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
.padding([.top, .bottom], 8)
|
||||
.background(.white)
|
||||
.background(
|
||||
GeometryReader { geometry in
|
||||
Color.clear
|
||||
.onAppear {
|
||||
print("hstack height is: \(geometry.size.height)")
|
||||
}
|
||||
}
|
||||
)
|
||||
.opacity(showFloatGroupLabel ? 1 : 0)
|
||||
}
|
||||
}
|
||||
.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 {
|
||||
|
||||
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 {
|
||||
let group_name: String
|
||||
|
||||
@ -65,6 +65,9 @@ final class IndexModel {
|
||||
// 转换后的数据, 方便在一次循环中展示数据
|
||||
var dramaGroupElements: [GroupElement] = []
|
||||
|
||||
// 判断GroupLabel的显示方式
|
||||
var showFloatGroupLabel: Bool = false
|
||||
|
||||
var follow_num: String = "0"
|
||||
|
||||
// 用来显示固定栏目的group_name
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user