@@ -179,49 +179,69 @@ fun TagViewContainerLayout(
179179 height = constraints.maxHeight
180180 ) {
181181 placeAbles.forEachIndexed { index, tagPlaceable ->
182- val (placeable, offset) = tagPlaceable
183- // check whether container has enough space to place the current tag
184- if (offset.x + placeable.width < constraints.maxWidth && offset.y + placeable.height < constraints.maxHeight) {
185- // space available for current tag
186- val nextItemIndex = index + 1
187- // check whether container has enough space to place the next tag
188- if (nextItemIndex <= placeAbles.lastIndex) {
189- val nextItemOffset = placeAbles[nextItemIndex].second
190- if (nextItemOffset.x + placeAbles[nextItemIndex].first.width < constraints.maxWidth && nextItemOffset.y + placeAbles[nextItemIndex].first.height < constraints.maxHeight) {
191- // space available for next tag
192- placeable.place(offset.x, offset.y)
193- } else {
194- // space not available for next tag
195- // place the over flow tag
196- val overflow = showOverFlow(
197- index,
198- placeAbles,
199- tagViewContainerModifiers,
200- constraints,
201- localDensity,
202- remainingTags
203- )
204- overflow?.let {
205- it.first.place(it.second)
182+ if (index != placeAbles.lastIndex) {
183+ val (placeable, offset) = tagPlaceable
184+ // check whether container has enough space to place the current tag
185+ if (offset.x + placeable.width < constraints.maxWidth && offset.y + placeable.height < constraints.maxHeight) {
186+ // space available for current tag
187+ val nextItemIndex = index + 1
188+ // check whether container has enough space to place the next tag
189+ if (nextItemIndex <= placeAbles.lastIndex) {
190+ val nextItemOffset = placeAbles[nextItemIndex].second
191+ if (nextItemOffset.x + placeAbles[nextItemIndex].first.width < constraints.maxWidth && nextItemOffset.y + placeAbles[nextItemIndex].first.height < constraints.maxHeight) {
192+ // space available for next tag
193+ placeable.place(offset.x, offset.y)
194+ } else {
195+ // space not available for next tag
196+ // place the over flow tag
197+ // check whether to accommodate current tag and more
198+ val moreTagPlaceAble = placeAbles.last()
199+ val moreXOffset =
200+ offset.x + placeable.width + tagViewContainerModifiers.tagSpacingHorizontal.toPx()
201+ .toInt()
202+ val moreYOffset = offset.y
203+ if (moreXOffset + moreTagPlaceAble.first.width < constraints.maxWidth &&
204+ moreYOffset + moreTagPlaceAble.first.height < constraints.maxHeight
205+ ) {
206+ // place current tag
207+ placeable.place(offset.x, offset.y)
208+ // place more tag
209+ val remainingItems = placeAbles.lastIndex - 1 - index
210+ remainingTags.invoke(remainingItems)
211+ moreTagPlaceAble.first.place(moreXOffset, moreYOffset)
212+ return @layout
213+ } else {
214+ val overflow = showOverFlow(
215+ index,
216+ placeAbles,
217+ tagViewContainerModifiers,
218+ constraints,
219+ localDensity,
220+ remainingTags
221+ )
222+ overflow?.let {
223+ it.first.place(it.second)
224+ }
225+ return @layout
226+ }
206227 }
207- return @layout
208228 }
229+ } else {
230+ // space not available for current tag
231+ // place the over flow tag
232+ val overflow = showOverFlow(
233+ index,
234+ placeAbles,
235+ tagViewContainerModifiers,
236+ constraints,
237+ localDensity,
238+ remainingTags
239+ )
240+ overflow?.let {
241+ it.first.place(it.second)
242+ }
243+ return @layout
209244 }
210- } else {
211- // space available for current tag
212- // place the over flow tag
213- val overflow = showOverFlow(
214- index,
215- placeAbles,
216- tagViewContainerModifiers,
217- constraints,
218- localDensity,
219- remainingTags
220- )
221- overflow?.let {
222- it.first.place(it.second)
223- }
224- return @layout
225245 }
226246 }
227247 }
@@ -247,10 +267,8 @@ fun showOverFlow(
247267): Pair <Placeable , IntOffset >? {
248268 val offset = placeAbles[index].second
249269 val placeable = placeAbles[index]
250-
251270 if (tagViewContainerModifiers.moreTagConfiguration.showOverFlow) {
252271 val moreTagPlaceAble = placeAbles.last()
253-
254272 if (offset.x + moreTagPlaceAble.first.width < constraints.maxWidth && offset.y + moreTagPlaceAble.first.height < constraints.maxHeight) {
255273 // place more tag
256274 // check whether space available for over flow tag to place in between current [which replace over flow tag] and previous tags
@@ -272,7 +290,7 @@ fun showOverFlow(
272290 }
273291 val remainingTags = placeAbles.lastIndex - index
274292 remainingItems.invoke(remainingTags)
275- return moreTagPlaceAble
293+ return Pair ( moreTagPlaceAble.first, IntOffset (offset.x, offset.y))
276294 }
277295 } else {
278296 return placeable
0 commit comments