1515 */
1616package com.webtoonscorp.android.readmore.foundation
1717
18+ import androidx.compose.foundation.background
19+ import androidx.compose.foundation.layout.Box
20+ import androidx.compose.foundation.layout.fillMaxSize
21+ import androidx.compose.foundation.layout.padding
22+ import androidx.compose.foundation.shape.RoundedCornerShape
23+ import androidx.compose.foundation.text.BasicText
24+ import androidx.compose.foundation.text.InlineTextContent
25+ import androidx.compose.foundation.text.appendInlineContent
1826import androidx.compose.runtime.Composable
1927import androidx.compose.runtime.CompositionLocalProvider
2028import androidx.compose.runtime.Stable
29+ import androidx.compose.ui.Alignment
30+ import androidx.compose.ui.Modifier
31+ import androidx.compose.ui.draw.clip
2132import androidx.compose.ui.graphics.Color
2233import androidx.compose.ui.platform.LocalLayoutDirection
2334import androidx.compose.ui.test.junit4.createComposeRule
2435import androidx.compose.ui.test.onRoot
2536import androidx.compose.ui.text.AnnotatedString
37+ import androidx.compose.ui.text.Placeholder
38+ import androidx.compose.ui.text.PlaceholderVerticalAlign
2639import androidx.compose.ui.text.SpanStyle
2740import androidx.compose.ui.text.TextStyle
2841import androidx.compose.ui.text.buildAnnotatedString
@@ -31,6 +44,7 @@ import androidx.compose.ui.text.font.FontWeight
3144import androidx.compose.ui.text.style.TextDecoration
3245import androidx.compose.ui.text.withStyle
3346import androidx.compose.ui.unit.LayoutDirection
47+ import androidx.compose.ui.unit.dp
3448import androidx.compose.ui.unit.sp
3549import com.github.takahirom.roborazzi.RoborazziRule
3650import com.github.takahirom.roborazzi.captureRoboImage
@@ -117,6 +131,102 @@ internal class BasicReadMoreTextScreenshotTest(
117131 readMoreText = " Read more" ,
118132 readLessText = " Read less" ,
119133 ),
134+ AnnotatedStringScreenshotTestCase (
135+ name = " InlineTextContent" ,
136+ text = buildAnnotatedString {
137+ appendInlineContent(" start" )
138+ append(" Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." )
139+ appendInlineContent(" middle" )
140+ append(" Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." )
141+ appendInlineContent(" end" )
142+ },
143+ inlineContent = mapOf (
144+ " start" to InlineTextContent (
145+ Placeholder (
146+ width = 55 .sp,
147+ height = 15 .sp,
148+ placeholderVerticalAlign = PlaceholderVerticalAlign .TextCenter ,
149+ ),
150+ ) {
151+ val shape = RoundedCornerShape (4 .dp)
152+ Box (
153+ contentAlignment = Alignment .Center ,
154+ modifier = Modifier
155+ .padding(end = 5 .dp)
156+ .fillMaxSize()
157+ .background(color = Color .Red , shape = shape)
158+ .clip(shape = shape),
159+ ) {
160+ BasicText (
161+ text = " START" ,
162+ style = TextStyle .Default .copy(
163+ color = Color .White ,
164+ fontSize = 13 .sp,
165+ fontWeight = FontWeight .Bold ,
166+ lineHeight = 14 .sp,
167+ ),
168+ )
169+ }
170+ },
171+ " middle" to InlineTextContent (
172+ Placeholder (
173+ width = 70 .sp,
174+ height = 15 .sp,
175+ placeholderVerticalAlign = PlaceholderVerticalAlign .TextCenter ,
176+ ),
177+ ) {
178+ val shape = RoundedCornerShape (4 .dp)
179+ Box (
180+ contentAlignment = Alignment .Center ,
181+ modifier = Modifier
182+ .padding(horizontal = 5 .dp)
183+ .fillMaxSize()
184+ .background(color = Color .Blue , shape = shape)
185+ .clip(shape = shape),
186+ ) {
187+ BasicText (
188+ text = " MIDDLE" ,
189+ style = TextStyle .Default .copy(
190+ color = Color .White ,
191+ fontSize = 13 .sp,
192+ fontWeight = FontWeight .Bold ,
193+ lineHeight = 14 .sp,
194+ ),
195+ )
196+ }
197+ },
198+ " end" to InlineTextContent (
199+ Placeholder (
200+ width = 35 .sp,
201+ height = 15 .sp,
202+ placeholderVerticalAlign = PlaceholderVerticalAlign .TextCenter ,
203+ ),
204+ ) {
205+ val shape = RoundedCornerShape (4 .dp)
206+ Box (
207+ contentAlignment = Alignment .Center ,
208+ modifier = Modifier
209+ .padding(start = 5 .dp)
210+ .fillMaxSize()
211+ .background(color = Color .Green , shape = shape)
212+ .clip(shape = shape),
213+ ) {
214+ BasicText (
215+ text = " END" ,
216+ style = TextStyle .Default .copy(
217+ color = Color .White ,
218+ fontSize = 13 .sp,
219+ fontWeight = FontWeight .Bold ,
220+ lineHeight = 14 .sp,
221+ ),
222+ )
223+ }
224+ },
225+ ),
226+ maxLines = 4 ,
227+ readMoreText = " Read more" ,
228+ readLessText = " Read less" ,
229+ ),
120230 )
121231 }
122232 }
@@ -292,12 +402,14 @@ internal class BasicReadMoreTextScreenshotTest(
292402 is AnnotatedStringScreenshotTestCase -> {
293403 BasicReadMoreText (
294404 text = testCase.text,
405+ inlineContent = testCase.inlineContent,
295406 expanded = expanded,
296407 style = TextStyle .Default .copy(
297408 fontSize = 15 .sp,
298409 fontStyle = FontStyle .Normal ,
299410 lineHeight = 22 .sp,
300411 ),
412+ readMoreMaxLines = testCase.maxLines,
301413 readMoreText = readMoreText,
302414 readMoreStyle = SpanStyle (
303415 color = Color .Blue ,
@@ -340,6 +452,8 @@ internal data class StringScreenshotTestCase(
340452internal data class AnnotatedStringScreenshotTestCase (
341453 override val name : String ,
342454 val text : AnnotatedString ,
455+ val inlineContent : Map <String , InlineTextContent > = mapOf(),
456+ val maxLines : Int = 2 ,
343457 override val readMoreText : String ,
344458 override val readLessText : String ,
345459 override val isRtl : Boolean = false ,
0 commit comments