Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
✅ Check List
📌 Related Issue
📎 Work Description
문제 정의
1. 루트뷰 전환의 관심사 분리가 필요하다.
만약, 로그인 성공 이후에 NavigationStack 으로 TabBar를 push 한다면, 불필요한 로그인 화면이 메모리에 올라가게 되며 이는 메모리를 효율적으로 사용하지 못하게 됩니다.
해결 방법
2. Factory Pattern
관심사 분리: ViewController는 본인이 다음에 어디로 가야 하는지 구체적인 클래스명을 알 필요가 없습니다.
유연성: 나중에 로그인 화면이 LoginVC에서 SocialLoginVC로 바뀌어도 Factory 코드만 수정하면 됩니다.
메모리 관리: rootViewController를 통째로 갈아 끼우기 때문에 이전 화면들이 메모리에서 깔끔하게 해제됩니다.
3. 코드 설명 (화면 객체 생성 AppSceneFactory)
'AppSceneFactory' : type 기반으로 뷰 컨트롤러를 생성합니다.
확장 가능성 : 연관 타입 (Associated type)을 이용하여 객체 주입이 가능해집니다.
enum이 아닌
SceneFactory프로토콜의 함수를 추가, 삭제하고 매개변수를 이용해서 객체 주입을 받는 방향도 있습니다. (앱잼 때 합의해서 결정하면 좋을 내용)4. 화면 전환 객체 RootViewSwitcher
매개변수로 뷰를 받고, 루트 뷰로 전환해줍니다.
5. 탭 바 DefaultTabBarSceneFactory
탭 바 또한 같은 원리로 Factory 객체가 생성 및 전환을 담당합니다.
이렇게 관심사를 분리하면, 알림 뷰 컨트롤러에서 탭 뷰의 전환이 자연스러워집니다.
문제점
화면 전환 관심사의 분리를 통해 발생하는 문제가 있습니다.
DI Container 를 이용하여 ViewModel 등의 객체를 저장하여 (Singleton Pattern 사용 예상) 재진입 시, 저장된 데이터를 사용할 수 있습니다.
ViewModel 에 화면의 상태를 저장한다면 (스크롤 위치, 선택된 사항 등...) 이전 UI 그대로 그릴 수 있습니다.
📷 Screenshots
💬 To Reviewers