Skip to content

Commit

Permalink
画面遷移時にパラメーターの受け渡しを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
geekshu625 committed Jul 22, 2020
1 parent 0296a9c commit 1761114
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
6 changes: 3 additions & 3 deletions chat-iOS/Views/Chats/ChatsViewBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import UIKit

struct ChatsViewBuilder {
static func create() -> UIViewController {
static func create(withRoomId roomId: String, withRoomName roomName: String) -> UIViewController {
guard let chatsViewController = ChatsViewController.loadFromStoryboard() as? ChatsViewController else {
fatalError("fatal: Failed to initialize the ChatsViewController")
}
let model = ChatsViewModel()
let presenter = ChatsViewPresenter(model: model)
chatsViewController.inject(with: presenter)
let presenter = ChatsViewPresenter(model: model, withRoomId: roomId)
chatsViewController.inject(with: presenter, withRoomName: roomName)
return chatsViewController
}
}
6 changes: 4 additions & 2 deletions chat-iOS/Views/Chats/ChatsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ final class ChatsViewController: UIViewController, UICollectionViewDelegateFlowL
@IBOutlet weak var sendButton: UIButton!

var transScripts: [Transcript] = Array()

private var roomName: String = ""

let chatsCellID = "chatsCellID"

override func viewDidLoad() {
Expand Down Expand Up @@ -93,9 +94,10 @@ final class ChatsViewController: UIViewController, UICollectionViewDelegateFlowL
self.presenter.didTapSendButton(messageText: text)
}

func inject(with presenter: ChatsViewPresenterProtocol) {
func inject(with presenter: ChatsViewPresenterProtocol, withRoomName roomName: String) {
self.presenter = presenter
self.presenter.view = self
self.roomName = roomName
}
}

Expand Down
4 changes: 3 additions & 1 deletion chat-iOS/Views/Chats/ChatsViewPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ protocol ChatsViewPresenterOutput: class {
final class ChatsViewPresenter: ChatsViewPresenterProtocol, ChatsViewModelOutput {
weak var view: ChatsViewPresenterOutput!
private var model: ChatsViewModelProtocol
private var roomId: String

init(model: ChatsViewModelProtocol) {
init(model: ChatsViewModelProtocol, withRoomId roomId: String) {
self.model = model
self.roomId = roomId
self.model.presenter = self
}

Expand Down
7 changes: 5 additions & 2 deletions chat-iOS/Views/SelectChat/SelectChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ extension SelectChatViewController: SelectChatViewPresenterOutput {
}

func transitionToChatsViewController(selectedRoom room: Room) {
//TODO:- 画面遷移時に加えて値の引き渡しをする
let chatsViewController = ChatsViewBuilder.create()

guard let roomId = room.id else { return }
guard let roomName = room.name else { return }
let chatsViewController = ChatsViewBuilder.create(withRoomId: roomId, withRoomName: roomName)
self.navigationController?.pushViewController(chatsViewController, animated: true)

}

}

0 comments on commit 1761114

Please sign in to comment.