@@ -30,22 +30,27 @@ import androidx.compose.material.MaterialTheme
3030import androidx.compose.material.Scaffold
3131import androidx.compose.material.Text
3232import androidx.compose.material.TopAppBar
33+ import androidx.compose.material.rememberScaffoldState
3334import androidx.compose.runtime.Composable
3435import androidx.compose.runtime.CompositionLocalProvider
3536import androidx.compose.runtime.mutableStateOf
37+ import androidx.compose.runtime.rememberCoroutineScope
3638import androidx.compose.runtime.saveable.rememberSaveable
3739import androidx.compose.ui.Modifier
3840import androidx.compose.ui.graphics.Color
3941import androidx.compose.ui.platform.LocalLayoutDirection
4042import androidx.compose.ui.res.stringResource
43+ import androidx.compose.ui.text.LinkAnnotation
4144import androidx.compose.ui.text.SpanStyle
45+ import androidx.compose.ui.text.TextLinkStyles
4246import androidx.compose.ui.text.TextStyle
4347import androidx.compose.ui.text.buildAnnotatedString
4448import androidx.compose.ui.text.font.FontFamily
4549import androidx.compose.ui.text.font.FontStyle
4650import androidx.compose.ui.text.font.FontWeight
4751import androidx.compose.ui.text.style.TextDecoration
4852import androidx.compose.ui.text.style.TextDirection
53+ import androidx.compose.ui.text.withLink
4954import androidx.compose.ui.text.withStyle
5055import androidx.compose.ui.tooling.preview.PreviewLightDark
5156import androidx.compose.ui.unit.LayoutDirection
@@ -55,14 +60,20 @@ import com.webtoonscorp.android.readmore.foundation.BasicReadMoreText
5560import com.webtoonscorp.android.readmore.foundation.ReadMoreTextOverflow
5661import com.webtoonscorp.android.readmore.foundation.ToggleArea
5762import com.webtoonscorp.android.readmore.sample.R
63+ import kotlinx.coroutines.launch
5864
5965@Composable
6066fun BasicReadMoreTextDemo () {
67+ val scaffoldState = rememberScaffoldState()
68+ val coroutineScope = rememberCoroutineScope()
6169 Scaffold (
70+ scaffoldState = scaffoldState,
6271 topBar = {
63- TopAppBar (title = {
64- Text (text = stringResource(id = R .string.compose_foundation_title))
65- })
72+ TopAppBar (
73+ title = {
74+ Text (text = stringResource(id = R .string.compose_foundation_title))
75+ },
76+ )
6677 },
6778 content = {
6879 val scrollState = rememberScrollState()
@@ -76,7 +87,7 @@ fun BasicReadMoreTextDemo() {
7687 Divider ()
7788 Item_Hyperfocus ()
7889 Divider ()
79- ItemReunion ()
90+ Item_Reunion ()
8091 Divider ()
8192 Item_TheWorldAfterTheFall ()
8293 Divider ()
@@ -88,6 +99,12 @@ fun BasicReadMoreTextDemo() {
8899 Divider ()
89100 Item_Emoji ()
90101 Divider ()
102+ Item_Hyperlink { message ->
103+ coroutineScope.launch {
104+ scaffoldState.snackbarHostState.showSnackbar(message = message)
105+ }
106+ }
107+ Divider ()
91108 }
92109 },
93110 )
@@ -164,7 +181,7 @@ private fun Item_Hyperfocus() {
164181}
165182
166183@Composable
167- private fun ItemReunion () {
184+ private fun Item_Reunion () {
168185 val (expanded, onExpandedChange) = rememberSaveable { mutableStateOf(false ) }
169186 Column {
170187 Text (
@@ -426,6 +443,57 @@ private fun Item_Emoji() {
426443 }
427444}
428445
446+ @Composable
447+ private fun Item_Hyperlink (showMessage : (String ) -> Unit ) {
448+ val (expanded, onExpandedChange) = rememberSaveable { mutableStateOf(false ) }
449+ Column {
450+ Text (
451+ text = stringResource(id = R .string.title_hyperlink),
452+ modifier = Modifier
453+ .fillMaxWidth()
454+ .padding(start = 18 .dp, end = 18 .dp, top = 16 .dp),
455+ color = MaterialTheme .colors.onSurface,
456+ fontSize = 18 .sp,
457+ fontWeight = FontWeight .Bold ,
458+ )
459+ BasicReadMoreText (
460+ text = buildAnnotatedString {
461+ repeat(30 ) { index ->
462+ withLink(
463+ LinkAnnotation .Clickable (
464+ tag = " TAG$index " ,
465+ styles = TextLinkStyles (style = SpanStyle (color = Color .Blue )),
466+ ) {
467+ showMessage(" #TAG$index Clicked!" )
468+ },
469+ ) {
470+ append(" #TAG$index " )
471+ }
472+ append(' ' )
473+ }
474+ append(" END" )
475+ },
476+ expanded = expanded,
477+ onExpandedChange = onExpandedChange,
478+ modifier = Modifier
479+ .fillMaxWidth()
480+ .padding(start = 18 .dp, top = 5 .dp, end = 18 .dp, bottom = 18 .dp),
481+ style = TextStyle .Default .copy(
482+ color = MaterialTheme .colors.onSurface,
483+ fontSize = 15 .sp,
484+ fontStyle = FontStyle .Normal ,
485+ lineHeight = 22 .sp,
486+ ),
487+ readMoreMaxLines = 3 ,
488+ readMoreText = stringResource(id = R .string.read_more),
489+ readMoreStyle = SpanStyle (
490+ textDecoration = TextDecoration .Underline ,
491+ ),
492+ readLessText = stringResource(id = R .string.read_less),
493+ )
494+ }
495+ }
496+
429497@PreviewLightDark
430498@Composable
431499private fun Preview () {
0 commit comments