Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Showing blank space when removing very first item when content is long ( notifyItemRemoved() issue) #415

Open
1 task done
punitshah89 opened this issue Mar 16, 2018 · 4 comments

Comments

@punitshah89
Copy link

punitshah89 commented Mar 16, 2018

Issues and steps to reproduce

Using demo-playground

  1. Change settings of app to use width wrap_content for list item
  2. Change FlexItemViewHolder class inside com.google.android.flexbox package to show long content at 0th position
  3. Change FlexItemAdapter class's removeItem() function inside com.google.android.flexbox package to remove 0th item from list so when we press '-' button it removes from top
  4. Add items using "+" fab multiple times (7 times) based on list used (see attached snapshot)
  5. Remove item using "-" fab once

Expected behavior

RecyclerView should remove simply remove item and move all items accordingly

Version of the flexbox library

0.3.1, 0.3.2

Code example/snapshots based on repro steps

screenshot_1521163662
screenshot_1521163667

class FlexItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
   val textList: List<String> = listOf<String>(
           "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy",
           "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', ",
           "fdsfdsfdsfds", "gfgdfgdfgdfdf", "gdfgdfgfdgfd", "gff", "gfdgfd", "gfgdf", "gfdg")
   private val textView: TextView = itemView.findViewById(R.id.textview)

   fun bindTo(params: RecyclerView.LayoutParams) {
       val adapterPosition = adapterPosition
       textView.apply {
           text = textList[adapterPosition]
           setBackgroundResource(R.drawable.flex_item_background)
           gravity = Gravity.CENTER
           layoutParams = params
       }
   }
}
    fun removeItem(position: Int) {
        if (position < 0 || position >= layoutParams.size) {
            return
        }
        layoutParams.removeAt(0)
        notifyItemRemoved(0)
        notifyItemRangeChanged(position, layoutParams.size)
    }

screenshot_1521163698
5.
screenshot_1521163706

Note: if used notifyDataSetChange() instead of notifyItemRemoved works fine

@punitshah89
Copy link
Author

Hi @thagikura, looks there is issue in updateDirtyPosition() function inside FlexboxLayoutManager.java

I'm not sure about the best solution, but firstVisiblePosition <= positionStart condition satisfies and returns from function, my guess is this condition should be firstVisiblePosition < positionStart. changing this solves the issue.


        if (firstVisiblePosition <= positionStart && positionStart <= lastVisiblePosition) {
            return;
        }

        // Assign the pending scroll position and offset so that the first visible position is
        // restored in the next layout.
        mPendingScrollPosition = getPosition(firstView);

        if (!isMainAxisDirectionHorizontal() && mIsRtl) {
            mPendingScrollPositionOffset = mOrientationHelper.getDecoratedEnd(firstView) +
                    mOrientationHelper.getEndPadding();
        } else {
            mPendingScrollPositionOffset = mOrientationHelper.getDecoratedStart(firstView) -
                    mOrientationHelper.getStartAfterPadding();
        }

@WanDa1993
Copy link

I have the same problem here!!!
(1)In addition, it only appears when the first element is deleted.
(2)You will then find that after the first element is deleted, the next line will be blank.

@WanDa1993
Copy link

According to the form, I think FlexBoxLayoutManager + RecyclerView, it's going to generate strange reuse behavior

eg:
[xxxxxxx] [xxxxx]
[xxxxxxxxxxxx]
[xxxxxxxx]

removeItem -> [xxxxxxx] is index zero

addItem -> [xxxxxx] is index zero

notifyDataSetChanged

result:
[ xxxxxx ]
[ xxxx ]
[xxxxxxxxxxxx]
[xxxxxxxx]

@honglei92
Copy link

thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants