Skip to content

Commit 66737bc

Browse files
authored
Merge pull request #15 from OutSystems/feat/RMET-4122/navigation-completed-event
RMET-4122 ::: Add onBrowserPageNavigationCompleted event
2 parents 480caaf + ca805eb commit 66737bc

File tree

8 files changed

+39
-11
lines changed

8 files changed

+39
-11
lines changed

OSInAppBrowserLib/RouterAdapters/OSIABApplicationRouterAdapter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public protocol OSIABApplicationDelegate: AnyObject {
99

1010
/// Provide a default implementations that abstracts the options parameter.
1111
extension OSIABApplicationDelegate {
12-
func open(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey: Any] = [:], completionHandler completion: ((Bool) -> Void)?) {
12+
public func open(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey: Any] = [:], completionHandler completion: ((Bool) -> Void)?) {
1313
self.open(url, options: options, completionHandler: completion)
1414
}
1515
}

OSInAppBrowserLib/WebView/OSIABWebViewCallbackHandler.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ public struct OSIABWebViewCallbackHandler {
1010
let onBrowserPageLoad: () -> Void
1111
/// Callback to trigger when the browser is closed. The boolean arguments indicates if the browser was already close or still needs to be.
1212
let onBrowserClosed: (Bool) -> Void
13-
13+
/// Callback to trigger when the browser finishes navigation. The argument is the current URL.
14+
let onBrowserPageNavigationCompleted: (String?) -> Void
15+
1416
/// Constructor method.
1517
/// - Parameters:
1618
/// - onDelegateURL: Callback to trigger when the an URL needs to be delegates to its callers.
@@ -21,11 +23,13 @@ public struct OSIABWebViewCallbackHandler {
2123
onDelegateURL: @escaping (URL) -> Void,
2224
onDelegateAlertController: @escaping (UIAlertController) -> Void,
2325
onBrowserPageLoad: @escaping () -> Void,
24-
onBrowserClosed: @escaping (Bool) -> Void // boolean indicates if the browser is already closed.
26+
onBrowserClosed: @escaping (Bool) -> Void, // boolean indicates if the browser is already closed.
27+
onBrowserPageNavigationCompleted: @escaping (String?) -> Void
2528
) {
2629
self.onDelegateURL = onDelegateURL
2730
self.onDelegateAlertController = onDelegateAlertController
2831
self.onBrowserPageLoad = onBrowserPageLoad
2932
self.onBrowserClosed = onBrowserClosed
33+
self.onBrowserPageNavigationCompleted = onBrowserPageNavigationCompleted
3034
}
3135
}

OSInAppBrowserLib/WebView/OSIABWebViewModel.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ extension OSIABWebViewModel: WKNavigationDelegate {
182182
if !self.firstLoadDone {
183183
self.callbackHandler.onBrowserPageLoad()
184184
self.firstLoadDone = true
185+
} else {
186+
self.callbackHandler.onBrowserPageNavigationCompleted(url.absoluteString)
185187
}
186188
error = nil
187189
}

OSInAppBrowserLib/WebView/Views/OSIABWebView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ private extension OSIABWebViewModel {
9696
onDelegateURL: { _ in },
9797
onDelegateAlertController: { _ in },
9898
onBrowserPageLoad: {},
99-
onBrowserClosed: onBrowserClosed
99+
onBrowserClosed: onBrowserClosed,
100+
onBrowserPageNavigationCompleted: { _ in }
100101
)
101102
)
102103
}

OSInAppBrowserLib/WebView/Views/OSIABWebView13WrapperView.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ private extension OSIABWebViewModel {
5858
onDelegateURL: { _ in },
5959
onDelegateAlertController: { _ in },
6060
onBrowserPageLoad: {},
61-
onBrowserClosed: { _ in }
61+
onBrowserClosed: { _ in },
62+
onBrowserPageNavigationCompleted: { _ in }
6263
)
6364
)
6465
}
@@ -73,7 +74,8 @@ private extension OSIABWebViewModel {
7374
onDelegateURL: { _ in },
7475
onDelegateAlertController: { _ in },
7576
onBrowserPageLoad: {},
76-
onBrowserClosed: { _ in }
77+
onBrowserClosed: { _ in },
78+
onBrowserPageNavigationCompleted: { _ in }
7779
)
7880
)
7981
}

