11package co.yml.coreui.core.ui.ytag
22
3- import android.util.Log
43import androidx.compose.foundation.background
54import androidx.compose.foundation.border
65import androidx.compose.foundation.clickable
@@ -34,7 +33,7 @@ fun TagViewContainer(
3433 tagViewData : List <TagViewData >,
3534 tagViewContainerModifiers : TagViewContainerModifiers
3635) {
37- // add more tag into the list
36+ // add overflow details tag into the list
3837 val updatedTagViewData = tagViewData.toMutableList()
3938 val moreTag = tagViewContainerModifiers.moreTagConfiguration
4039 updatedTagViewData.add(moreTag)
@@ -69,7 +68,7 @@ fun TagViewContainer(
6968 .clickable { }
7069 .semantics {
7170 this .contentDescription =
72- context.getString(co.yml.coreui.ui.R .string.tag_view_container_accessibility_title)
71+ tagViewContainerModifiers.semantics.ifEmpty { context.getString(co.yml.coreui.ui.R .string.tag_view_container_accessibility_title) }
7372 }
7473 .testTag(" tag_view_container" )
7574 .background(
@@ -127,20 +126,14 @@ fun TagViewContainerLayout(
127126 var currentRow = 0
128127 var currentOffset = IntOffset .Zero
129128
129+ // Measurement phase
130130 val placeAbles = measurables.map { measurable ->
131131 val placeAble: Placeable = measurable.measure(looseConstraints)
132132
133+ // calculate the offsets to place the tags in layout phase
133134 if (currentOffset.x > 0f && currentOffset.x + placeAble.width + tagViewContainerModifiers.tagSpacingHorizontal.toPx()
134135 .toInt() > constraints.maxWidth
135136 ) {
136- Log .i(
137- " check_measure" ,
138- " c.XOffset: ${currentOffset.x} p.Width: ${placeAble.width} p.Height: ${placeAble.height} tagHSpace: ${
139- tagViewContainerModifiers.tagSpacingHorizontal.toPx().toInt()
140- } tagVSpace: ${
141- tagViewContainerModifiers.tagSpacingVertical.toPx().toInt()
142- } max w: ${constraints.maxWidth} "
143- )
144137 currentRow + = 1
145138 currentOffset =
146139 currentOffset.copy(
@@ -161,30 +154,21 @@ fun TagViewContainerLayout(
161154 width = constraints.maxWidth,
162155 height = constraints.maxHeight
163156 ) {
164- Log .i(" check_placeAble" , " size: ${placeAbles.size} " )
165- placeAbles.forEachIndexed { index, placeable ->
166- val (placeable, offset) = placeable
167- // check whether current item has enough space
157+ placeAbles.forEachIndexed { index, tagPlaceable ->
158+ val (placeable, offset) = tagPlaceable
159+ // check whether container has enough space to place the current tag
168160 if (offset.x + placeable.width < constraints.maxWidth && offset.y + placeable.height < constraints.maxHeight) {
169- // current item has space
170- Log .i(" check_placeable" , " index: $index current item has space" )
161+ // space available for current tag
171162 val nextItemIndex = index + 1
163+ // check whether container has enough space to place the next tag
172164 if (nextItemIndex <= placeAbles.lastIndex) {
173165 val nextItemOffset = placeAbles[nextItemIndex].second
174- Log .i(
175- " check_placeable" ,
176- " next index: $nextItemIndex nextItemOffset : $nextItemOffset Before checking"
177- )
178166 if (nextItemOffset.x + placeAbles[nextItemIndex].first.width < constraints.maxWidth && nextItemOffset.y + placeAbles[nextItemIndex].first.height < constraints.maxHeight) {
179- // next item has space
180- Log .i(
181- " check_placeable" ,
182- " next index: $nextItemIndex nextItemOffset : $nextItemOffset next item has space and placed"
183- )
167+ // space available for next tag
184168 placeable.place(offset.x, offset.y)
185169 } else {
186- // next item has no space
187- // check space to accommodate more tag
170+ // space not available for next tag
171+ // place the over flow tag
188172 val overflow = showOverFlow(
189173 index,
190174 placeAbles,
@@ -199,8 +183,8 @@ fun TagViewContainerLayout(
199183 }
200184 }
201185 } else {
202- // current item has no space
203- // check space to accommodate more tag
186+ // space available for current tag
187+ // place the over flow tag
204188 val overflow = showOverFlow(
205189 index,
206190 placeAbles,
@@ -237,18 +221,12 @@ fun showOverFlow(
237221 val placeable = placeAbles[index]
238222
239223 if (tagViewContainerModifiers.moreTagConfiguration.showOverFlow) {
240- Log .i(" check_placeable" , " index: $index next item has no space" )
241224 val moreTagPlaceAble = placeAbles.last()
242225 val remainingTags = placeAbles.lastIndex - 1 - index
243226
244227 if (offset.x + moreTagPlaceAble.first.width < constraints.maxWidth && offset.y + moreTagPlaceAble.first.height < constraints.maxHeight) {
245228 // place more tag
246- Log .i(
247- " check_placeable" ,
248- " index: $index more tag placed offset: $offset "
249- )
250-
251- // check whether more tag can be placed in between current and previous offset
229+ // check whether space available for over flow tag to place in between current [which replace over flow tag] and previous tags
252230 val previousIndex = index - 1
253231 if (previousIndex >= 0 ) {
254232 val previousOffset = placeAbles[previousIndex].second
@@ -260,18 +238,11 @@ fun showOverFlow(
260238 val moreTagYOffset = previousOffset.y
261239
262240 if (moreTagXOffset + moreTagPlaceAble.first.width < constraints.maxWidth && moreTagYOffset + moreTagPlaceAble.first.height < constraints.maxHeight) {
263- Log .i(
264- " check_placeable" ,
265- " prev index: $previousIndex more tag placed on in btw offset: $previousOffset "
266- )
267-
268241 return Pair (moreTagPlaceAble.first, IntOffset (moreTagXOffset, moreTagYOffset))
269242 }
270243 }
271244
272245 return moreTagPlaceAble
273- } else {
274- Log .i(" check_placeable" , " index: $index more tag has no space" )
275246 }
276247 } else {
277248 return placeable
0 commit comments