Skip to content

Commit

Permalink
Add progress
Browse files Browse the repository at this point in the history
  • Loading branch information
bourvill committed Sep 2, 2023
1 parent 281fe48 commit cb98c53
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion App/Features/Entry/EntryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
9 changes: 7 additions & 2 deletions App/Features/Entry/WebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit cb98c53

Please sign in to comment.