fix bug
This commit is contained in:
@@ -13,6 +13,8 @@ struct EpisodeListView: View {
|
|||||||
@State private var currentGroup = 0
|
@State private var currentGroup = 0
|
||||||
/// 每个分组展示的剧集数量。
|
/// 每个分组展示的剧集数量。
|
||||||
private let groupSize = 50
|
private let groupSize = 50
|
||||||
|
/// 自适应列:根据可用宽度自动换行,避免集数过多时右侧被截断。
|
||||||
|
private let gridColumns = [GridItem(.adaptive(minimum: 78), spacing: 10)]
|
||||||
|
|
||||||
/// 分组总数,至少为 1,避免空数组时出现 0 组的边界问题。
|
/// 分组总数,至少为 1,避免空数组时出现 0 组的边界问题。
|
||||||
private var groupCount: Int {
|
private var groupCount: Int {
|
||||||
@@ -63,44 +65,40 @@ struct EpisodeListView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 剧集网格
|
// 剧集网格:自适应换行,避免横向裁切。
|
||||||
ScrollView(.horizontal, showsIndicators: false) {
|
LazyVGrid(columns: gridColumns, alignment: .leading, spacing: 10) {
|
||||||
LazyHGrid(rows: [
|
// 这里使用当前组内索引 + 组偏移,换算成全局索引以便外部状态一致。
|
||||||
GridItem(.fixed(44)),
|
ForEach(Array(currentEpisodes.enumerated()), id: \.offset) { index, episode in
|
||||||
GridItem(.fixed(44))
|
let actualIndex = currentGroup * groupSize + index
|
||||||
], spacing: 10) {
|
Button {
|
||||||
// 这里使用当前组内索引 + 组偏移,换算成全局索引以便外部状态一致。
|
onSelect(actualIndex)
|
||||||
ForEach(Array(currentEpisodes.enumerated()), id: \.offset) { index, episode in
|
} label: {
|
||||||
let actualIndex = currentGroup * groupSize + index
|
Text(episode.name)
|
||||||
Button {
|
.font(.system(size: 13, weight: actualIndex == selectedIndex ? .bold : .medium))
|
||||||
onSelect(actualIndex)
|
.foregroundColor(actualIndex == selectedIndex ? .white : .white.opacity(0.7))
|
||||||
} label: {
|
.lineLimit(1)
|
||||||
Text(episode.name)
|
.minimumScaleFactor(0.85)
|
||||||
.font(.system(size: 13, weight: actualIndex == selectedIndex ? .bold : .medium))
|
.frame(maxWidth: .infinity)
|
||||||
.foregroundColor(actualIndex == selectedIndex ? .white : .white.opacity(0.7))
|
.frame(height: 44)
|
||||||
.frame(minWidth: 70)
|
.background(
|
||||||
.frame(height: 44)
|
ZStack {
|
||||||
.background(
|
if actualIndex == selectedIndex {
|
||||||
ZStack {
|
AppTheme.accentGradient
|
||||||
if actualIndex == selectedIndex {
|
} else {
|
||||||
AppTheme.accentGradient
|
Color.white.opacity(0.05)
|
||||||
} else {
|
|
||||||
Color.white.opacity(0.05)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
.clipShape(RoundedRectangle(cornerRadius: 10))
|
)
|
||||||
.overlay(
|
.clipShape(RoundedRectangle(cornerRadius: 10))
|
||||||
RoundedRectangle(cornerRadius: 10)
|
.overlay(
|
||||||
.stroke(actualIndex == selectedIndex ? Color.clear : Color.white.opacity(0.1), lineWidth: 0.5)
|
RoundedRectangle(cornerRadius: 10)
|
||||||
)
|
.stroke(actualIndex == selectedIndex ? Color.clear : Color.white.opacity(0.1), lineWidth: 0.5)
|
||||||
}
|
)
|
||||||
.buttonStyle(.plain)
|
|
||||||
}
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
}
|
}
|
||||||
.padding(.horizontal, 20)
|
|
||||||
}
|
}
|
||||||
.frame(height: 100)
|
.padding(.horizontal, 20)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user