Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class MainActivity : AppCompatActivity() {
MainScreen(
onAdRequest = { onRewardSuccess ->
showAdIfAvailable(onRewardSuccess)
}
},
onExit = { finish() }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,13 @@ class MainNavigator(
navController.navigatePostLikeUsers(postId = postId)
}

fun navigateUp() {
navController.navigateUp()
fun navigateUp(): Boolean {
return if (navController.previousBackStackEntry != null) {
navController.navigateUp()
true
} else {
false
}
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package daily.dayo.presentation.screen.main

import android.widget.Toast
import androidx.activity.compose.BackHandler
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.compose.animation.ExperimentalSharedTransitionApi
Expand Down Expand Up @@ -30,13 +32,15 @@ import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableLongStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.tooling.preview.Preview
Expand Down Expand Up @@ -78,6 +82,7 @@ import kotlinx.coroutines.launch
@Composable
internal fun MainScreen(
onAdRequest: (onRewardSuccess: () -> Unit) -> Unit,
onExit: () -> Unit,
navigator: MainNavigator = rememberMainNavigator(),
profileViewModel: ProfileViewModel = hiltViewModel()
) {
Expand All @@ -92,6 +97,22 @@ internal fun MainScreen(
derivedStateOf { if (bottomSheetState.bottomSheetState.currentValue == SheetValue.Expanded) 0.6f else 0f }
}
val animatedDimAlpha by animateFloatAsState(targetValue = bottomSheetDimAlpha)
val context = LocalContext.current
var lastBackPressedTime by remember { mutableLongStateOf(0L) }
val toast = remember { Toast.makeText(context, context.getString(R.string.main_finish_toast), Toast.LENGTH_SHORT) }

BackHandler {
if (!navigator.navigateUp()) { // 뒤로갈 화면 없는 경우
val currentTime = System.currentTimeMillis()
if (currentTime - lastBackPressedTime < 2000) {
toast?.cancel()
onExit() // 앱 종료
} else {
lastBackPressedTime = currentTime
toast?.show()
}
}
}

SharedTransitionLayout {
BottomSheetScaffold(
Expand Down
3 changes: 3 additions & 0 deletions presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
<string name="permission_fail_second">DENIED</string>
<string name="permission_fail_final">EXPLAINED</string>

<!-- Main -->
<string name="main_finish_toast">한 번 더 누르면 앱이 종료됩니다.</string>

<!-- OnBoarding -->
<string name="onboarding_first_message">인기가 많은 다꾸들을 구경할 수 있어요</string>
<string name="onboarding_second_message">내 취향의 다꾸러들을 팔로우하고 모아볼 수 있어요</string>
Expand Down