From ece83c2a67ef0f0079e221737912395737b71abc Mon Sep 17 00:00:00 2001 From: oguuk Date: Wed, 14 Dec 2022 20:38:15 +0900 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20=EC=9E=85=EC=9E=A5=20=ED=9B=84=20?= =?UTF-8?q?=EC=B2=AB=EC=B1=84=ED=8C=85=20=EC=98=A4=EB=A5=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Data/DataSources/Remote/ChatDataSource.swift | 1 - .../Chat/ViewController/ChatViewController.swift | 1 - .../Presentation/Chat/ViewModel/ChatViewModel.swift | 13 ++++--------- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/Mogakco/Sources/Data/DataSources/Remote/ChatDataSource.swift b/Mogakco/Sources/Data/DataSources/Remote/ChatDataSource.swift index 63b69af6..34f8dea5 100644 --- a/Mogakco/Sources/Data/DataSources/Remote/ChatDataSource.swift +++ b/Mogakco/Sources/Data/DataSources/Remote/ChatDataSource.swift @@ -63,7 +63,6 @@ final class ChatDataSource: ChatDataSourceProtocol { return Observable.create { emitter in let query = Constant.chatRoom.document(chatRoomID).collection("chat") query.getDocuments(completion: { snapshot, _ in - if snapshot?.isEmpty == true { query.addDocument(data: [:]) } self.listener = query.order(by: "date").limit(toLast: 1).addSnapshotListener({ snapshot, _ in if let snapshot = snapshot, let change = snapshot.documentChanges.last, diff --git a/Mogakco/Sources/Presentation/Chat/ViewController/ChatViewController.swift b/Mogakco/Sources/Presentation/Chat/ViewController/ChatViewController.swift index 50e76111..fd3560a3 100644 --- a/Mogakco/Sources/Presentation/Chat/ViewController/ChatViewController.swift +++ b/Mogakco/Sources/Presentation/Chat/ViewController/ChatViewController.swift @@ -147,7 +147,6 @@ final class ChatViewController: UIViewController { for: IndexPath(row: index, section: 0)) as? ChatCell else { return UICollectionViewCell() } - cell.layoutChat(chat: chat) cell.profileImageButton.rx.tap diff --git a/Mogakco/Sources/Presentation/Chat/ViewModel/ChatViewModel.swift b/Mogakco/Sources/Presentation/Chat/ViewModel/ChatViewModel.swift index 4ede51bb..3b9d2d40 100644 --- a/Mogakco/Sources/Presentation/Chat/ViewModel/ChatViewModel.swift +++ b/Mogakco/Sources/Presentation/Chat/ViewModel/ChatViewModel.swift @@ -44,7 +44,6 @@ final class ChatViewModel: ViewModel { let alert: Signal } - private var isFirst = true var chatRoomID: String = "" var chatUseCase: ChatUseCaseProtocol? var leaveStudyUseCase: LeaveStudyUseCaseProtocol? @@ -141,10 +140,10 @@ final class ChatViewModel: ViewModel { switch result { case .success(let chat): let chatID = try? newChats.value().last?.id - if viewModel.isFirst == false && chat.id != chatID { + let newChats = try? newChats.value().isEmpty + + if newChats != false && chat.id != chatID { newChat.onNext(chat) - } else { - viewModel.isFirst = false } case .failure: let alert = Alert(title: "메세지 로드 실패", message: "메세지 로드에 실패했어요! 다시 시도해주세요", observer: nil) @@ -262,9 +261,7 @@ final class ChatViewModel: ViewModel { ) .withUnretained(self) .flatMap { $0.0.unsubscribePushNotificationUseCase?.excute(topic: $0.0.chatRoomID) ?? .empty() } - .subscribe(onNext: { [weak self] _ in - self?.isFirst = true - }) + .subscribe(onNext: { _ in }) .disposed(by: disposeBag) // 채팅방 나갈 시 -> 푸쉬 알림 구독 @@ -275,8 +272,6 @@ final class ChatViewModel: ViewModel { .withUnretained(self) .flatMap { $0.0.subscribePushNotificationUseCase?.excute(topic: $0.0.chatRoomID) ?? .empty() } .subscribe(onNext: { [weak self] _ in - print("DEBUG : OBSERVE OUT") - self?.isFirst = true self?.chatUseCase?.stopObserving() }) .disposed(by: disposeBag) From 9d49c0071ec642c3c0b50cf471329b716365edd4 Mon Sep 17 00:00:00 2001 From: oguuk Date: Wed, 14 Dec 2022 20:58:42 +0900 Subject: [PATCH 2/5] =?UTF-8?q?fix:=20=EC=B1=84=ED=8C=85=EB=B0=A9=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=EC=9C=A0=EB=B0=9C=ED=95=9C=20=EC=A1=B0?= =?UTF-8?q?=EA=B1=B4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Presentation/Chat/ViewModel/ChatViewModel.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Mogakco/Sources/Presentation/Chat/ViewModel/ChatViewModel.swift b/Mogakco/Sources/Presentation/Chat/ViewModel/ChatViewModel.swift index 3b9d2d40..0e02100e 100644 --- a/Mogakco/Sources/Presentation/Chat/ViewModel/ChatViewModel.swift +++ b/Mogakco/Sources/Presentation/Chat/ViewModel/ChatViewModel.swift @@ -140,9 +140,7 @@ final class ChatViewModel: ViewModel { switch result { case .success(let chat): let chatID = try? newChats.value().last?.id - let newChats = try? newChats.value().isEmpty - - if newChats != false && chat.id != chatID { + if chat.id != chatID { newChat.onNext(chat) } case .failure: From 265fca9857a19734ad1d0b3743ba0d08270fbdb0 Mon Sep 17 00:00:00 2001 From: oguuk Date: Thu, 15 Dec 2022 00:02:50 +0900 Subject: [PATCH 3/5] =?UTF-8?q?refactor:=20=EC=9E=90=EC=9E=98=ED=95=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mogakco/Sources/Presentation/Chat/View/ChatCell.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mogakco/Sources/Presentation/Chat/View/ChatCell.swift b/Mogakco/Sources/Presentation/Chat/View/ChatCell.swift index ff156654..9bdb0d43 100644 --- a/Mogakco/Sources/Presentation/Chat/View/ChatCell.swift +++ b/Mogakco/Sources/Presentation/Chat/View/ChatCell.swift @@ -186,7 +186,7 @@ final class ChatCell: UICollectionViewCell, Identifiable { } timeLabel.snp.remakeConstraints { - $0.right.equalTo(bubbleContainer.snp.left).offset(-4) + $0.right.equalTo(bubbleContainer.snp.left).offset(-8) $0.bottom.equalTo(bubbleContainer) } From 821136aa48d246ff260f7394d040fdc18b7d650d Mon Sep 17 00:00:00 2001 From: oguuk Date: Thu, 15 Dec 2022 00:03:38 +0900 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20=EC=9E=85=EB=A0=A5=20TextView=20?= =?UTF-8?q?=EB=86=92=EC=9D=B4=20=EC=A1=B0=EC=A0=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewController/ChatViewController.swift | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Mogakco/Sources/Presentation/Chat/ViewController/ChatViewController.swift b/Mogakco/Sources/Presentation/Chat/ViewController/ChatViewController.swift index fd3560a3..72b81e01 100644 --- a/Mogakco/Sources/Presentation/Chat/ViewController/ChatViewController.swift +++ b/Mogakco/Sources/Presentation/Chat/ViewController/ChatViewController.swift @@ -32,6 +32,7 @@ final class ChatViewController: UIViewController { private lazy var messageInputView = MessageInputView().then { $0.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: 0) + $0.backgroundColor = .red } private lazy var collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout() @@ -63,6 +64,7 @@ final class ChatViewController: UIViewController { private let viewModel: ChatViewModel private let selectedUser = PublishSubject() private let chatMenuSelected = PublishSubject() + private var keyboardHeight = 0.0 init(viewModel: ChatViewModel) { self.viewModel = viewModel @@ -119,6 +121,7 @@ final class ChatViewController: UIViewController { let output = viewModel.transform(input: input) bindChatCollection(output: output) bindSideBar(output: output) + bindTextView() bindKeyboard() } @@ -214,6 +217,35 @@ final class ChatViewController: UIViewController { .disposed(by: disposeBag) } + func bindTextView() { + messageInputView.messageInputTextView.rx + .didChange + .subscribe(onNext: { [weak self] in + guard let self else { return } + let size = CGSize(width: self.messageInputView.messageInputTextView.frame.width, height: .infinity) + let estimatedSize = self.messageInputView.messageInputTextView.sizeThatFits(size) + let isMaxHeight = estimatedSize.height >= Constant.messageInputViewHeight + if isMaxHeight == self.messageInputView.messageInputTextView.isScrollEnabled { return } + self.messageInputView.messageInputTextView.isScrollEnabled = isMaxHeight + self.messageInputView.messageInputTextView.reloadInputViews() + print("DEBUG @@ : \(isMaxHeight)") + self.setNeedsUpdateConstraints(isScrollEnabled: isMaxHeight) + }) + .disposed(by: disposeBag) + } + + func setNeedsUpdateConstraints(isScrollEnabled: Bool) { + messageInputView.snp.remakeConstraints { + $0.left.right.equalTo(self.view.safeAreaLayoutGuide) + $0.bottom.equalToSuperview().inset(keyboardHeight) + if isScrollEnabled { + $0.top.lessThanOrEqualTo(self.view.snp.centerY) + } else { + $0.height.equalTo(Constant.messageInputViewHeight) + } + } + } + func bindKeyboard() { RxKeyboard.instance.visibleHeight .skip(1) @@ -302,6 +334,7 @@ final class ChatViewController: UIViewController { } else { UIView.animate(withDuration: 0.5) { [weak self] in guard let self else { return } + self.keyboardHeight = height self.collectionView.snp.remakeConstraints { $0.top.left.right.equalToSuperview() $0.bottom.equalTo(self.messageInputView.snp.top) From a4b5177555b16ab85bb50cdee89ee14565c6041a Mon Sep 17 00:00:00 2001 From: oguuk Date: Thu, 15 Dec 2022 00:19:35 +0900 Subject: [PATCH 5/5] =?UTF-8?q?refactor:=20=ED=82=A4=EB=B3=B4=EB=93=9C=20?= =?UTF-8?q?=EC=83=89=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Presentation/Chat/ViewController/ChatViewController.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Mogakco/Sources/Presentation/Chat/ViewController/ChatViewController.swift b/Mogakco/Sources/Presentation/Chat/ViewController/ChatViewController.swift index 72b81e01..f7b127b6 100644 --- a/Mogakco/Sources/Presentation/Chat/ViewController/ChatViewController.swift +++ b/Mogakco/Sources/Presentation/Chat/ViewController/ChatViewController.swift @@ -32,7 +32,6 @@ final class ChatViewController: UIViewController { private lazy var messageInputView = MessageInputView().then { $0.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: 0) - $0.backgroundColor = .red } private lazy var collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()