From 2617cc27fadb13b8266c7f9a985551d2e45badbc Mon Sep 17 00:00:00 2001 From: SongSeoYoung Date: Sat, 15 Jul 2023 16:11:06 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=EC=9B=B9=20=EB=94=94=EB=B2=84?= =?UTF-8?q?=EA=B9=85=EC=9A=A9=20=EA=B0=9C=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Project.swift | 3 + App/Sources/AppDelegate.swift | 6 +- App/Sources/Root/RootBuilder.swift | 10 +- App/Sources/Root/RootInteractor.swift | 25 +++++ App/Sources/Root/RootRouter.swift | 36 ++++++- App/Sources/Root/RootViewController.swift | 97 ++++++++++++++++++- Config/Debug.xcconfig | 4 +- Config/Release.xcconfig | 4 +- .../MOITWeb/Implement/MOITWebBuilder.swift | 2 +- .../Implement/MOITWebViewController.swift | 27 +++++- Features/MOITWeb/Interface/MOITWebPath.swift | 18 +++- Scripts/SwiftLintRunScript.sh | 36 +++---- 12 files changed, 231 insertions(+), 37 deletions(-) diff --git a/App/Project.swift b/App/Project.swift index b3b7581a..fe241883 100644 --- a/App/Project.swift +++ b/App/Project.swift @@ -46,6 +46,9 @@ let project = Project( dependencies: [ .ThirdParty.RIBs, .ThirdParty.SkeletonView, + .Feature.MOITWeb.Implement, + .ThirdParty.RxCocoa, + .ThirdParty.RxSwift ], settings: .settings(configurations: [ .debug(name: "Debug", xcconfig: .relativeToRoot("Config/Debug.xcconfig")), diff --git a/App/Sources/AppDelegate.swift b/App/Sources/AppDelegate.swift index aa1b307a..8c333038 100644 --- a/App/Sources/AppDelegate.swift +++ b/App/Sources/AppDelegate.swift @@ -27,7 +27,11 @@ final class AppDelegate: UIResponder, let router = RootBuilder(dependency: EmptyComponent()).build() self.launchRouter = router - self.launchRouter?.launch(from: window) + window.rootViewController = UINavigationController(rootViewController: router.viewControllable.uiviewController) + window.makeKeyAndVisible() + + router.interactable.activate() + router.load() return true } } diff --git a/App/Sources/Root/RootBuilder.swift b/App/Sources/Root/RootBuilder.swift index da1f9356..7c9e18cb 100644 --- a/App/Sources/Root/RootBuilder.swift +++ b/App/Sources/Root/RootBuilder.swift @@ -6,7 +6,12 @@ // import RIBs +import MOITWebImpl +import MOITWeb +final class RootComponent: EmptyDependency, MOITWebDependency{ + +} // MARK: - Builder protocol RootBuildable: Buildable { @@ -22,12 +27,15 @@ final class RootBuilder: Builder, RootBuildable { deinit { debugPrint("\(self) deinit") } func build() -> LaunchRouting { + let component = RootComponent() let viewController = RootViewController() let interactor = RootInteractor(presenter: viewController) + let webBuilder = MOITWebBuilder(dependency: component) return RootRouter( interactor: interactor, - viewController: viewController + viewController: viewController, + moitWebBuilder: webBuilder ) } } diff --git a/App/Sources/Root/RootInteractor.swift b/App/Sources/Root/RootInteractor.swift index 4bd18a38..e2e9b812 100644 --- a/App/Sources/Root/RootInteractor.swift +++ b/App/Sources/Root/RootInteractor.swift @@ -7,8 +7,12 @@ import RIBs import RxSwift +import MOITWebImpl +import MOITWeb protocol RootRouting: ViewableRouting { + func routeToMoitWeb(path: MOITWebPath) + func detachWeb(withPop: Bool) } protocol RootPresentable: Presentable { @@ -37,5 +41,26 @@ final class RootInteractor: PresentableInteractor, super.willResignActive() } + func didTapCreateButton() { + self.router?.routeToMoitWeb(path: .register) + } + + func didTapAttendanceButton() { + self.router?.routeToMoitWeb(path: .attendance) + } + + func didTapModifyButton(id: String) { + self.router?.routeToMoitWeb(path: .modify(id: id)) + } + + func didTapAttendanceResultButton() { + self.router?.routeToMoitWeb(path: .attendanceResult) + } deinit { debugPrint("\(self) deinit") } } + +extension RootInteractor { + func shouldDetach(withPop: Bool) { + self.router?.detachWeb(withPop: withPop) + } +} diff --git a/App/Sources/Root/RootRouter.swift b/App/Sources/Root/RootRouter.swift index d361b1c2..c98096d8 100644 --- a/App/Sources/Root/RootRouter.swift +++ b/App/Sources/Root/RootRouter.swift @@ -6,8 +6,11 @@ // import RIBs +import MOITWeb +import MOITWebImpl -protocol RootInteractable: Interactable { +protocol RootInteractable: Interactable, + MOITWebListener { var router: RootRouting? { get set } } @@ -17,13 +20,40 @@ protocol RootViewControllable: ViewControllable { final class RootRouter: LaunchRouter, RootRouting { - override init( + init( interactor: RootInteractable, - viewController: RootViewControllable + viewController: RootViewControllable, + moitWebBuilder: MOITWebBuildable ) { + self.moitWebBuilder = moitWebBuilder super.init(interactor: interactor, viewController: viewController) interactor.router = self } deinit { debugPrint("\(self) deinit") } + + private let moitWebBuilder: MOITWebBuildable + private var moitWebRouter: ViewableRouting? + + func routeToMoitWeb(path: MOITWebPath) { + guard self.moitWebRouter == nil else { return } + let router = moitWebBuilder.build( + withListener: self.interactor, + path: path + ) + + self.viewController.uiviewController.navigationController?.pushViewController(router.viewControllable.uiviewController, animated: true) + self.moitWebRouter = router + self.attachChild(router) + } + + func detachWeb(withPop: Bool) { + guard let moitWebRouter else { return } + if withPop { + self.viewController.uiviewController.navigationController?.popViewController(animated: true) + } + + self.moitWebRouter = nil + self.detachChild(moitWebRouter) + } } diff --git a/App/Sources/Root/RootViewController.swift b/App/Sources/Root/RootViewController.swift index 18a4313a..79963607 100644 --- a/App/Sources/Root/RootViewController.swift +++ b/App/Sources/Root/RootViewController.swift @@ -8,8 +8,15 @@ import RIBs import RxSwift import UIKit +import FlexLayout +import PinLayout +import RxCocoa protocol RootPresentableListener: AnyObject { + func didTapCreateButton() + func didTapAttendanceButton() + func didTapModifyButton(id: String) + func didTapAttendanceResultButton() } final class RootViewController: UIViewController, @@ -17,11 +24,99 @@ final class RootViewController: UIViewController, RootViewControllable { weak var listener: RootPresentableListener? + private let flexrootView = UIView() + private let moitCreateButton = UIButton() + private let attendancesButton = UIButton() + private let modifyTextField = UITextField() + private let modifyButton = UIButton() + private let attendanceResultButton = UIButton() + private let label = UILabel() + private let tokenLabel = UILabel() + private let diseposeBag = DisposeBag() + + override func loadView() { + self.view = flexrootView + } override func viewDidLoad() { super.viewDidLoad() - self.view.backgroundColor = .red + self.flexrootView.backgroundColor = .white + self.label.text = "웹분들 여기예용 😲💖 화이팅! 전자군단🤖" + self.tokenLabel.numberOfLines = 0 + self.tokenLabel.text = """ +토큰은 아래를 넘깁니다. +Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJqd3QtdXNlci1kZWZhdWx0IiwiYXVkIjoiYXV0aDB8YWJjQG5hdmVyLmNvbXw3fGRlZmF1bHQiLCJpc3MiOiJodHRwczovL2dpdGh1Yi5jb20vbWFzaC11cC1rci9NT0lULWJhY2tlbmQiLCJpYXQiOjE2ODg4ODkyOTMsImV4cCI6MTY5MTQ4MTI5MywiaW5mbyI6eyJpZCI6NywicHJvdmlkZXJVbmlxdWVLZXkiOiJhdXRoMHxhYmNAbmF2ZXIuY29tIiwibmlja25hbWUiOiJkZWZhdWx0IiwicHJvZmlsZUltYWdlIjowLCJlbWFpbCI6ImFiY0BuYXZlci5jb20iLCJyb2xlcyI6WyJVU0VSIl19fQ.o9WjiGqNOZSkHGDKQ54b50TUEy-oWvPo1-5Egjw1HXc +""" + self.label.textAlignment = .center + modifyTextField.layer.borderColor = UIColor.black.cgColor + modifyTextField.layer.borderWidth = 1 + moitCreateButton.setTitle("모잇생성 진입점", for: .normal) + attendancesButton.setTitle("출석하기 진입점", for: .normal) + modifyButton.setTitle("모잇 수정하기 진입점(아이디안적을시에2번으로수정됨)", for: .normal) + attendanceResultButton.setTitle("출석결과 진입점", for: .normal) + moitCreateButton.rx.tap + .bind(onNext: { [weak self] _ in + self?.listener?.didTapCreateButton() + }) + .disposed(by: diseposeBag) + + attendancesButton.rx.tap + .bind(onNext: { [weak self] _ in + self?.listener?.didTapAttendanceButton() + }) + .disposed(by: diseposeBag) + + modifyButton.rx.tap + .bind(onNext: { [weak self] _ in + let id = self?.modifyTextField.text ?? "2" + self?.listener?.didTapModifyButton(id: id) + }) + .disposed(by: self.diseposeBag) + + attendanceResultButton.rx.tap + .bind(onNext: { [weak self] _ in + self?.listener?.didTapAttendanceResultButton() + }) + .disposed(by: self.diseposeBag) + + moitCreateButton.setTitleColor(.black, for: .normal) + attendancesButton.setTitleColor(.black, for: .normal) + modifyButton.setTitleColor(.black, for: .normal) + attendanceResultButton.setTitleColor(.black, for: .normal) + define() + } + + override func viewDidLayoutSubviews() { + super.viewDidLayoutSubviews() + self.flexrootView.pin.all() + self.flexrootView.flex.layout() } deinit { debugPrint("\(self) deinit") } + + private func define() { + self.flexrootView.flex.define { flex in + flex.addItem(self.label) + .marginTop(100) + flex.addItem() + .backgroundColor(.black) + .height(5) + flex.addItem(tokenLabel) + .marginTop(10) + flex.addItem() + .backgroundColor(.black) + .height(5) + flex.addItem(moitCreateButton) + .marginTop(20) + flex.addItem(attendancesButton) + .marginTop(20) + flex.addItem(modifyTextField) + .marginTop(20) + .marginHorizontal(50) + flex.addItem(modifyButton) + .marginTop(20) + flex.addItem(attendanceResultButton) + .marginTop(20) + } + } } diff --git a/Config/Debug.xcconfig b/Config/Debug.xcconfig index ace9ae2a..b0d9b9fd 100644 --- a/Config/Debug.xcconfig +++ b/Config/Debug.xcconfig @@ -3,7 +3,7 @@ CODE_SIGN_IDENTITY=Apple Development: Chansoo Kim (T7MYKWLF92) CODE_SIGN_STYLE=Manual DEVELOPMENT_TEAM=4NV4Z6BW27 ENABLE_PREVIEWS=YES -IPHONEOS_DEPLOYMENT_TARGET=15.0 +IPHONEOS_DEPLOYMENT_TARGET=16.0 OTHER_LDFLAGS=-ObjC PRODUCT_BUNDLE_IDENTIFIER=com.chansoo.MOIT PRODUCT_NAME=MOIT @@ -19,4 +19,4 @@ SWIFT_ACTIVE_COMPILATION_CONDITIONS[config=Debug]=DEBUG SWIFT_COMPILATION_MODE[config=Debug]=singlefile SWIFT_COMPILATION_MODE[config=Release]=wholemodule SWIFT_OPTIMIZATION_LEVEL[config=Debug]=-Onone -SWIFT_OPTIMIZATION_LEVEL[config=Release]=-Owholemodule \ No newline at end of file +SWIFT_OPTIMIZATION_LEVEL[config=Release]=-Owholemodule diff --git a/Config/Release.xcconfig b/Config/Release.xcconfig index b230af2c..f73ee344 100644 --- a/Config/Release.xcconfig +++ b/Config/Release.xcconfig @@ -3,7 +3,7 @@ CODE_SIGN_IDENTITY=Apple Development: Chansoo Kim (T7MYKWLF92) CODE_SIGN_STYLE=Manual DEVELOPMENT_TEAM=4NV4Z6BW27 ENABLE_PREVIEWS=YES -IPHONEOS_DEPLOYMENT_TARGET=15.0 +IPHONEOS_DEPLOYMENT_TARGET=16.0 OTHER_LDFLAGS=-ObjC PRODUCT_BUNDLE_IDENTIFIER=com.chansoo.MOIT PRODUCT_NAME=MOIT @@ -19,4 +19,4 @@ SWIFT_ACTIVE_COMPILATION_CONDITIONS[config=Debug]=DEBUG SWIFT_COMPILATION_MODE[config=Debug]=singlefile SWIFT_COMPILATION_MODE[config=Release]=wholemodule SWIFT_OPTIMIZATION_LEVEL[config=Debug]=-Onone -SWIFT_OPTIMIZATION_LEVEL[config=Release]=-Owholemodule \ No newline at end of file +SWIFT_OPTIMIZATION_LEVEL[config=Release]=-Owholemodule diff --git a/Features/MOITWeb/Implement/MOITWebBuilder.swift b/Features/MOITWeb/Implement/MOITWebBuilder.swift index 60645e69..eeaac7e0 100644 --- a/Features/MOITWeb/Implement/MOITWebBuilder.swift +++ b/Features/MOITWeb/Implement/MOITWebBuilder.swift @@ -32,7 +32,7 @@ public final class MOITWebBuilder: Builder, let viewController = MOITWebViewController() let interactor = MOITWebInteractor( presenter: viewController, - path: path.rawValue + path: path.path ) interactor.listener = listener diff --git a/Features/MOITWeb/Implement/MOITWebViewController.swift b/Features/MOITWeb/Implement/MOITWebViewController.swift index e7bc7011..713725eb 100644 --- a/Features/MOITWeb/Implement/MOITWebViewController.swift +++ b/Features/MOITWeb/Implement/MOITWebViewController.swift @@ -24,7 +24,7 @@ final class MOITWebViewController: UIViewController, static let messageName = "MOIT" // TODO: 합의 후 수정 필요 - static let domain = "https://entertain.naver.com" + static let domain = "https://dev-moit-web.vercel.app" } weak var listener: MOITWebPresentableListener? @@ -57,6 +57,7 @@ extension MOITWebViewController { self.view.addSubview(webView) guard let url = URL(string: "\(Self.Constant.domain)\(path)") else { return } + print(url) let URLRequest = URLRequest(url: url) webView.load(URLRequest) } @@ -70,8 +71,8 @@ extension MOITWebViewController { HTTPCookie(properties: [ .domain: Self.Constant.domain, .path: path, - .name: "accessToken", // TODO: 합의 후 수정 필요 - .value: "어딘가에서 가지고 온 토큰값" // TODO: 합의 후 수정 필요 + .name: "accessToken", + .value: "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJqd3QtdXNlci1kZWZhdWx0IiwiYXVkIjoiYXV0aDB8YWJjQG5hdmVyLmNvbXw3fGRlZmF1bHQiLCJpc3MiOiJodHRwczovL2dpdGh1Yi5jb20vbWFzaC11cC1rci9NT0lULWJhY2tlbmQiLCJpYXQiOjE2ODg4ODkyOTMsImV4cCI6MTY5MTQ4MTI5MywiaW5mbyI6eyJpZCI6NywicHJvdmlkZXJVbmlxdWVLZXkiOiJhdXRoMHxhYmNAbmF2ZXIuY29tIiwibmlja25hbWUiOiJkZWZhdWx0IiwicHJvZmlsZUltYWdlIjowLCJlbWFpbCI6ImFiY0BuYXZlci5jb20iLCJyb2xlcyI6WyJVU0VSIl19fQ.o9WjiGqNOZSkHGDKQ54b50TUEy-oWvPo1-5Egjw1HXc" ]) } @@ -99,12 +100,30 @@ extension MOITWebViewController { // MARK: - WKScriptMessageHandler +enum Command: String { + case toast + case back + case alert + case keypad + case share +} + extension MOITWebViewController: WKScriptMessageHandler { func userContentController( _ userContentController: WKUserContentController, didReceive message: WKScriptMessage ) { - print(#function, message) + guard message.name == Constant.messageName, + let messages = message.body as? [String: Any], + let cmd = messages["command"] as? String, + let command = Command(rawValue: cmd) else { return } + let value = messages["body"] + let alertController = UIAlertController( + title: "\(cmd)", + message: "\(value)", preferredStyle: .alert) + let okAction = UIAlertAction(title: "확인", style: .default) + alertController.addAction(okAction) + self.present(alertController, animated: true) } } diff --git a/Features/MOITWeb/Interface/MOITWebPath.swift b/Features/MOITWeb/Interface/MOITWebPath.swift index 984e6534..3cb04d19 100644 --- a/Features/MOITWeb/Interface/MOITWebPath.swift +++ b/Features/MOITWeb/Interface/MOITWebPath.swift @@ -8,8 +8,18 @@ import Foundation -public enum MOITWebPath: String { - // TODO: 추후 삭제 해야됩니다. - case tv = "/tv" - case movie = "/movie" +public enum MOITWebPath { + case register + case modify(id: String) + case attendance + case attendanceResult + + public var path: String { + switch self { + case .attendance: return "/attendance" + case .register: return "/register" + case .modify(let id): return "/register?id=\(id)" + case .attendanceResult: return "/attendanceResult" + } + } } diff --git a/Scripts/SwiftLintRunScript.sh b/Scripts/SwiftLintRunScript.sh index 9cb71e9c..d46adafb 100755 --- a/Scripts/SwiftLintRunScript.sh +++ b/Scripts/SwiftLintRunScript.sh @@ -1,18 +1,18 @@ -# #!/bin/sh - -# # SwiftLintRunScript.sh -# # Manifests -# # -# # Created by 김찬수 on 2023/04/28. -# # - -export PATH="$PATH:/usr/local/bin:/opt/homebrew/bin" -if which swiftlint >/dev/null; then - - DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" - - swiftlint --config "$DIR/.swiftlint.yml" 2>/dev/null || true - -else - echo "warning: SwiftLint not installed, download from" -fi +## #!/bin/sh +# +## # SwiftLintRunScript.sh +## # Manifests +## # +## # Created by 김찬수 on 2023/04/28. +## # +# +#export PATH="$PATH:/usr/local/bin:/opt/homebrew/bin" +#if which swiftlint >/dev/null; then +# +# DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" +# +# swiftlint --config "$DIR/.swiftlint.yml" 2>/dev/null || true +# +#else +# echo "warning: SwiftLint not installed, download from" +#fi From 6b561e603cee337062817309410810a1ae55face Mon Sep 17 00:00:00 2001 From: SongSeoYoung Date: Sat, 15 Jul 2023 16:14:49 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=EC=9D=BC=EB=B6=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Sources/Root/RootViewController.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/App/Sources/Root/RootViewController.swift b/App/Sources/Root/RootViewController.swift index 79963607..b6990ebc 100644 --- a/App/Sources/Root/RootViewController.swift +++ b/App/Sources/Root/RootViewController.swift @@ -68,7 +68,8 @@ Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJqd3QtdXNlci1kZWZhdWx0Iiwi modifyButton.rx.tap .bind(onNext: { [weak self] _ in - let id = self?.modifyTextField.text ?? "2" + var id = self?.modifyTextField.text ?? "" + if id.isEmpty { id = "2" } self?.listener?.didTapModifyButton(id: id) }) .disposed(by: self.diseposeBag) From 77566cb0e4e7464fb0037ca9f1e08f306ba1c69a Mon Sep 17 00:00:00 2001 From: SongSeoYoung Date: Sat, 15 Jul 2023 16:19:53 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20back=20->=20close=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Features/MOITWeb/Implement/MOITWebViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Features/MOITWeb/Implement/MOITWebViewController.swift b/Features/MOITWeb/Implement/MOITWebViewController.swift index 713725eb..df5ddb6c 100644 --- a/Features/MOITWeb/Implement/MOITWebViewController.swift +++ b/Features/MOITWeb/Implement/MOITWebViewController.swift @@ -102,7 +102,7 @@ extension MOITWebViewController { enum Command: String { case toast - case back + case close case alert case keypad case share