Skip to content

Commit

Permalink
expand synopsis on clicking it
Browse files Browse the repository at this point in the history
  • Loading branch information
axiel7 committed Sep 16, 2023
1 parent c19bf45 commit 629f6c2
Showing 1 changed file with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
Expand Down Expand Up @@ -113,8 +112,14 @@ fun MediaDetailsView(
val sheetState = rememberModalBottomSheetState()
val bottomBarPadding = WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding()

var maxLinesSynopsis by remember { mutableIntStateOf(5) }
var iconExpand by remember { mutableIntStateOf(R.drawable.ic_round_keyboard_arrow_down_24) }
var isSynopsisExpanded by remember { mutableStateOf(false) }
val maxLinesSynopsis by remember {
derivedStateOf { if (isSynopsisExpanded) Int.MAX_VALUE else 5 }
}
val iconExpand by remember {
derivedStateOf {
if (isSynopsisExpanded) R.drawable.ic_round_keyboard_arrow_up_24 else R.drawable.ic_round_keyboard_arrow_down_24 }
}
val isNewEntry by remember {
derivedStateOf { viewModel.mediaDetails?.myListStatus == null }
}
Expand Down Expand Up @@ -263,6 +268,7 @@ fun MediaDetailsView(
?: AnnotatedString(stringResource(R.string.lorem_ipsun)),
modifier = Modifier
.padding(horizontal = 16.dp)
.clickable { isSynopsisExpanded = !isSynopsisExpanded }
.defaultPlaceholder(visible = viewModel.isLoading),
lineHeight = 20.sp,
overflow = TextOverflow.Ellipsis,
Expand All @@ -288,15 +294,7 @@ fun MediaDetailsView(
} else Spacer(modifier = Modifier.size(48.dp))

IconButton(
onClick = {
if (maxLinesSynopsis == 5) {
maxLinesSynopsis = Int.MAX_VALUE
iconExpand = R.drawable.ic_round_keyboard_arrow_up_24
} else {
maxLinesSynopsis = 5
iconExpand = R.drawable.ic_round_keyboard_arrow_down_24
}
}
onClick = { isSynopsisExpanded = !isSynopsisExpanded }
) {
Icon(painter = painterResource(iconExpand), contentDescription = "expand")
}
Expand Down

0 comments on commit 629f6c2

Please sign in to comment.