mirror of
https://github.com/VGEAREN/Stockbar.git
synced 2026-10-06 14:33:11 +08:00
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:
co-authored by
Claude Opus 4.6
parent
c7b19e4f49
commit
80c12aba58
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user