v1.2.2: Preserve scroll position when returning from chart view

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
vgearen
2026-03-20 20:17:35 +08:00
co-authored by Claude Opus 4.6
parent c7b19e4f49
commit 80c12aba58
2 changed files with 22 additions and 8 deletions
+21 -8
View File
@@ -5,6 +5,7 @@ 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
private var groupedStocks: [(Market, [Stock])] {
[Market.aStock, .hkStock, .usStock].compactMap { market in
@@ -49,17 +50,29 @@ struct DropdownView: View {
.frame(maxWidth: .infinity)
.padding()
} else {
ScrollView {
VStack(alignment: .leading, spacing: 6) {
ForEach(groupedStocks, id: \.0) { market, stocks in
StockGroupView(market: market, stocks: stocks,
onSelect: { selectedStock = $0 })
ScrollViewReader { proxy in
ScrollView {
VStack(alignment: .leading, spacing: 6) {
ForEach(groupedStocks, id: \.0) { market, stocks in
StockGroupView(market: market, stocks: stocks,
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)
}
}
}
.padding(.horizontal, 6)
}
.scrollIndicators(.never)
.frame(maxHeight: 520)
}
Divider()
+1
View File
@@ -31,6 +31,7 @@ struct StockGroupView: View {
ForEach(stocks) { stock in
StockRowView(stock: stock, quote: appState.quotes[stock.id],
onTap: { onSelect?(stock) })
.id(stock.id)
}
}
}