Skip to content

Commit

Permalink
Tutorial 1 completed
Browse files Browse the repository at this point in the history
  • Loading branch information
opendoorlife committed Jan 14, 2022
1 parent 5d7dd69 commit 0bdfb21
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 23 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,39 @@ protocol LoggedOutListener: AnyObject {

final class LoggedOutInteractor: PresentableInteractor<LoggedOutPresentable>, LoggedOutInteractable, LoggedOutPresentableListener {

weak var router: LoggedOutRouting?
weak var listener: LoggedOutListener?

// TODO: Add additional dependencies to constructor. Do not perform any logic
// in constructor.
override init(presenter: LoggedOutPresentable) {
super.init(presenter: presenter)
presenter.listener = self
}

override func didBecomeActive() {
super.didBecomeActive()
// TODO: Implement business logic here.
}

override func willResignActive() {
super.willResignActive()
// TODO: Pause any business logic.
weak var router: LoggedOutRouting?
weak var listener: LoggedOutListener?

// TODO: Add additional dependencies to constructor. Do not perform any logic
// in constructor.

func login(player1Name: String?, player2Name: String?) {
let player1NameWithDefault = playerName(player1Name, withDefaultName: "Player 1")
let player2NameWithDefault = playerName(player2Name, withDefaultName: "Player 2")
print("---> \(player1NameWithDefault) vs \(player2NameWithDefault)")
}

private func playerName(_ name: String?, withDefaultName defaultName: String) -> String {
if let name = name {
return name.isEmpty ? defaultName : name
} else {
return defaultName
}
}

override init(presenter: LoggedOutPresentable) {
super.init(presenter: presenter)
presenter.listener = self
}

override func didBecomeActive() {
super.didBecomeActive()
// TODO: Implement business logic here.
}

override func willResignActive() {
super.willResignActive()
// TODO: Pause any business logic.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,83 @@
import RIBs
import RxSwift
import UIKit
import SnapKit

protocol LoggedOutPresentableListener: AnyObject {
// TODO: Declare properties and methods that the view controller can invoke to perform
// business logic, such as signIn(). This protocol is implemented by the corresponding
// interactor class.
// TODO: Declare properties and methods that the view controller can invoke to perform
// business logic, such as signIn(). This protocol is implemented by the corresponding
// interactor class.

func login(player1Name: String?, player2Name: String?)
}

final class LoggedOutViewController: UIViewController, LoggedOutPresentable, LoggedOutViewControllable {

// MARK: - Properties
weak var listener: LoggedOutPresentableListener?

let player1Field: UITextField = {
let textField = UITextField()
textField.layer.borderWidth = 1
textField.layer.borderColor = UIColor.orange.cgColor
textField.placeholder = " Player 1 Name"
return textField
}()

let player2Field: UITextField = {
let textField = UITextField()
textField.layer.borderWidth = 1
textField.layer.borderColor = UIColor.orange.cgColor
textField.placeholder = " Player 2 Name"
return textField
}()

let loginButton: UIButton = {
let button = UIButton()
button.setTitle("로그인", for: .normal)
button.titleLabel?.font = .systemFont(ofSize: 14, weight: .bold)
button.setTitleColor(UIColor.white, for: .normal)
button.setTitleColor(UIColor.white.withAlphaComponent(0.3), for: .highlighted)
button.layer.cornerRadius = 4
button.backgroundColor = UIColor.orange
button.addTarget(self, action: #selector(didTapLoginButton), for: .touchUpInside)
return button
}()

// MARK: - Life Cycle
override func viewDidLoad() {
super.viewDidLoad()

configureUI()
}
}

weak var listener: LoggedOutPresentableListener?
// MARK: - Configure UI
extension LoggedOutViewController {
func configureUI() {
view.backgroundColor = UIColor.white

view.addSubview(player1Field)
player1Field.snp.makeConstraints { (make) in
make.top.equalToSuperview().offset(100)
make.leading.trailing.equalToSuperview().inset(40)
make.height.equalTo(40)
}

view.addSubview(player2Field)
player2Field.snp.makeConstraints { (make) in
make.top.equalTo(player1Field.snp.bottom).offset(20)
make.leading.trailing.height.equalTo(player1Field)
}

view.addSubview(loginButton)
loginButton.snp.makeConstraints { (make) in
make.top.equalTo(player2Field.snp.bottom).offset(20)
make.leading.trailing.height.equalTo(player1Field)
}
}

@objc private func didTapLoginButton() {
listener?.login(player1Name: player1Field.text, player2Name: player2Field.text)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ final class RootViewController: UIViewController, RootPresentable, RootViewContr
// MARK: - RootViewControllable

func present(viewController: ViewControllable) {
present(viewController.uiviewController, animated: true, completion: nil)
viewController.uiviewController.modalPresentationStyle = .fullScreen
present(viewController.uiviewController, animated: false, completion: nil)
}
}
24 changes: 24 additions & 0 deletions ios/tutorials/tutorial1/TicTacToe/Utils/RIBs+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// RIBs+Extension.swift
// TicTacToe
//
// Created by 정연문 on 2022/01/14.
// Copyright © 2022 Uber. All rights reserved.
//

import RIBs

extension ViewControllable {
func present(viewControllable: ViewControllable, animated: Bool, completion: (() -> Void)? = nil) {
viewControllable.uiviewController.modalPresentationStyle = .fullScreen
uiviewController.present(viewControllable.uiviewController, animated: animated, completion: completion)
}

func pushViewController(_ viewControllable: ViewControllable, animated: Bool) {
if let navigationController = uiviewController as? UINavigationController {
navigationController.pushViewController(viewControllable.uiviewController, animated: animated)
} else {
uiviewController.navigationController?.pushViewController(viewControllable.uiviewController, animated: animated)
}
}
}

0 comments on commit 0bdfb21

Please sign in to comment.