From a0cc758ad3b161238b0ca8e789c6ac2b8674d7e5 Mon Sep 17 00:00:00 2001 From: "mt.hodaka" Date: Fri, 4 Mar 2022 16:36:29 +0900 Subject: [PATCH] fix duplicated RxWKNavigationDelegateProxy in RxSwift and RxWebKit --- RxWebKit.xcodeproj/project.pbxproj | 4 -- .../RxWKNavigationDelegateProxy.swift | 44 ------------------- .../WKNavigationDelegateEvents+Rx.swift | 25 +++++------ 3 files changed, 10 insertions(+), 63 deletions(-) delete mode 100644 Sources/RxWebKit/RxWKNavigationDelegateProxy.swift diff --git a/RxWebKit.xcodeproj/project.pbxproj b/RxWebKit.xcodeproj/project.pbxproj index ef86fbb..8356b07 100644 --- a/RxWebKit.xcodeproj/project.pbxproj +++ b/RxWebKit.xcodeproj/project.pbxproj @@ -34,7 +34,6 @@ C4878CD61FA1066C00B12C60 /* FailedRequestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4878CD51FA1066C00B12C60 /* FailedRequestViewController.swift */; }; C4878CD81FA117E900B12C60 /* RedirectViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4878CD71FA117E900B12C60 /* RedirectViewController.swift */; }; C4878CDA1FA11B5A00B12C60 /* OtherRequestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4878CD91FA11B5A00B12C60 /* OtherRequestViewController.swift */; }; - C48E617E1F9E27A700C6A753 /* RxWKNavigationDelegateProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = C48E617D1F9E27A700C6A753 /* RxWKNavigationDelegateProxy.swift */; }; C48E61841F9E336000C6A753 /* WKNavigationDelegateEvents+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = C48E61831F9E336000C6A753 /* WKNavigationDelegateEvents+Rx.swift */; }; C4CA6B07228AB1680088A7A3 /* ForwardsEventsBehavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4CA6B06228AB1680088A7A3 /* ForwardsEventsBehavior.swift */; }; EFC27F84246D7E9C0093D8B3 /* RxWebKitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4CB7D5322874EE700FB8D99 /* RxWebKitTests.swift */; }; @@ -148,7 +147,6 @@ C4878CD51FA1066C00B12C60 /* FailedRequestViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FailedRequestViewController.swift; sourceTree = ""; }; C4878CD71FA117E900B12C60 /* RedirectViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RedirectViewController.swift; sourceTree = ""; }; C4878CD91FA11B5A00B12C60 /* OtherRequestViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OtherRequestViewController.swift; sourceTree = ""; }; - C48E617D1F9E27A700C6A753 /* RxWKNavigationDelegateProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RxWKNavigationDelegateProxy.swift; sourceTree = ""; }; C48E61831F9E336000C6A753 /* WKNavigationDelegateEvents+Rx.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WKNavigationDelegateEvents+Rx.swift"; sourceTree = ""; }; C4A50F9E229AF3EF0037E608 /* config.yml */ = {isa = PBXFileReference; lastKnownFileType = text; name = config.yml; path = .circleci/config.yml; sourceTree = SOURCE_ROOT; }; C4CA6B06228AB1680088A7A3 /* ForwardsEventsBehavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForwardsEventsBehavior.swift; sourceTree = ""; }; @@ -211,7 +209,6 @@ children = ( 42F426DB1C662CF9001FED46 /* Rx+WebKit.swift */, C48E61831F9E336000C6A753 /* WKNavigationDelegateEvents+Rx.swift */, - C48E617D1F9E27A700C6A753 /* RxWKNavigationDelegateProxy.swift */, C4607FCF1FA0DAC9002DA12F /* RxWKUIDelegateProxy.swift */, C4607FD51FA0DC40002DA12F /* RxWKUIDelegateEvents+Rx.swift */, F6D7DD0C224F62860066C90F /* RxWKUserContentController.swift */, @@ -514,7 +511,6 @@ files = ( 42F426DC1C662CF9001FED46 /* Rx+WebKit.swift in Sources */, C48E61841F9E336000C6A753 /* WKNavigationDelegateEvents+Rx.swift in Sources */, - C48E617E1F9E27A700C6A753 /* RxWKNavigationDelegateProxy.swift in Sources */, C4607FD01FA0DAC9002DA12F /* RxWKUIDelegateProxy.swift in Sources */, F6D7DD0D224F62860066C90F /* RxWKUserContentController.swift in Sources */, C4607FD61FA0DC40002DA12F /* RxWKUIDelegateEvents+Rx.swift in Sources */, diff --git a/Sources/RxWebKit/RxWKNavigationDelegateProxy.swift b/Sources/RxWebKit/RxWKNavigationDelegateProxy.swift deleted file mode 100644 index 0853906..0000000 --- a/Sources/RxWebKit/RxWKNavigationDelegateProxy.swift +++ /dev/null @@ -1,44 +0,0 @@ -// -// RxWKNavigationDelegateProxy.swift -// RxWebKit -// -// Created by Bob Obi on 23.10.17. -// Copyright © 2017 RxSwift Community. All rights reserved. -// - -import WebKit -#if !RX_NO_MODULE - import RxSwift - import RxCocoa -#endif - -public typealias RxWKNavigationDelegate = DelegateProxy - -open class RxWKNavigationDelegateProxy: RxWKNavigationDelegate, DelegateProxyType, WKNavigationDelegate { - - /// Type of parent object - public weak private(set) var webView: WKWebView? - - /// Init with ParentObject - public init(parentObject: ParentObject) { - webView = parentObject - super.init(parentObject: parentObject, delegateProxy: RxWKNavigationDelegateProxy.self) - } - - /// Register self to known implementations - public static func registerKnownImplementations() { - self.register { parent -> RxWKNavigationDelegateProxy in - RxWKNavigationDelegateProxy(parentObject: parent) - } - } - - /// Gets the current `WKNavigationDelegate` on `WKWebView` - open class func currentDelegate(for object: ParentObject) -> WKNavigationDelegate? { - return object.navigationDelegate - } - - /// Set the navigationDelegate for `WKWebView` - open class func setCurrentDelegate(_ delegate: WKNavigationDelegate?, to object: ParentObject) { - object.navigationDelegate = delegate - } -} diff --git a/Sources/RxWebKit/WKNavigationDelegateEvents+Rx.swift b/Sources/RxWebKit/WKNavigationDelegateEvents+Rx.swift index 878c1d9..93c4d76 100644 --- a/Sources/RxWebKit/WKNavigationDelegateEvents+Rx.swift +++ b/Sources/RxWebKit/WKNavigationDelegateEvents+Rx.swift @@ -43,14 +43,9 @@ extension Reactive where Base: WKWebView { /// WKNavigationActionPolicyEvent emits a tuple event of WKWebView + WKNavigationAction + ActionHandler public typealias WKNavigationActionPolicyEvent = ( webView: WKWebView, action: WKNavigationAction, handler: ActionHandler) - /// Reactive wrapper for `navigationDelegate`. - public var delegate: DelegateProxy { - return RxWKNavigationDelegateProxy.proxy(for: base) - } - /// Reactive wrapper for delegate method `webView(_ webView: WKWebView, didCommit navigation: WKNavigation!)`. public var didCommitNavigation: ControlEvent { - let source: Observable = delegate + let source: Observable = navigationDelegate .methodInvoked(.didCommitNavigation) .map { arg in let view = try castOrThrow(WKWebView.self, arg[0]) @@ -62,7 +57,7 @@ extension Reactive where Base: WKWebView { /// Reactive wrapper for delegate method `webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!)`. public var didStartProvisionalNavigation: ControlEvent { - let source: Observable = delegate + let source: Observable = navigationDelegate .methodInvoked(.didStartProvisionalNavigation) .map { arg in let view = try castOrThrow(WKWebView.self, arg[0]) @@ -74,7 +69,7 @@ extension Reactive where Base: WKWebView { /// Reactive wrapper for delegate method `webView(_ webView: WKWebView, didFinish navigation: WKNavigation!)` public var didFinishNavigation: ControlEvent { - let source: Observable = delegate + let source: Observable = navigationDelegate .methodInvoked(.didFinishNavigation) .map { arg in let view = try castOrThrow(WKWebView.self, arg[0]) @@ -87,7 +82,7 @@ extension Reactive where Base: WKWebView { /// Reactive wrapper for delegate method `webViewWebContentProcessDidTerminate(_ webView: WKWebView)`. @available(iOS 9.0, *) public var didTerminate: ControlEvent { - let source: Observable = delegate + let source: Observable = navigationDelegate .methodInvoked(.didTerminate) .map { try castOrThrow(WKWebView.self, $0[0]) } return ControlEvent(events: source) @@ -95,7 +90,7 @@ extension Reactive where Base: WKWebView { /// Reactive wrapper for delegate method `webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!)`. public var didReceiveServerRedirectForProvisionalNavigation: ControlEvent { - let source: Observable = delegate + let source: Observable = navigationDelegate .methodInvoked(.didReceiveServerRedirectForProvisionalNavigation) .map { arg in let view = try castOrThrow(WKWebView.self, arg[0]) @@ -107,7 +102,7 @@ extension Reactive where Base: WKWebView { /// Reactive wrapper for delegate method `webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error)`. public var didFailNavigation: ControlEvent { - let source: Observable = delegate + let source: Observable = navigationDelegate .methodInvoked(.didFailNavigation) .map { arg in let view = try castOrThrow(WKWebView.self, arg[0]) @@ -120,7 +115,7 @@ extension Reactive where Base: WKWebView { /// Reactive wrapper for delegate method `webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error)`. public var didFailProvisionalNavigation: ControlEvent { - let source: Observable = delegate + let source: Observable = navigationDelegate .methodInvoked(.didFailProvisionalNavigation) .map { arg in let view = try castOrThrow(WKWebView.self, arg[0]) @@ -148,7 +143,7 @@ extension Reactive where Base: WKWebView { credential. @discussion If you do not implement this method, the web view will respond to the authentication challenge with the NSURLSessionAuthChallengeRejectProtectionSpace disposition. */ - let source: Observable = delegate + let source: Observable = navigationDelegate .sentMessage(.didReceiveChallenge) .map { arg in /// Extracting the WKWebView from the array at index zero @@ -205,7 +200,7 @@ extension Reactive where Base: WKWebView { /// Reactive wrapper for `func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Swift.Void)` public var decidePolicyNavigationResponse: ControlEvent { typealias __DecisionHandler = @convention(block) (WKNavigationResponsePolicy) -> () - let source:Observable = delegate + let source:Observable = navigationDelegate .methodInvoked(.decidePolicyNavigationResponse).map { args in let view = try castOrThrow(WKWebView.self, args[0]) let response = try castOrThrow(WKNavigationResponse.self, args[1]) @@ -225,7 +220,7 @@ extension Reactive where Base: WKWebView { /// Reactive wrapper for `func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Swift.Void)` public var decidePolicyNavigationAction: ControlEvent { typealias __ActionHandler = @convention(block) (WKNavigationActionPolicy) -> () - let source:Observable = delegate + let source:Observable = navigationDelegate .methodInvoked(.decidePolicyNavigationAction).map { args in let view = try castOrThrow(WKWebView.self, args[0]) let action = try castOrThrow(WKNavigationAction.self, args[1])