diff options
author | Navan Chauhan <navanchauhan@gmail.com> | 2024-02-19 11:39:54 -0700 |
---|---|---|
committer | Navan Chauhan <navanchauhan@gmail.com> | 2024-02-19 11:39:54 -0700 |
commit | 07d7ef1668ef4d5718cfeeafed8e552804951101 (patch) | |
tree | 32c10fd20ddec2efcbe2cdce1d8830145424218d | |
parent | 8ec0233fe9642328e5db923d21c1b052905faffc (diff) |
fix ScrollTo for macOS
-rw-r--r-- | iGopherBrowser/BrowserView.swift | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/iGopherBrowser/BrowserView.swift b/iGopherBrowser/BrowserView.swift index 885d5fa..c38fb8f 100644 --- a/iGopherBrowser/BrowserView.swift +++ b/iGopherBrowser/BrowserView.swift @@ -70,6 +70,7 @@ struct BrowserView: View { .frame(height: 20) .listRowSeparator(.hidden) .padding(.vertical, -8) + .id(idx) } else if item.parsedItemType == .directory { Button(action: { performGopherRequest(host: item.host, port: item.port, selector: item.selector) @@ -83,7 +84,7 @@ struct BrowserView: View { Spacer() }.foregroundStyle(linkColour) }.buttonStyle(PlainButtonStyle()) - + .id(idx) } else if item.parsedItemType == .search { Button(action: { #if canImport(UIKit) @@ -98,7 +99,7 @@ struct BrowserView: View { Spacer() }.foregroundStyle(linkColour) }.buttonStyle(PlainButtonStyle()) - + .id(idx) } else if item.parsedItemType == .text { NavigationLink(destination: FileView(item: item)) { HStack { @@ -107,6 +108,7 @@ struct BrowserView: View { Spacer() }.foregroundStyle(linkColour) } + .id(idx) } else if item.selector.hasPrefix("URL:") { if let url = URL(string: item.selector.replacingOccurrences(of: "URL:", with: "")) { @@ -120,6 +122,7 @@ struct BrowserView: View { Spacer() }.foregroundStyle(linkColour) }.buttonStyle(PlainButtonStyle()) + .id(idx) } } else if [.doc, .image, .gif, .movie, .sound, .bitmap].contains( item.parsedItemType) @@ -130,6 +133,7 @@ struct BrowserView: View { Text(item.message) Spacer() }.foregroundStyle(linkColour) + .id(idx) } } else { Button(action: { @@ -144,25 +148,20 @@ struct BrowserView: View { Spacer() }.foregroundStyle(linkColour) }.buttonStyle(PlainButtonStyle()) - + .id(idx) } } - }.id(topID) - //.background(Color.white) - .cornerRadius(10) - .onChange(of: scrollToTop) { - // TODO: Cleanup - withAnimation { - // TODO: Fix for macOS - #if os(macOS) - proxy.scrollTo(0, anchor: .top) - #else - proxy.scrollTo(0, anchor: .top) - #endif + } + //.background(Color.white) + .cornerRadius(10) + .onChange(of: scrollToTop) { + // TODO: Cleanup + withAnimation { + proxy.scrollTo(0, anchor: .top) - } } + } } .sheet(isPresented: $showSearchInput) { if let index = selectedSearchItem, gopherItems.indices.contains(index) { |