Created
April 29, 2020 16:24
-
-
Save prafullakumar/a625f9e4c5ee55c6c1692914df43a58c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WebViewStateModel: ObservableObject { | |
@Published var pageTitle: String = "Web View" | |
@Published var loading: Bool = false | |
@Published var canGoBack: Bool = false | |
@Published var goBack: Bool = false | |
} | |
struct WebView: View { | |
enum NavigationAction { | |
case decidePolicy(WKNavigationAction, (WKNavigationActionPolicy) -> Void) //mendetory | |
case didRecieveAuthChallange(URLAuthenticationChallenge, (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) //mendetory | |
case didStartProvisionalNavigation(WKNavigation) | |
case didReceiveServerRedirectForProvisionalNavigation(WKNavigation) | |
case didCommit(WKNavigation) | |
case didFinish(WKNavigation) | |
case didFailProvisionalNavigation(WKNavigation,Error) | |
case didFail(WKNavigation,Error) | |
} | |
@ObservedObject var webViewStateModel: WebViewStateModel | |
private var actionDelegate: ((_ navigationAction: WebView.NavigationAction) -> Void)? | |
let uRLRequest: URLRequest | |
var body: some View { | |
WebViewWrapper(webViewStateModel: webViewStateModel, | |
action: actionDelegate, | |
request: uRLRequest) | |
} | |
/* | |
if passed onNavigationAction it is mendetory to complete URLAuthenticationChallenge and decidePolicyFor callbacks | |
*/ | |
init(uRLRequest: URLRequest, webViewStateModel: WebViewStateModel, onNavigationAction: ((_ navigationAction: WebView.NavigationAction) -> Void)?) { | |
self.uRLRequest = uRLRequest | |
self.webViewStateModel = webViewStateModel | |
self.actionDelegate = onNavigationAction | |
} | |
init(url: URL, webViewStateModel: WebViewStateModel, onNavigationAction: ((_ navigationAction: WebView.NavigationAction) -> Void)? = nil) { | |
self.init(uRLRequest: URLRequest(url: url), | |
webViewStateModel: webViewStateModel, | |
onNavigationAction: onNavigationAction) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment