diff --git a/App/Features/Entry/EntryView.swift b/App/Features/Entry/EntryView.swift index bd8e9d7d..7fe5117c 100644 --- a/App/Features/Entry/EntryView.swift +++ b/App/Features/Entry/EntryView.swift @@ -14,6 +14,7 @@ struct EntryView: View { @ObservedObject var entry: Entry @State var showTag: Bool = false @State private var showDeleteConfirm = false + @State private var progress = 0.0 #if os(iOS) let toolbarPlacement: ToolbarItemPlacement = .bottomBar @@ -28,7 +29,8 @@ struct EntryView: View { .fontWeight(.black) .lineLimit(2) .padding(.horizontal) - WebView(entry: entry) + ProgressView(value: progress, total: 1) + WebView(entry: entry, progress: $progress) } .addSwipeToBack { dismiss() diff --git a/App/Features/Entry/WebView.swift b/App/Features/Entry/WebView.swift index af0c29c8..22e29c2e 100644 --- a/App/Features/Entry/WebView.swift +++ b/App/Features/Entry/WebView.swift @@ -8,6 +8,7 @@ import WebKit var entry: Entry private(set) var wkWebView = WKWebView(frame: .zero) @EnvironmentObject var appSetting: AppSetting + @Binding var progress: Double func makeCoordinator() -> Coordinator { Coordinator(self, appSetting: appSetting) @@ -61,6 +62,10 @@ import WebKit decisionHandler(.cancel) } + func scrollViewDidScroll(_ scrollView: UIScrollView) { + webView.progress = scrollView.contentOffset.y / (scrollView.contentSize.height - scrollView.bounds.height) + } + func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { context.perform { self.webView.entry.screenPosition = Float(scrollView.contentOffset.y) @@ -176,10 +181,10 @@ struct WebView_Previews: PreviewProvider { static var previews: some View { Group { WebView( - entry: entry + entry: entry, progress: .constant(0.5) ).colorScheme(.light) WebView( - entry: entry + entry: entry, progress: .constant(0.5) ).colorScheme(.dark) } }