Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐Ÿ”€ :: [#145] ํšŒ์›๊ฐ€์ž…, ๋น„๋ฐ€๋ฒˆํ˜ธ ์ฐพ๊ธฐ์—์„œ ๋กœ๊ทธ์ธ URL์— ์ ‘๊ทผ ์‹œ ๋กœ๊ทธ์ธ ํ™”๋ฉด์œผ๋กœ ์ „ํ™˜ #146

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
)
}
}
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