From 2e35cb8dbc4d818300c7f1b38d18440f0cea0826 Mon Sep 17 00:00:00 2001
From: ddyeon <cab05102@naver.com>
Date: Tue, 9 Jul 2024 22:49:29 +0900
Subject: [PATCH] =?UTF-8?q?[fix]=20savestatehandler=EB=A1=9C=20=EA=B0=92?=
 =?UTF-8?q?=20=EB=B0=9B=EA=B8=B0=20=EC=88=98=EC=A0=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../com/mashup/dorabangs/feature/home/HomeScreen.kt    |  5 +----
 .../com/mashup/dorabangs/feature/home/HomeViewModel.kt |  9 +++++++++
 .../dorabangs/feature/navigation/HomeNavigation.kt     | 10 ++--------
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/feature/home/src/main/java/com/mashup/dorabangs/feature/home/HomeScreen.kt b/feature/home/src/main/java/com/mashup/dorabangs/feature/home/HomeScreen.kt
index 20811a03..23dd0f67 100644
--- a/feature/home/src/main/java/com/mashup/dorabangs/feature/home/HomeScreen.kt
+++ b/feature/home/src/main/java/com/mashup/dorabangs/feature/home/HomeScreen.kt
@@ -51,7 +51,6 @@ import org.orbitmvi.orbit.compose.collectSideEffect
 
 @Composable
 fun HomeRoute(
-    isVisibleBottomSheet: Boolean,
     modifier: Modifier = Modifier,
     view: View = LocalView.current,
     clipboardManager: ClipboardManager = LocalClipboardManager.current,
@@ -66,9 +65,7 @@ fun HomeRoute(
     val scope = rememberCoroutineScope()
 
     LaunchedEffect(key1 = Unit) {
-        if (isVisibleBottomSheet) {
-            viewModel.setVisibleMovingFolderBottomSheet(true)
-        }
+        viewModel.getIsVisibleMoreBottomSheet()
     }
 
     viewModel.collectSideEffect { sideEffect ->
diff --git a/feature/home/src/main/java/com/mashup/dorabangs/feature/home/HomeViewModel.kt b/feature/home/src/main/java/com/mashup/dorabangs/feature/home/HomeViewModel.kt
index c9b1da3a..e80ddb21 100644
--- a/feature/home/src/main/java/com/mashup/dorabangs/feature/home/HomeViewModel.kt
+++ b/feature/home/src/main/java/com/mashup/dorabangs/feature/home/HomeViewModel.kt
@@ -1,5 +1,6 @@
 package com.mashup.dorabangs.feature.home
 
+import android.util.Log
 import androidx.lifecycle.SavedStateHandle
 import androidx.lifecycle.ViewModel
 import androidx.lifecycle.viewModelScope
@@ -17,6 +18,7 @@ import org.orbitmvi.orbit.syntax.simple.postSideEffect
 import org.orbitmvi.orbit.syntax.simple.reduce
 import org.orbitmvi.orbit.viewmodel.container
 import javax.inject.Inject
+import kotlin.math.log
 
 @HiltViewModel
 class HomeViewModel @Inject constructor(
@@ -26,6 +28,13 @@ class HomeViewModel @Inject constructor(
 ) : ViewModel(), ContainerHost<HomeState, HomeSideEffect> {
     override val container = container<HomeState, HomeSideEffect>(HomeState())
 
+    fun getIsVisibleMoreBottomSheet() {
+        savedStateHandle.get<Boolean>("isVisibleMovingBottomSheet")?.let { isVisible ->
+            Log.d("HomeViewModel", ": ${isVisible} ")
+            setVisibleMovingFolderBottomSheet(isVisible)
+        }
+    }
+
     fun changeSelectedTapIdx(index: Int) = intent {
         reduce {
             state.copy(selectedIndex = index)
diff --git a/feature/home/src/main/java/com/mashup/dorabangs/feature/navigation/HomeNavigation.kt b/feature/home/src/main/java/com/mashup/dorabangs/feature/navigation/HomeNavigation.kt
index ac56b076..e3c0dc73 100644
--- a/feature/home/src/main/java/com/mashup/dorabangs/feature/navigation/HomeNavigation.kt
+++ b/feature/home/src/main/java/com/mashup/dorabangs/feature/navigation/HomeNavigation.kt
@@ -14,7 +14,7 @@ fun NavController.navigateToHome(navOptions: NavOptions? = null) =
     navigate(NavigationRoute.HomeScreen.route, navOptions)
 
 fun NavGraphBuilder.homeNavigation(
-    navigateToClassification: () -> Unit = {},
+    navigateToClassification: () -> Unit,
     navigateToSaveScreenWithLink: (String) -> Unit,
     navigateToSaveScreenWithoutLink: () -> Unit,
     navigateToCreateFolder: () -> Unit,
@@ -27,14 +27,8 @@ fun NavGraphBuilder.homeNavigation(
                 defaultValue = false
             },
         ),
-    ) { backStackEntry ->
-
-        val isVisibleBottomSheet = backStackEntry.savedStateHandle.getStateFlow(
-            "isVisibleMovingBottomSheet",
-            initialValue = false,
-        ).collectAsState().value
+    ) { 
         HomeRoute(
-            isVisibleBottomSheet = isVisibleBottomSheet,
             navigateToClassification = navigateToClassification,
             navigateToSaveScreenWithLink = navigateToSaveScreenWithLink,
             navigateToSaveScreenWithoutLink = navigateToSaveScreenWithoutLink,