@@ -6,7 +6,7 @@ import androidx.compose.foundation.clickable
66import androidx.compose.foundation.layout.*
77import androidx.compose.foundation.shape.CircleShape
88import androidx.compose.foundation.shape.RoundedCornerShape
9- import androidx.compose.runtime.Composable
9+ import androidx.compose.runtime.*
1010import androidx.compose.ui.Modifier
1111import androidx.compose.ui.graphics.Color
1212import 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
114137fun 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 */
213240fun 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 {
0 commit comments