Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,10 @@ public List<FlexLine> getFlexLines() {

@Override
public int getDecorationLengthMainAxis(View view, int index, int indexInFlexLine) {
View v = mRecycler.getViewForPosition(index);
calculateItemDecorationsForChild(v, TEMP_RECT);
if (isMainAxisDirectionHorizontal()) {
return getLeftDecorationWidth(view) + getRightDecorationWidth(view);
return getLeftDecorationWidth(v) + getRightDecorationWidth(v);
Copy link

@ghost ghost Aug 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't like this solution. Why? You're creating new View instance instead of reusing the existing one.

Code from lines 371 and 372 you should put into if conditional statement, but instead of using new v variable, please use existing view.

To be more precise:

if (isMainAxisDirectionHorizontal()) {
         view = mRecycler.getViewForPosition(index);
         calculateItemDecorationsForChild(view, TEMP_RECT);
         return getLeftDecorationWidth(view) + getRightDecorationWidth(view);
} else {
          return getTopDecorationHeight(view) + getBottomDecorationHeight(view);
}

Another thing - did you write any test or check it on more than 3 different devices?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.I have modify the code.
But i have to say.
view = mRecycler.getViewForPosition(index);
calculateItemDecorationsForChild(view, TEMP_RECT);
Here actually is not the best solution because calculateItemDecorationsForChild is invoked frequent.But it is a solution.
At last. I write the test code and test on HUAWEI and SAMSUNG devices.

} else {
return getTopDecorationHeight(view) + getBottomDecorationHeight(view);
}
Expand Down