OSInAppBrowserLib/WebView/Views/OSIABWebViewWrapperView.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ private extension OSIABWebViewModel {
3535
onDelegateURL: { _ in },
3636
onDelegateAlertController: { _ in },
3737
onBrowserPageLoad: {},
38-
onBrowserClosed: { _ in }
38+
onBrowserClosed: { _ in },
39+
onBrowserPageNavigationCompleted: { _ in }
3940
)
4041
)
4142
}
@@ -50,7 +51,8 @@ private extension OSIABWebViewModel {
5051
onDelegateURL: { _ in },
5152
onDelegateAlertController: { _ in },
5253
onBrowserPageLoad: {},
53-
onBrowserClosed: { _ in }
54+
onBrowserClosed: { _ in },
55+
onBrowserPageNavigationCompleted: { _ in }
5456
)
5557
)
5658
}

OSInAppBrowserLibTests/OSIABViewModelTests.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,20 @@ final class OSIABViewModelTests: XCTestCase {
181181
XCTAssertEqual(resultAction, .allow)
182182
}
183183

184+
func test_navigateToNewPage_onBrowserPageNavigationCompletedEventShouldBeTrigged() {
185+
var result: String? = nil
186+
let expectation = self.expectation(description: "Trigger onBrowserPageNavigationCompleted Event")
187+
188+
let sut = makeSUT(url, onBrowserPageNavigationCompleted: { data in
189+
result = data
190+
expectation.fulfill()
191+
})
192+
sut.webView(sut.webView, didFinish: nil)
193+
sut.webView(sut.webView, didFinish: nil)
194+
waitForExpectations(timeout: 1)
195+
XCTAssertEqual(url.absoluteString, result)
196+
}
197+
184198
// MARK: Browser Page Load Event Tests
185199

186200
func test_navigateToURL_whenFinished_triggerPageLoadEventOnFirstTime() {
@@ -275,7 +289,8 @@ private extension OSIABViewModelTests {
275289
onDelegateURL: @escaping (URL) -> Void = { _ in },
276290
onDelegateAlertController: @escaping (UIAlertController) -> Void = { _ in },
277291
onBrowserPageLoad: @escaping () -> Void = {},
278-
onBrowserClosed: @escaping (Bool) -> Void = { _ in }
292+
onBrowserClosed: @escaping (Bool) -> Void = { _ in },
293+
onBrowserPageNavigationCompleted: @escaping (String?) -> Void = { _ in }
279294
) -> OSIABWebViewModel {
280295
let configurationModel = OSIABWebViewConfigurationModel(
281296
mediaTypesRequiringUserActionForPlayback, ignoresViewportScaleLimits, allowsInlineMediaPlayback, surpressesIncrementalRendering
@@ -297,7 +312,8 @@ private extension OSIABViewModelTests {
297312
onDelegateURL: onDelegateURL,
298313
onDelegateAlertController: onDelegateAlertController,
299314
onBrowserPageLoad: onBrowserPageLoad,
300-
onBrowserClosed: onBrowserClosed
315+
onBrowserClosed: onBrowserClosed,
316+
onBrowserPageNavigationCompleted: onBrowserPageNavigationCompleted
301317
)
302318
)
303319
}

OSInAppBrowserLibTests/OSIABWebViewRouterAdapterTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ private extension OSIABWebViewRouterAdapterTests {
141141
onDelegateURL: { _ in },
142142
onDelegateAlertController: { _ in },
143143
onBrowserPageLoad: {},
144-
onBrowserClosed: onBrowserClosed
144+
onBrowserClosed: onBrowserClosed,
145+
onBrowserPageNavigationCompleted: { _ in }
145146
)
146147
)
147148
}

0 commit comments

Comments
 (0)