Skip to content

[5주차 트러블 슈팅] 홍성준

SungJun Hong edited this page Dec 11, 2023 · 1 revision

🖼️ 배경

🫠 트러블

  • iOS 에서 제공하는 왼쪽 끝을 Swipe해서 이전 화면으로 가는 기능을 사용하지 못했음
  • RIBs 구조가 뒤로 가기 후에 리블렛을 detach 해야 하기 때문에 구현하기 까다로웠음

🏃🏻 시도했던 방법

  • UINavigationControllerDelegate에 willPop 이라는 메소드가 존재하는가?
  • 기존의 pop 동작은 단순히 NavigationController의 pop을 호출하였는데 ViewController를 추가하여 해당 ViewController와 동일하면 pop 되도록 하기

✅ 솔루션

  • Pop 동작에 ViewController를 넣어 Pop될 ViewController와 동일한 객체인지 확인하기
    • 만약 스와이프로 ViewController가 사라지고 detach 메소드가 호출되면 pop을 두 번 호출하였음
    • 따라서 pop 동작에 ViewController를 넣어 ViewController가 없는 상태에서 detach가 호출되어도 ViewController는 제거하지 않고 (이미 제거되었으므로) 리블렛을 detach 하도록 구현하였음
  • 위의 방식을 깔끔하게 동작시키기
    • 위 동작을 Router의 Extension으로 추가하여 attachChild/detachChild까지 하도록 추가하였음
public extension ViewableRouting {

    // MARK: - Attach
    
    func presentRouter(
        _ router: ViewableRouting,
        animated: Bool,
        isFullScreen: Bool = false,
        completion: (() -> Void)? = nil
    ) {
        viewControllable.present(router.viewControllable, animated: animated, isFullScreen: isFullScreen, completion: completion)
        attachChild(router)
    }

    func pushRouter(_ router: ViewableRouting, animated: Bool) {
        viewControllable.pushViewController(router.viewControllable, animated: animated)
        attachChild(router)
    }

    func setRouters(_ routers: [ViewableRouting], animated: Bool) {
        viewControllable.setViewControllers(routers.map(\.viewControllable), animated: animated)
        routers.forEach(attachChild)
    }

    // MARK: - Detach
    
    func dismissRouter(_ router: ViewableRouting, animated: Bool, completion: (() -> Void)? = nil) {
        viewControllable.dismiss(animated: animated, completion: completion)
        detachChild(router)
    }

    func popRouter(_ router: ViewableRouting, animted: Bool, completion: (() -> Void)? = nil) {
        viewControllable.popViewController(router.viewControllable, animated: animted, completion: completion)
        detachChild(router)
    }

}
  • 뒤로 가기 이벤트를 ViewController에서 Interactor로 전달하기
    • 현재 앱에서 NavigationView라는 공통의 View를 통해 뒤로가기 기능을 사용하고 있었음
    • BaseViewController를 추가하여 ViewController가 스와이프로 뒤로가기가 되었을 때 해당 NavigationView의 뒤로 가기 이벤트를 주어 해결하였음
open class BaseViewController: UIViewController {

    public let navigationView = NavigationView()
    public var cancellables = Set<AnyCancellable>()

    open override func viewDidLoad() {
        super.viewDidLoad()
        setupLayout()
        setupAttributes()
        bind()
    }

    open override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        if isMovingFromParent {
            navigationView.sendCloseEvent()
        }
    }

    open func setupLayout() {}
    open func setupAttributes() {}
    open func bind() {}

}

🔥 HeatPick

🔨 프로젝트 소개

🫠 트러블 슈팅

1주차

2주차

3주차

4주차

5주차

🤔 기획 회의록

🤷🏻 의사 결정록

🍎 iOS

🌐 Backend

🎯 주차별 목표

🏃🏻 데일리 스크럼

1주차

2주차

3주차

4주차

5주차

6주차

🙇🏻 멘토링 일지

👀 프로젝트 현황 공유

🙋🏻 팀 회고

💪 개인 회고

1주차

2주차

3주차

4주차

5주차

📇 템플릿

Clone this wiki locally