Skip to content

Commit 2a16eef

Browse files
Added remaining item text change for over flow tag.
1 parent 14acc31 commit 2a16eef

File tree

3 files changed

+45
-17
lines changed

3 files changed

+45
-17
lines changed

core/ui/src/main/java/co/yml/coreui/core/ui/ytag/TagViewContainer.kt

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import androidx.compose.foundation.clickable
66
import androidx.compose.foundation.layout.*
77
import androidx.compose.foundation.shape.CircleShape
88
import androidx.compose.foundation.shape.RoundedCornerShape
9-
import androidx.compose.runtime.Composable
9+
import androidx.compose.runtime.*
1010
import androidx.compose.ui.Modifier
1111
import androidx.compose.ui.graphics.Color
1212
import androidx.compose.ui.layout.Layout
@@ -34,9 +34,14 @@ fun TagViewContainer(
3434
tagViewContainerModifiers: TagViewContainerModifiers
3535
) {
3636
//add overflow details tag into the list
37-
val updatedTagViewData = tagViewData.toMutableList()
37+
val overFlowText = remember {
38+
mutableStateOf("")
39+
}
40+
3841
val moreTag = tagViewContainerModifiers.moreTagConfiguration
39-
updatedTagViewData.add(moreTag)
42+
val remainingTags: (Int) -> Unit = { count ->
43+
overFlowText.value = moreTag.overFlowText.invoke(count)
44+
}
4045

4146
with(tagViewContainerModifiers) {
4247
val context = LocalContext.current
@@ -82,9 +87,10 @@ fun TagViewContainer(
8287
modifier = modifier
8388
) {
8489
TagViewContainerLayout(
90+
remainingTags = remainingTags,
8591
tagViewContainerModifiers = tagViewContainerModifiers,
8692
content = {
87-
updatedTagViewData.forEach {
93+
tagViewData.forEach {
8894
with(it) {
8995
val containerItemClick = {
9096
tagViewContainerModifiers.onClick.invoke(it)
@@ -100,6 +106,22 @@ fun TagViewContainer(
100106
)
101107
}
102108
}
109+
110+
//over flow item
111+
with(moreTag) {
112+
val containerItemClick = {
113+
tagViewContainerModifiers.onClick.invoke(this)
114+
}
115+
TagView(
116+
text = overFlowText.value,
117+
leadingIcon = leadingIcon,
118+
trailingIcon = trailingIcon,
119+
enabled = enabled,
120+
tagViewModifiers = tagViewModifiers,
121+
overFlowText = "",
122+
onClick = containerItemClick
123+
)
124+
}
103125
})
104126
}
105127
}
@@ -108,10 +130,12 @@ fun TagViewContainer(
108130
/**
109131
* [TagViewContainerLayout] used for creating a custom layout to hosting y tag
110132
* @param tagViewContainerModifiers collection of modifier elements that decorate or add behavior to tag view container
111-
* @param content content of the container [Tag views]
133+
* @param content content of the tag view container
134+
* @param remainingTags return item count which are not rendered in the tag view container
112135
*/
113136
@Composable
114137
fun TagViewContainerLayout(
138+
remainingTags: (Int) -> Unit,
115139
tagViewContainerModifiers: TagViewContainerModifiers,
116140
content: @Composable () -> Unit
117141
) {
@@ -174,7 +198,8 @@ fun TagViewContainerLayout(
174198
placeAbles,
175199
tagViewContainerModifiers,
176200
constraints,
177-
localDensity
201+
localDensity,
202+
remainingTags
178203
)
179204
overflow?.let {
180205
it.first.place(it.second)
@@ -190,7 +215,8 @@ fun TagViewContainerLayout(
190215
placeAbles,
191216
tagViewContainerModifiers,
192217
constraints,
193-
localDensity
218+
localDensity,
219+
remainingTags
194220
)
195221
overflow?.let {
196222
it.first.place(it.second)
@@ -209,13 +235,15 @@ fun TagViewContainerLayout(
209235
* @param tagViewContainerModifiers collection of modifier elements that decorate or add behavior to tag view container
210236
* @param constraints immutable constraints for measuring layouts
211237
* @param localDensity A density of the screen. Used for the conversions between pixels and Dp
238+
* @param remainingItems return item count which are not rendered in the tag view container
212239
*/
213240
fun showOverFlow(
214241
index: Int,
215242
placeAbles: List<Pair<Placeable, IntOffset>>,
216243
tagViewContainerModifiers: TagViewContainerModifiers,
217244
constraints: Constraints,
218-
localDensity: Density
245+
localDensity: Density,
246+
remainingItems: (Int) -> Unit
219247
): Pair<Placeable, IntOffset>? {
220248
val offset = placeAbles[index].second
221249
val placeable = placeAbles[index]
@@ -238,12 +266,12 @@ fun showOverFlow(
238266

239267
if (moreTagXOffset + moreTagPlaceAble.first.width < constraints.maxWidth && moreTagYOffset + moreTagPlaceAble.first.height < constraints.maxHeight) {
240268
val remainingTags = placeAbles.lastIndex - index
241-
tagViewContainerModifiers.moreTagConfiguration.overFlowText.invoke(remainingTags)
269+
remainingItems.invoke(remainingTags)
242270
return Pair(moreTagPlaceAble.first, IntOffset(moreTagXOffset, moreTagYOffset))
243271
}
244272
}
245273
val remainingTags = placeAbles.lastIndex - index
246-
tagViewContainerModifiers.moreTagConfiguration.overFlowText.invoke(remainingTags)
274+
remainingItems.invoke(remainingTags)
247275
return moreTagPlaceAble
248276
}
249277
} else {

core/ui/src/main/java/co/yml/coreui/core/ui/ytag/model/TagViewData.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import androidx.compose.runtime.Composable
55
/**
66
* [TagViewData] Used for holding the TagView data
77
*
8-
* @param text text the text to be displayed
8+
* @param text Tag view text to be displayed
99
* @param leadingIcon the optional leading icon to be displayed at the beginning of the TagView
1010
* @param trailingIcon the optional leading icon to be displayed at the end of the TagView
1111
* @param enabled controls the enabled state of the TagView
1212
* @param tagViewModifiers collection of modifier elements that decorate or add behavior to TagView elements
13+
* @param showOverFlow show or hide over flow text
14+
* @param overFlowText to be displayed for over flow tag [use overFlowText instead of [text] for over flow tag ]
1315
*/
1416
data class TagViewData(
15-
val text: String,
17+
val text: String = "",
1618
val tagViewModifiers: TagViewModifiers = TagViewModifiers.Builder().build(),
1719
val leadingIcon: @Composable ((enable: Boolean) -> Unit)? = null,
1820
val trailingIcon: @Composable ((enable: Boolean) -> Unit)? = null,

feature/ytag/src/main/java/co/yml/coreui/feature/ytag/ui/YTagActivity.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,13 +357,11 @@ fun DefaultTagViewContainer() {
357357
.tagSpacingHorizontal(8.dp)
358358
.backgroundColor(Color.Gray)
359359
.width(250.dp)
360-
.height(250.dp)
360+
.height(240.dp)
361361
.moreTagConfiguration(
362362
TagViewData(
363-
text = "more",
364-
overFlowText = { count ->
365-
Log.i("check_over_flow","remaining tags: $count")
366-
"$count more items"
363+
overFlowText = {count ->
364+
"$count more"
367365
},
368366
tagViewModifiers = TagViewModifiers.Builder().backgroundColor(Color.Gray)
369367
.width(100.dp)

0 commit comments

Comments
 (0)