So, i have 2 bottomsheet
composable named DetailCharacter
and Synopsis
. But this 2 composable behave differently, when i touch outside of the bottomsheet
area, the synopsis
close the bottomsheet
and also popup the route from backstack, but DetailCharacter
is only closing it without popup the route from backstack.
Here is the code of the Synopsis Composable
:
bottomSheet(
route = Screen.FullSynopsisScreen.route,
arguments = listOf(
navArgument(
name = "mal_id"
) {
type = NavType.IntType
}
)
) { navBackstack ->
val animeID = navBackstack.arguments?.getInt("mal_id") ?: 0
val viewModel = hiltViewModel<DetailAnimeViewModel>()
LaunchedEffect(key1 = Unit) {
viewModel.initiateView(animeID)
}
val animeResource by viewModel.anime.collectAsStateWithLifecycle()
Surface(
modifier = Modifier
.fillMaxSize()
.animateContentSize()
) {
when (animeResource) {
is Resource.Success -> SynopsisScreen(synopsis = (animeResource.data as Anime).synopsis as String)
else -> Unit
}
}
}
And here is the code of the DetailCharacter Composable
:
bottomSheet(
route = Screen.DetailCharacterScreen.route,
arguments = listOf(
navArgument(
name = "mal_id"
) {
type = NavType.IntType
}
)
) { navBackstack ->
val configuration: Configuration = LocalConfiguration.current
val screenHeight: Dp = configuration.screenHeightDp.dp
val oneThirdHeight: Dp = screenHeight / 3
val characterID = navBackstack.arguments?.getInt("mal_id") ?: 0
val viewModel: DetailCharacterViewModel = hiltViewModel()
LaunchedEffect(key1 = Unit, block = {
Timber.d("Fetching Character with MAL ID $characterID")
viewModel.fetchDetailCharacter(characterID = characterID)
})
val characterResource by viewModel.characterResource.collectAsStateWithLifecycle()
Surface(
modifier = Modifier.animateContentSize()
) {
when (characterResource) {
is Resource.Error -> {}
Resource.Loading -> {
Box(
modifier = Modifier
.height(oneThirdHeight)
.fillMaxWidth(),
contentAlignment = Alignment.Center
) {
CircularProgressIndicator()
}
}
Resource.None -> Unit
is Resource.Success -> DetailCharacterScreen(
characterResource.data as CharacterDetail
)
}
}
}
If you need further information about the code, here is the repository for this project Lelenime