From 8dcae83548faf37b683a7580d02342cb8e75ccef Mon Sep 17 00:00:00 2001 From: HyunWoo Lee Date: Wed, 1 Jan 2025 19:01:34 +0900 Subject: [PATCH] =?UTF-8?q?[#1012]=20Context=20=EC=A7=81=EC=A0=91=20?= =?UTF-8?q?=EC=B0=B8=EC=A1=B0=ED=95=98=EB=8A=94=20=EB=B6=80=EB=B6=84=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../soptamp/state/rememberModifyProfileState.kt | 16 +++++++--------- .../mypage/soptamp/ui/AdjustSentenceActivity.kt | 5 ++++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/feature/mypage/src/main/java/org/sopt/official/feature/mypage/soptamp/state/rememberModifyProfileState.kt b/feature/mypage/src/main/java/org/sopt/official/feature/mypage/soptamp/state/rememberModifyProfileState.kt index df5dcc704..54e657a04 100644 --- a/feature/mypage/src/main/java/org/sopt/official/feature/mypage/soptamp/state/rememberModifyProfileState.kt +++ b/feature/mypage/src/main/java/org/sopt/official/feature/mypage/soptamp/state/rememberModifyProfileState.kt @@ -24,7 +24,7 @@ */ package org.sopt.official.feature.mypage.soptamp.state -import androidx.activity.ComponentActivity +import androidx.activity.compose.LocalOnBackPressedDispatcherOwner import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue @@ -32,24 +32,22 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue -import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalSoftwareKeyboardController import io.github.takahirom.rin.rememberRetained import kotlinx.coroutines.launch -import org.sopt.official.common.context.findActivity -import org.sopt.official.common.view.toast import org.sopt.official.feature.mypage.di.userRepository import timber.log.Timber @Composable -fun rememberModifyProfileState(): ModifySoptampProfileUiState { +fun rememberModifyProfileState( + onShowToast: (String) -> Unit +): ModifySoptampProfileUiState { var current by rememberRetained { mutableStateOf("") } var previous by rememberSaveable { mutableStateOf("") } val scope = rememberCoroutineScope() - val context = LocalContext.current - val activity = context.findActivity() val keyboardController = LocalSoftwareKeyboardController.current + val onBackPressedDispatcherOwner = LocalOnBackPressedDispatcherOwner.current LaunchedEffect(Unit) { userRepository.getUserInfo() @@ -70,8 +68,8 @@ fun rememberModifyProfileState(): ModifySoptampProfileUiState { userRepository.updateProfileMessage(current) .onSuccess { keyboardController?.hide() - context.toast("한마디가 변경되었습니다") - activity?.onBackPressedDispatcher?.onBackPressed() + onShowToast("한마디가 변경되었습니다") + onBackPressedDispatcherOwner?.onBackPressedDispatcher?.onBackPressed() }.onFailure { Timber.e(it) } diff --git a/feature/mypage/src/main/java/org/sopt/official/feature/mypage/soptamp/ui/AdjustSentenceActivity.kt b/feature/mypage/src/main/java/org/sopt/official/feature/mypage/soptamp/ui/AdjustSentenceActivity.kt index a4e15c622..abcea8d5a 100644 --- a/feature/mypage/src/main/java/org/sopt/official/feature/mypage/soptamp/ui/AdjustSentenceActivity.kt +++ b/feature/mypage/src/main/java/org/sopt/official/feature/mypage/soptamp/ui/AdjustSentenceActivity.kt @@ -39,9 +39,11 @@ import androidx.compose.foundation.layout.padding import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import dagger.hilt.android.AndroidEntryPoint +import org.sopt.official.common.view.toast import org.sopt.official.designsystem.SoptTheme import org.sopt.official.feature.mypage.R import org.sopt.official.feature.mypage.component.MyPageButton @@ -56,7 +58,8 @@ class AdjustSentenceActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContent { SoptTheme { - val uiState = rememberModifyProfileState() + val context = LocalContext.current + val uiState = rememberModifyProfileState(onShowToast = { context.toast(it) }) Scaffold( modifier = Modifier