Skip to content

Commit

Permalink
[#1012] Context 직접 참조하는 부분 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
l2hyunwoo committed Jan 2, 2025
1 parent b39fa8d commit 8dcae83
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,30 @@
*/
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
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<ComponentActivity>()
val keyboardController = LocalSoftwareKeyboardController.current
val onBackPressedDispatcherOwner = LocalOnBackPressedDispatcherOwner.current

LaunchedEffect(Unit) {
userRepository.getUserInfo()
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 8dcae83

Please sign in to comment.