Created
December 18, 2019 21:38
-
-
Save mattlaver/45519a58de65a304b10acaee663b06a2 to your computer and use it in GitHub Desktop.
This file contains 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
final internal class ChildView: NSObject, View, WKNavigationDelegate, UIViewRepresentable { | |
var _loginWebView: WKWebView! | |
func webView(_ _webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: (WKNavigationResponsePolicy) -> Void) { | |
guard ((navigationResponse.response as? HTTPURLResponse)?.statusCode) != nil else { | |
decisionHandler(.allow) | |
return | |
} | |
decisionHandler(.allow) | |
} | |
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: (WKNavigationActionPolicy) -> Void) { | |
guard let returnUrl = (webView.url?.absoluteString) else { | |
decisionHandler(.cancel) | |
return | |
} | |
if (returnUrl.contains("my-identifier") ) { | |
/* raise event here */ | |
} | |
decisionHandler(.allow) | |
} | |
func makeUIView(context: Context) -> WKWebView { | |
_loginWebView = WKWebView(frame: .zero) | |
_loginWebView.navigationDelegate = self | |
return _loginWebView | |
} | |
func updateUIView(_ uiView: WKWebView, context: Context) { | |
let request = // build a request... | |
_loginWebView.load(request) | |
} | |
} |
This file contains 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
import SwiftUI | |
import Combine | |
struct LoginHostView : View { | |
@Binding var showView : Bool | |
var body: some View { | |
VStack{ | |
HStack{ | |
Button(action: { | |
self.showView = false | |
}){ | |
Text("back") | |
} | |
Spacer() | |
} | |
if (self.settings.nowPlaying.isLoggedIn){ | |
Button(action: { | |
self.showView = false | |
}){ | |
Text("You are logged in!") | |
} | |
} | |
else { | |
LoginView() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment