Skip to content

Commit

Permalink
[Feat/#288] 캐릭터 선톡 채팅 탭 시 채팅 로그 뷰로 이동 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanMinsung committed Nov 17, 2024
1 parent 8c3497f commit 1b69b43
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,35 @@

import UIKit

import RxSwift

class ORBNavigationController: UINavigationController {

//MARK: - Properties

var disposeBag = DisposeBag()
var customPopTransition: UIPercentDrivenInteractiveTransition?
lazy var screenEdgePanGesture = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(handlePanGesture(_:)))

//MARK: - Life Cycle

override func viewDidLoad() {
super.viewDidLoad()

setupGestures()
setupDelegates()
setupSubscription()
}

override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)

guard viewControllers.last is CharacterChatLogViewController else { return }
popViewController(animated: false)
}

}


extension ORBNavigationController {

//MARK: - @objc Func
Expand Down Expand Up @@ -61,9 +75,19 @@ extension ORBNavigationController {
interactivePopGestureRecognizer?.delegate = self
}

private func setupSubscription() {
ORBCharacterChatManager.shared.shouldPushCharacterChatLogViewController
.subscribe(onNext: { [weak self] characterName in
guard let self else { return }
self.pushChatLogViewController(characterName: characterName)
}).disposed(by: disposeBag)
}

//MARK: - Func

func pushChatLogViewController(characterName: String) {
guard !(viewControllers.last is CharacterChatLogViewController) else { return }
guard view.window != nil else { return }
guard let snapshot = topViewController?.view.snapshotView(afterScreenUpdates: true) else { return }
let chatLogViewController = CharacterChatLogViewController(background: snapshot, characterName: characterName)
pushViewController(chatLogViewController, animated: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import UIKit

import RxSwift

final class ORBCharacterChatManager {

//MARK: - Static Properties
Expand All @@ -15,6 +17,10 @@ final class ORBCharacterChatManager {

//MARK: - Properties

let shouldPushCharacterChatLogViewController = PublishSubject<String>()

//MARK: - UI Properties

var chatWindow = ORBCharacterChatWindow(windowScene: UIWindowScene.current)
var chatViewController: ORBCharacterChatViewController {
chatWindow.rootViewController as! ORBCharacterChatViewController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class ORBCharacterChatView: UIView {

//MARK: - Properties

lazy var characterChatBoxTopConstraint = characterChatBox.topAnchor.constraint(equalTo: topAnchor)
lazy var characterChatBoxTopConstraint = characterChatBox.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor)
lazy var userChatViewBottomConstraint = userChatView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: 160)
lazy var userChatInputViewHeightConstraint = userChatInputView.heightAnchor.constraint(equalToConstant: 37)
lazy var userChatDisplayViewHeightConstraint = userChatDisplayView.heightAnchor.constraint(equalToConstant: 24)
Expand Down Expand Up @@ -57,7 +57,7 @@ extension ORBCharacterChatView {
//MARK: - Layout Func

private func setupLayout() {
characterChatBoxTopConstraint.constant = -150
characterChatBoxTopConstraint.constant = -(safeAreaInsets.top + 150)
characterChatBoxTopConstraint.isActive = true
characterChatBox.snp.makeConstraints { make in
make.horizontalEdges.equalToSuperview().inset(24)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ORBCharacterChatViewController: UIViewController {
let userChatDisplayViewHeightAnimator = UIViewPropertyAnimator(duration: 0.3, dampingRatio: 1)

lazy var panGesture = UIPanGestureRecognizer(target: self, action: #selector(panGestureHandler))
lazy var tapGesture = UITapGestureRecognizer(target: self, action: #selector(tapGestureHandler))

override func loadView() {
view = rootView
Expand Down Expand Up @@ -82,7 +83,11 @@ extension ORBCharacterChatViewController {
@unknown default:
rootView.characterChatBox.transform = CGAffineTransform.identity
}

}

@objc private func tapGestureHandler(sender: UITapGestureRecognizer) {
guard rootView.characterChatBox.mode == .withReplyButton else { return }
ORBCharacterChatManager.shared.shouldPushCharacterChatLogViewController.onNext(rootView.characterChatBox.characterNameLabel.text!)
}

//MARK: - Private Func
Expand Down Expand Up @@ -183,6 +188,7 @@ extension ORBCharacterChatViewController {

private func setupGestures() {
rootView.characterChatBox.addGestureRecognizer(panGesture)
rootView.characterChatBox.addGestureRecognizer(tapGesture)
}

//MARK: - Func
Expand All @@ -193,7 +199,7 @@ extension ORBCharacterChatViewController {
characterChatBoxPositionAnimator.addAnimations { [weak self] in
guard let self else { return }
self.rootView.characterChatBox.transform = CGAffineTransform.identity
self.rootView.characterChatBoxTopConstraint.constant = 74
self.rootView.characterChatBoxTopConstraint.constant = 27
self.rootView.layoutIfNeeded()
}
characterChatBoxPositionAnimator.startAnimation()
Expand All @@ -204,9 +210,15 @@ extension ORBCharacterChatViewController {
characterChatBoxPositionAnimator.addAnimations { [weak self] in
guard let self else { return }
self.rootView.characterChatBox.transform = CGAffineTransform.identity
self.rootView.characterChatBoxTopConstraint.constant = -self.rootView.characterChatBox.frame.height
self.rootView.characterChatBoxTopConstraint.constant
= -(rootView.safeAreaInsets.top + self.rootView.characterChatBox.frame.height)
self.rootView.layoutIfNeeded()
}
characterChatBoxPositionAnimator.addCompletion { [weak self] _ in
guard let self else { return }
self.rootView.characterChatBox.characterNameLabel.text = ""
self.rootView.characterChatBox.messageLabel.text = ""
}
characterChatBoxPositionAnimator.startAnimation()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class CharacterChatLogViewController: OffroadTabBarViewController {
guard let tabBarController = tabBarController as? OffroadTabBarController else { return }
tabBarController.showTabBarAnimation()
rootView.backgroundView.isHidden = false
ORBCharacterChatManager.shared.hideCharacterChatBox()
}

override func viewDidAppear(_ animated: Bool) {
Expand All @@ -78,12 +79,6 @@ class CharacterChatLogViewController: OffroadTabBarViewController {
rootView.endEditing(true)
}

override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)

navigationController?.popViewController(animated: false)
}

}

extension CharacterChatLogViewController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,6 @@ extension OffroadTabBarController {
customOffroadLogoButton.addTarget(self, action: #selector(centerTabBarButtonItemTapped), for: .touchUpInside)
}

// private func setupDelegates() {
// guard let homeNavigationController = viewControllers?[0] as? UINavigationController else { return }
// guard let questMapNavigationController = viewControllers?[1] as? UINavigationController else { return }
// guard let myPageNavigationController = viewControllers?[2] as? UINavigationController else { return }
// homeNavigationController.delegate = self
// questMapNavigationController.delegate = self
// myPageNavigationController.delegate = self
// }

func disableTabBarInteraction() {
tabBar.isUserInteractionEnabled = false
tabBar.items?.enumerated().forEach({ index, item in
Expand Down

0 comments on commit 1b69b43

Please sign in to comment.