Skip to content

Commit

Permalink
feat: 웹 디버깅용 개발 (#67)
Browse files Browse the repository at this point in the history
* feat: 웹 디버깅용 개발

* fix: 일부 수정
  • Loading branch information
SongSeoYoung committed Jul 15, 2023
1 parent 8e677e7 commit 3f8f29c
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 37 deletions.
3 changes: 3 additions & 0 deletions App/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down
6 changes: 5 additions & 1 deletion App/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
10 changes: 9 additions & 1 deletion App/Sources/Root/RootBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
//

import RIBs
import MOITWebImpl
import MOITWeb

final class RootComponent: EmptyDependency, MOITWebDependency{

}
// MARK: - Builder

protocol RootBuildable: Buildable {
Expand All @@ -22,12 +27,15 @@ final class RootBuilder: Builder<EmptyDependency>, 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
)
}
}
25 changes: 25 additions & 0 deletions App/Sources/Root/RootInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -37,5 +41,26 @@ final class RootInteractor: PresentableInteractor<RootPresentable>,
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)
}
}
36 changes: 33 additions & 3 deletions App/Sources/Root/RootRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
//

import RIBs
import MOITWeb
import MOITWebImpl

protocol RootInteractable: Interactable {
protocol RootInteractable: Interactable,
MOITWebListener {
var router: RootRouting? { get set }
}

Expand All @@ -17,13 +20,40 @@ protocol RootViewControllable: ViewControllable {
final class RootRouter: LaunchRouter<RootInteractable, RootViewControllable>,
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)
}
}
98 changes: 97 additions & 1 deletion App/Sources/Root/RootViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,116 @@
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,
RootPresentable,
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
var id = self?.modifyTextField.text ?? ""
if id.isEmpty { id = "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)
}
}
}
4 changes: 2 additions & 2 deletions Config/Debug.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
SWIFT_OPTIMIZATION_LEVEL[config=Release]=-Owholemodule
4 changes: 2 additions & 2 deletions Config/Release.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
SWIFT_OPTIMIZATION_LEVEL[config=Release]=-Owholemodule
2 changes: 1 addition & 1 deletion Features/MOITWeb/Implement/MOITWebBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public final class MOITWebBuilder: Builder<MOITWebDependency>,
let viewController = MOITWebViewController()
let interactor = MOITWebInteractor(
presenter: viewController,
path: path.rawValue
path: path.path
)
interactor.listener = listener

Expand Down
27 changes: 23 additions & 4 deletions Features/MOITWeb/Implement/MOITWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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)
}
Expand All @@ -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"
])
}

Expand Down Expand Up @@ -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)
}
}

Expand Down
18 changes: 14 additions & 4 deletions Features/MOITWeb/Interface/MOITWebPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Loading

0 comments on commit 3f8f29c

Please sign in to comment.