Skip to content

Commit

Permalink
✨ :: [#145] SigninMoordinator / 웹뷰에서 signin url에 접근 시 popViewControll…
Browse files Browse the repository at this point in the history
…er 실행
  • Loading branch information
baekteun committed Aug 2, 2023
1 parent b4fc22b commit 4df6255
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import Moordinator
import UIKit

public protocol RenewalPasswordFactory {
func makeViewController() -> UIViewController
func makeViewController(signinHandler: @escaping () -> Void) -> UIViewController
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import Moordinator
import UIKit

struct RenewalPasswordFactoryImpl: RenewalPasswordFactory {
func makeViewController() -> UIViewController {
func makeViewController(signinHandler: @escaping () -> Void) -> UIViewController {
let url = "https://www.dotori-gsm.com/changePasswd"

return DWebViewController(
urlString: url
urlString: url,
detectHandler: signinHandler
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ final class SigninMoordinator: Moordinator {
)

case .signup:
let viewController = signupFactory.makeViewController()
let viewController = signupFactory.makeViewController { [rootVC] in
print("ASD")
rootVC.popViewController(animated: true)
}
rootVC.pushViewController(viewController, animated: true)
return .one(.contribute(withNextPresentable: viewController))

case .renewalPassword:
let viewController = renewalPasswordFactory.makeViewController()
let viewController = renewalPasswordFactory.makeViewController { [rootVC] in
print("ASD")
rootVC.popViewController(animated: true)
}
rootVC.pushViewController(viewController, animated: true)
return .one(.contribute(withNextPresentable: viewController))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import UIKit
import Moordinator

public protocol SignupFactory {
func makeViewController() -> UIViewController
func makeViewController(signinHandler: @escaping () -> Void) -> UIViewController
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import DWebKit
import UIKit

struct SignupFactoryImpl: SignupFactory {
func makeViewController() -> UIViewController {
func makeViewController(signinHandler: @escaping () -> Void) -> UIViewController {
let url = "https://www.dotori-gsm.com/signup"

return DWebViewController(
urlString: url
urlString: url,
detectHandler: signinHandler
)
}
}
18 changes: 17 additions & 1 deletion Projects/UserInterface/DWebKit/Sources/DWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ public final class DWebViewController: UIViewController, WKNavigationDelegate {
// MARK: - Properties
private let urlString: String
private let wkWebView: WKWebView
private let detectKeyword: String
private let detectHandler: () -> Void
private var urlObservation: NSKeyValueObservation?

// MARK: - Init
public init(urlString: String, tokenDTO: LocalStorageTokenDTO? = nil) {
public init(
urlString: String,
tokenDTO: LocalStorageTokenDTO? = nil,
detectKeyword: String = "signin",
detectHandler: @escaping () -> Void = {}
) {
let preferences = WKPreferences()
preferences.javaScriptCanOpenWindowsAutomatically = true

Expand All @@ -18,6 +26,8 @@ public final class DWebViewController: UIViewController, WKNavigationDelegate {
wkWebView.translatesAutoresizingMaskIntoConstraints = false
self.wkWebView = wkWebView
self.urlString = urlString
self.detectKeyword = detectKeyword
self.detectHandler = detectHandler
super.init(nibName: nil, bundle: nil)
if let tokenDTO {
setAccessToken(tokenDTO: tokenDTO, configuration: wkWebView.configuration)
Expand Down Expand Up @@ -47,6 +57,12 @@ public final class DWebViewController: UIViewController, WKNavigationDelegate {
let request = URLRequest(url: url)
self.wkWebView.load(request)
}
urlObservation = wkWebView.observe(\.url, options: .new) { [detectKeyword, detectHandler] webView, _ in
guard let url = webView.url?.absoluteString, url.contains(detectKeyword) else {
return
}
detectHandler()
}
}
}

Expand Down

0 comments on commit 4df6255

Please sign in to comment.