Skip to content

Commit

Permalink
chore: handle onBackPressed in home
Browse files Browse the repository at this point in the history
  • Loading branch information
giovannijunseokim committed Apr 16, 2024
1 parent 0b8f288 commit aa4aef0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/src/main/java/univ/earthbreaker/namu/feature/home/HomeRoute.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package univ.earthbreaker.namu.feature.home

import androidx.activity.compose.BackHandler
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import univ.earthbreaker.namu.feature.home.model.HomeActions
import univ.earthbreaker.namu.feature.home.model.HomeUiState
import univ.earthbreaker.namu.feature.loading.LoadingActions
import univ.earthbreaker.namu.feature.loading.LoadingScreen
import univ.earthbreaker.namu.feature.loading.LoadingViewModel
import univ.earthbreaker.namu.util.extension.finishSafely
import univ.earthbreaker.namu.util.extension.getActivity

@Composable
fun HomeRoute(
Expand All @@ -21,6 +25,10 @@ fun HomeRoute(
characterNo: Int,
) -> Unit,
) {
// handle onBackPressed
HomeBackHandler()

// declare ViewModels
val homeViewModel: HomeViewModel = viewModel()
val loadingViewModel: LoadingViewModel = viewModel()

Expand Down Expand Up @@ -50,6 +58,14 @@ fun HomeRoute(
}
}

@Composable
fun HomeBackHandler() {
val context = LocalContext.current
BackHandler {
context.getActivity()?.finishSafely()
}
}

@Composable
fun rememberHomeActions(
viewModel: HomeViewModel,
Expand Down

0 comments on commit aa4aef0

Please sign in to comment.