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 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")
|
showDateNavPopover = true
|
||||||
.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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.padding([.top, .bottom], 8)
|
.opacity(showFloatGroupLabel ? 1 : 0)
|
||||||
.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
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user