mirror of
https://github.com/VGEAREN/Stockbar.git
synced 2026-10-06 14:33:11 +08:00
v1.2.4: Fix scroll position: preserve on chart return, reset on panel reopen
- Use ZStack overlay for chart instead of if/else branch swap - ScrollView stays mounted while chart is shown (opacity toggle) - Scroll position preserved when returning from chart view - Panel reopen naturally starts from top Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
7e502232d3
commit
ac87a4417d
@@ -5,7 +5,6 @@ struct DropdownView: View {
|
||||
@State private var showSettings = false
|
||||
@State private var sortByChange = false
|
||||
@State private var selectedStock: Stock? = nil
|
||||
@State private var lastSelectedStockId: String? = nil
|
||||
|
||||
/// 分组数据:(market, stocks, customTitle?)
|
||||
private var groupedStocks: [(Market, [Stock], String?)] {
|
||||
@@ -51,6 +50,21 @@ struct DropdownView: View {
|
||||
return result
|
||||
}
|
||||
|
||||
private var stockListView: some View {
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
ForEach(Array(groupedStocks.enumerated()), id: \.offset) { _, group in
|
||||
StockGroupView(market: group.0, stocks: group.1,
|
||||
title: group.2,
|
||||
onSelect: { selectedStock = $0 })
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 6)
|
||||
}
|
||||
.scrollIndicators(.never)
|
||||
.frame(maxHeight: 520)
|
||||
}
|
||||
|
||||
private func sortValue(quote: Quote?, market: Market, mode: USPriceMode) -> Double {
|
||||
guard let q = quote else { return -Double.infinity }
|
||||
if market == .usStock && mode == .sessionPrice, let ext = q.extendedPrice {
|
||||
@@ -67,37 +81,18 @@ struct DropdownView: View {
|
||||
} else {
|
||||
ProfitSummaryView()
|
||||
|
||||
if let stock = selectedStock {
|
||||
StockChartView(stock: stock, onClose: { selectedStock = nil })
|
||||
} else if appState.stocks.isEmpty {
|
||||
if appState.stocks.isEmpty {
|
||||
Text("暂无股票,点击设置添加")
|
||||
.font(.system(size: 12))
|
||||
.foregroundColor(.secondary)
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding()
|
||||
} else {
|
||||
ScrollViewReader { proxy in
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
ForEach(Array(groupedStocks.enumerated()), id: \.offset) { _, group in
|
||||
StockGroupView(market: group.0, stocks: group.1,
|
||||
title: group.2,
|
||||
onSelect: {
|
||||
lastSelectedStockId = $0.id
|
||||
selectedStock = $0
|
||||
})
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 6)
|
||||
}
|
||||
.scrollIndicators(.never)
|
||||
.frame(maxHeight: 520)
|
||||
.onAppear {
|
||||
if let id = lastSelectedStockId {
|
||||
DispatchQueue.main.async {
|
||||
proxy.scrollTo(id, anchor: .center)
|
||||
}
|
||||
}
|
||||
ZStack {
|
||||
stockListView
|
||||
.opacity(selectedStock == nil ? 1 : 0)
|
||||
if let stock = selectedStock {
|
||||
StockChartView(stock: stock, onClose: { selectedStock = nil })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user