Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] 내 정보 API 호출 시점 변경 #128

Merged
merged 1 commit into from
Mar 31, 2024
Merged

Conversation

easyhooon
Copy link
Collaborator

  • 기존의 로직에선 MyPageViewModel 의 init {} 블럭에서 내 정보 API 를 호출했었음
  • 허나 그럴 경우, 뷰모델이 파괴되지 않으면, 더이상 API를 호출하지 않기 때문에, 이미지를 생성하고 다시 MyPage에 진입하여도 API가 호출되지 않아 새로 생성된 이미지를 확인할 수 없는 문제가 발생 -> 앱을 껐다 켜야 반영됨
  • Navigation Bar 과 연동된 화면의 뷰모델의 생명주기가 다른 단일 화면들과 어떻게 다른지 알아볼 필요가 있음
  • 따라서 해당 화면에 진입할때마다 API를 호출하여 새로 갱신된 정보를 받아야 하므로 화면 컴포저블 내에 LaunchedEffect(key1 = Unit) 내에서 API를 호출하여 리컴포지션 될 때마다(화면 진입, 앨범 삭제 등등) 호출되도록 호출 시점 변경

다만 지금 슬랙에 언급한 API 관련 문제가 존재하여 해당 문제를 먼저 해결해야할듯(서버 데이터 관련 문제)

@easyhooon easyhooon added the bug Something isn't working label Mar 30, 2024
@easyhooon easyhooon self-assigned this Mar 30, 2024
@easyhooon
Copy link
Collaborator Author

easyhooon commented Mar 31, 2024

    fun navigate(tab: MainTab) {
        val navOptions = navOptions {
            popUpTo(navController.graph.findStartDestination().id) {
                saveState = true
            }
            launchSingleTop = true
            restoreState = true
        }

        when (tab) {
            MainTab.HOME -> navController.navigateToHome(navOptions)
            MainTab.UPLOAD_PHOTO -> navController.navigateToUploadPhoto(navOptions)
            MainTab.MY_PAGE -> navController.navigateToMyPage(navOptions)
        }
    }

Navigation Bar 에서 아이콘을 눌렀을 경우엔 해당 로직을 타는데, saveState 와 restoreState 옵션이 활성화 되어있어서 화면에 다시 돌아올 경우 이전의 상태를 저장하고, 이를 복원하여 기존의 인스턴스를 재사용하는 식인것으로 보임. 따라서 다른 화면들과 다르게 화면을 벗어나도, 뷰모델이 파괴되지않고 유지되는듯

@easyhooon easyhooon merged commit 7895360 into develop Mar 31, 2024
1 check passed
@easyhooon easyhooon deleted the fix/my-page-api branch March 31, 2024 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants