diff --git a/MVMCoreUI/Atomic/Atoms/Views/WebView.swift b/MVMCoreUI/Atomic/Atoms/Views/WebView.swift index e6708055..d3a91920 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/WebView.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/WebView.swift @@ -170,8 +170,11 @@ extension WebView : WKNavigationDelegate { public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { //validate request url //all validated link should be open in safari - if (navigationAction.navigationType == .linkActivated), let urlString = navigationAction.request.url?.absoluteString.removingPercentEncoding, !urlString.contains("#") { - MVMCoreActionHandler.shared()?.openURL(inWebView: navigationAction.request.url, actionInformation: nil, additionalData: nil, delegateObject: nil) + if (navigationAction.navigationType == .linkActivated), + let url = navigationAction.request.url, + let urlString = url.absoluteString.removingPercentEncoding, + !urlString.contains("#") { + MVMCoreUIActionHandler.shared()?.openURL(inSafariWebView: url) decisionHandler(.cancel) } else { decisionHandler(.allow) diff --git a/MVMCoreUI/Atomic/Templates/TemplateModel.swift b/MVMCoreUI/Atomic/Templates/TemplateModel.swift index 45c2ed1a..27cb3183 100644 --- a/MVMCoreUI/Atomic/Templates/TemplateModel.swift +++ b/MVMCoreUI/Atomic/Templates/TemplateModel.swift @@ -58,10 +58,16 @@ import Foundation //-------------------------------------------------- // MARK: - Codec //-------------------------------------------------- + + open class func defaultPageType() -> String? { return nil } required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - pageType = try typeContainer.decode(String.self, forKey: .pageType) + if let defaultPageType = Self.defaultPageType() { + pageType = try typeContainer.decodeIfPresent(String.self, forKey: .pageType) ?? defaultPageType + } else { + pageType = try typeContainer.decode(String.self, forKey: .pageType) + } screenHeading = try typeContainer.decodeIfPresent(String.self, forKey: .screenHeading) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) formRules = try typeContainer.decodeIfPresent([FormGroupRule].self, forKey: .formRules) diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIActionHandler.h b/MVMCoreUI/OtherHandlers/MVMCoreUIActionHandler.h index c1dee62a..4c1afd45 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIActionHandler.h +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIActionHandler.h @@ -27,6 +27,9 @@ NS_ASSUME_NONNULL_BEGIN // Shows a topnotification new molecular - (void)topNotificationAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; +/// Legacy in app safari webview load +- (void)openURLInSafariWebView:(nonnull NSURL *)url; + @end NS_ASSUME_NONNULL_END diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIActionHandler.m b/MVMCoreUI/OtherHandlers/MVMCoreUIActionHandler.m index 3673d99e..fb7fe919 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIActionHandler.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIActionHandler.m @@ -15,6 +15,7 @@ @import MVMCore.NSDictionary_MFConvenience; @import MVMCore.MVMCoreJSONConstants; @import MVMCore.MVMCoreCache; +@import SafariServices; @implementation MVMCoreUIActionHandler @@ -122,4 +123,11 @@ } } +- (void)openURLInSafariWebView:(nonnull NSURL *)url { + SFSafariViewController *safariViewController = [[SFSafariViewController alloc] initWithURL:url]; + safariViewController.preferredBarTintColor = [UIColor whiteColor]; + safariViewController.preferredControlTintColor = [UIColor blackColor]; + [[MVMCoreNavigationHandler sharedNavigationHandler] presentViewController:safariViewController animated:YES]; +} + @end