From dc39dba86abcd40fbb928d02a13fab9800ddf81d Mon Sep 17 00:00:00 2001 From: Horus Lugo Date: Sat, 23 Sep 2023 18:24:45 +0200 Subject: [PATCH 1/7] feat: support configuring webView.scrollView.bounce --- .../Peregrine/WebFrame+Configuration.swift | 5 ++++- Sources/Peregrine/WebFrame.swift | 2 +- Sources/Peregrine/WebViewOptions.swift | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 Sources/Peregrine/WebViewOptions.swift diff --git a/Sources/Peregrine/WebFrame+Configuration.swift b/Sources/Peregrine/WebFrame+Configuration.swift index 0b55d30..ac20fba 100644 --- a/Sources/Peregrine/WebFrame+Configuration.swift +++ b/Sources/Peregrine/WebFrame+Configuration.swift @@ -11,6 +11,7 @@ extension WebFrame { public let functions: RemoteFunctions? public let observables: RemoteObservables? public let pathHandlers: [String: PathHandler]? + public let webViewOptions: WebViewOptions internal static let appScheme = "app" internal static let rpcScheme = "peregrine" @@ -42,12 +43,14 @@ extension WebFrame { )!, // swiftlint:disable:this force_unwrapping functions: RemoteFunctions? = nil, observables: RemoteObservables? = nil, - pathHandlers: [String: PathHandler]? = nil + pathHandlers: [String: PathHandler]? = nil, + webViewOptions: WebViewOptions = WebViewOptions() ) { self.baseURL = baseURL self.functions = functions self.observables = observables self.pathHandlers = pathHandlers + self.webViewOptions = webViewOptions } } } diff --git a/Sources/Peregrine/WebFrame.swift b/Sources/Peregrine/WebFrame.swift index 7f62e95..514bfc8 100644 --- a/Sources/Peregrine/WebFrame.swift +++ b/Sources/Peregrine/WebFrame.swift @@ -124,7 +124,7 @@ public final class WebFrame: Frame { } webView.navigationDelegate = webViewNavigationDelegate - webView.scrollView.bounces = false + webView.scrollView.bounces = configuration.webViewOptions.scrollView.bounces webView.scrollView.contentInsetAdjustmentBehavior = .never webView.uiDelegate = webViewUIDelegate diff --git a/Sources/Peregrine/WebViewOptions.swift b/Sources/Peregrine/WebViewOptions.swift new file mode 100644 index 0000000..8a01773 --- /dev/null +++ b/Sources/Peregrine/WebViewOptions.swift @@ -0,0 +1,19 @@ + + +public struct WebViewScrollViewOptions { + public let bounces: Bool + + public init( + bounces: Bool = false + ) { + self.bounces = bounces + } +} + +public struct WebViewOptions { + public let scrollView: WebViewScrollViewOptions + + public init(scrollView: WebViewScrollViewOptions = WebViewScrollViewOptions()) { + self.scrollView = scrollView + } +} From ed43c9b7f27ae3a17605126bc942581b3a25e8ce Mon Sep 17 00:00:00 2001 From: Horus Lugo Date: Sat, 23 Sep 2023 18:28:26 +0200 Subject: [PATCH 2/7] remove spacing --- Sources/Peregrine/WebViewOptions.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Sources/Peregrine/WebViewOptions.swift b/Sources/Peregrine/WebViewOptions.swift index 8a01773..e90b629 100644 --- a/Sources/Peregrine/WebViewOptions.swift +++ b/Sources/Peregrine/WebViewOptions.swift @@ -1,5 +1,3 @@ - - public struct WebViewScrollViewOptions { public let bounces: Bool From 968e700dad631ae2c035c213a1f891e528ff52c9 Mon Sep 17 00:00:00 2001 From: Horus Lugo Date: Sat, 23 Sep 2023 18:43:50 +0200 Subject: [PATCH 3/7] Run swiftlint --- Sources/Peregrine/WebViewOptions.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Peregrine/WebViewOptions.swift b/Sources/Peregrine/WebViewOptions.swift index e90b629..85858e7 100644 --- a/Sources/Peregrine/WebViewOptions.swift +++ b/Sources/Peregrine/WebViewOptions.swift @@ -1,6 +1,6 @@ public struct WebViewScrollViewOptions { public let bounces: Bool - + public init( bounces: Bool = false ) { @@ -10,7 +10,7 @@ public struct WebViewScrollViewOptions { public struct WebViewOptions { public let scrollView: WebViewScrollViewOptions - + public init(scrollView: WebViewScrollViewOptions = WebViewScrollViewOptions()) { self.scrollView = scrollView } From b5627245bbdbea930707f5a5594f6eaf97cd7ef1 Mon Sep 17 00:00:00 2001 From: Horus Lugo Date: Sat, 23 Sep 2023 19:07:26 +0200 Subject: [PATCH 4/7] Switch to mutation based API --- Sources/Peregrine/WebFrame+Configuration.swift | 6 ++---- Sources/Peregrine/WebViewOptions.swift | 16 +++------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/Sources/Peregrine/WebFrame+Configuration.swift b/Sources/Peregrine/WebFrame+Configuration.swift index ac20fba..6d2bcbd 100644 --- a/Sources/Peregrine/WebFrame+Configuration.swift +++ b/Sources/Peregrine/WebFrame+Configuration.swift @@ -11,7 +11,7 @@ extension WebFrame { public let functions: RemoteFunctions? public let observables: RemoteObservables? public let pathHandlers: [String: PathHandler]? - public let webViewOptions: WebViewOptions + public let webViewOptions = WebViewOptions() internal static let appScheme = "app" internal static let rpcScheme = "peregrine" @@ -43,14 +43,12 @@ extension WebFrame { )!, // swiftlint:disable:this force_unwrapping functions: RemoteFunctions? = nil, observables: RemoteObservables? = nil, - pathHandlers: [String: PathHandler]? = nil, - webViewOptions: WebViewOptions = WebViewOptions() + pathHandlers: [String: PathHandler]? = nil ) { self.baseURL = baseURL self.functions = functions self.observables = observables self.pathHandlers = pathHandlers - self.webViewOptions = webViewOptions } } } diff --git a/Sources/Peregrine/WebViewOptions.swift b/Sources/Peregrine/WebViewOptions.swift index 85858e7..018c234 100644 --- a/Sources/Peregrine/WebViewOptions.swift +++ b/Sources/Peregrine/WebViewOptions.swift @@ -1,17 +1,7 @@ -public struct WebViewScrollViewOptions { - public let bounces: Bool - - public init( - bounces: Bool = false - ) { - self.bounces = bounces - } +internal struct WebViewScrollViewOptions { + var bounces = false } public struct WebViewOptions { - public let scrollView: WebViewScrollViewOptions - - public init(scrollView: WebViewScrollViewOptions = WebViewScrollViewOptions()) { - self.scrollView = scrollView - } + public let scrollView = WebViewScrollViewOptions() } From 4de17e06fb97ebf69991769c6780dc9e1f311b94 Mon Sep 17 00:00:00 2001 From: Horus Lugo Date: Sat, 23 Sep 2023 19:08:29 +0200 Subject: [PATCH 5/7] Bring back allowing to pass WebViewOptions --- Sources/Peregrine/WebFrame+Configuration.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/Peregrine/WebFrame+Configuration.swift b/Sources/Peregrine/WebFrame+Configuration.swift index 6d2bcbd..ac20fba 100644 --- a/Sources/Peregrine/WebFrame+Configuration.swift +++ b/Sources/Peregrine/WebFrame+Configuration.swift @@ -11,7 +11,7 @@ extension WebFrame { public let functions: RemoteFunctions? public let observables: RemoteObservables? public let pathHandlers: [String: PathHandler]? - public let webViewOptions = WebViewOptions() + public let webViewOptions: WebViewOptions internal static let appScheme = "app" internal static let rpcScheme = "peregrine" @@ -43,12 +43,14 @@ extension WebFrame { )!, // swiftlint:disable:this force_unwrapping functions: RemoteFunctions? = nil, observables: RemoteObservables? = nil, - pathHandlers: [String: PathHandler]? = nil + pathHandlers: [String: PathHandler]? = nil, + webViewOptions: WebViewOptions = WebViewOptions() ) { self.baseURL = baseURL self.functions = functions self.observables = observables self.pathHandlers = pathHandlers + self.webViewOptions = webViewOptions } } } From 428222c39a75c93a9c11540108557e9b94abf9d1 Mon Sep 17 00:00:00 2001 From: Horus Lugo Date: Sat, 23 Sep 2023 19:22:40 +0200 Subject: [PATCH 6/7] fix: make WebViewScrollViewOptions public --- Sources/Peregrine/WebViewOptions.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Peregrine/WebViewOptions.swift b/Sources/Peregrine/WebViewOptions.swift index 018c234..2985c72 100644 --- a/Sources/Peregrine/WebViewOptions.swift +++ b/Sources/Peregrine/WebViewOptions.swift @@ -1,5 +1,5 @@ -internal struct WebViewScrollViewOptions { - var bounces = false +public struct WebViewScrollViewOptions { + public var bounces = false } public struct WebViewOptions { From 81c4bd21abb6ed82a684b6801c03f4a77869b71c Mon Sep 17 00:00:00 2001 From: Horus Lugo Date: Sat, 23 Sep 2023 19:29:56 +0200 Subject: [PATCH 7/7] Empty constructor I guess --- Sources/Peregrine/WebViewOptions.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/Peregrine/WebViewOptions.swift b/Sources/Peregrine/WebViewOptions.swift index 2985c72..3e87973 100644 --- a/Sources/Peregrine/WebViewOptions.swift +++ b/Sources/Peregrine/WebViewOptions.swift @@ -4,4 +4,6 @@ public struct WebViewScrollViewOptions { public struct WebViewOptions { public let scrollView = WebViewScrollViewOptions() + + public init() {} }