Skip to content

Commit

Permalink
- Implemented ExpandableText.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
piashcse committed Aug 16, 2024
1 parent d26c8dc commit 28f2074
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
42 changes: 42 additions & 0 deletions composeApp/src/commonMain/kotlin/ui/component/ExpandableText.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ui.component

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import theme.Teal200

@Composable
fun ExpandableText(
text: String,
minimizedMaxLines: Int = 3 // Default number of lines to show when collapsed
) {
var isExpanded by remember { mutableStateOf(false) }

Column(
modifier = Modifier
.fillMaxWidth()
.clickable { isExpanded = !isExpanded } // Toggle expansion on click
) {
Text(
text = text,
maxLines = if (isExpanded) Int.MAX_VALUE else minimizedMaxLines,
overflow = TextOverflow.Ellipsis,
)

Text(
text = if (isExpanded) "less" else "more",
color = Teal200,
modifier = Modifier.padding(top = 4.dp)
)
}
}
4 changes: 2 additions & 2 deletions composeApp/src/commonMain/kotlin/ui/detail/MovieDetail.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import org.jetbrains.compose.resources.stringResource
import theme.DefaultBackgroundColor
import theme.FontColor
import theme.cornerRadius
import ui.component.ExpandableText
import ui.component.ProgressIndicator
import ui.component.shimmerBackground
import ui.component.text.SubtitlePrimary
Expand Down Expand Up @@ -184,7 +185,7 @@ fun UiDetail(data: MovieDetail) {
fontSize = 17.sp,
fontWeight = FontWeight.SemiBold
)
Text(text = data.overview)
ExpandableText(text = data.overview)
}
}
}
Expand Down Expand Up @@ -277,4 +278,3 @@ fun ArtistAndCrew(navigator: Navigator?, cast: List<Cast>) {
}
}
}

0 comments on commit 28f2074

Please sign in to comment.