Skip to content

Commit

Permalink
Merge pull request #2 from jeffc-dev/main
Browse files Browse the repository at this point in the history
Added support for pull-to-refresh configuration option…
  • Loading branch information
marcprux authored Sep 4, 2024
2 parents ab4b6ac + 5e1a5f4 commit 4aaea42
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Sources/SkipWeb/WebEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ public struct WebLoadError : Error, CustomStringConvertible {
public class WebEngineConfiguration : ObservableObject {
@Published public var javaScriptEnabled: Bool
@Published public var allowsBackForwardNavigationGestures: Bool
@Published public var allowsPullToRefresh: Bool
@Published public var allowsInlineMediaPlayback: Bool
@Published public var dataDetectorsEnabled: Bool
@Published public var isScrollEnabled: Bool
Expand All @@ -392,6 +393,7 @@ public class WebEngineConfiguration : ObservableObject {

public init(javaScriptEnabled: Bool = true,
allowsBackForwardNavigationGestures: Bool = true,
allowsPullToRefresh: Bool = true,
allowsInlineMediaPlayback: Bool = true,
dataDetectorsEnabled: Bool = true,
isScrollEnabled: Bool = true,
Expand All @@ -400,6 +402,7 @@ public class WebEngineConfiguration : ObservableObject {
userScripts: [WebViewUserScript] = []) {
self.javaScriptEnabled = javaScriptEnabled
self.allowsBackForwardNavigationGestures = allowsBackForwardNavigationGestures
self.allowsPullToRefresh = allowsPullToRefresh
self.allowsInlineMediaPlayback = allowsInlineMediaPlayback
self.dataDetectorsEnabled = dataDetectorsEnabled
self.isScrollEnabled = isScrollEnabled
Expand Down
9 changes: 6 additions & 3 deletions Sources/SkipWeb/WebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,12 @@ extension WebView : ViewRepresentable {
webView.allowsBackForwardNavigationGestures = true
webView.allowsLinkPreview = true

// add a pull-to-refresh control to the page
webView.scrollView.refreshControl = UIRefreshControl()
webView.scrollView.refreshControl?.addTarget(context.coordinator, action: #selector(Coordinator.handleRefreshControl), for: .valueChanged)
if config.allowsPullToRefresh == true {
// add a pull-to-refresh control to the page

webView.scrollView.refreshControl = UIRefreshControl()
webView.scrollView.refreshControl?.addTarget(context.coordinator, action: #selector(Coordinator.handleRefreshControl), for: .valueChanged)
}

webView.publisher(for: \.title)
.receive(on: DispatchQueue.main)
Expand Down

0 comments on commit 4aaea42

Please sign in to comment.