From 7c3af22ed0223eb305259c0f614fea0e34dc6e67 Mon Sep 17 00:00:00 2001 From: Denis Panic Date: Wed, 28 Aug 2019 08:44:32 +0200 Subject: [PATCH] force set all items to adapter when wrap_content is set to RV, issues fixed: #349 #336 #339 --- .../android/flexbox/FlexboxLayoutManager.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/flexbox/src/main/java/com/google/android/flexbox/FlexboxLayoutManager.java b/flexbox/src/main/java/com/google/android/flexbox/FlexboxLayoutManager.java index 56d1a607..d778a219 100644 --- a/flexbox/src/main/java/com/google/android/flexbox/FlexboxLayoutManager.java +++ b/flexbox/src/main/java/com/google/android/flexbox/FlexboxLayoutManager.java @@ -182,6 +182,14 @@ public class FlexboxLayoutManager extends RecyclerView.LayoutManager implements /** The reference to the parent of the RecyclerView */ private View mParent; + /** + * if mFillAllItemsForced == true fixes all issues with "not all items displayed when wrap_content" + * issues: #349 #336 #339 + */ + private Boolean mSetAllItemsForced = false; + + + /** * Indicates the position that the view position that the flex line which has the view having * this position needs to be recomputed before the next layout. @@ -312,6 +320,14 @@ public void setFlexWrap(@FlexWrap int flexWrap) { } } + public Boolean getmSetAllItemsForced() { + return mSetAllItemsForced; + } + + public void setmSetAllItemsForced(Boolean mSetAllItemsForced) { + this.mSetAllItemsForced = mSetAllItemsForced; + } + @JustifyContent @Override public int getJustifyContent() { @@ -874,7 +890,8 @@ private void updateFlexLines(int childCount) { // passed as 0 from the RecyclerView) // Set the upper limit as the height of the device in order to prevent computing all // items in the adapter - needsToFill = mLayoutState.mInfinite ? + // or set the mSetAllItemsForced to true to force all items to show + needsToFill = mSetAllItemsForced ? 999999999 : mLayoutState.mInfinite ? mContext.getResources().getDisplayMetrics().heightPixels : mLayoutState.mAvailable; } else { @@ -885,7 +902,8 @@ private void updateFlexLines(int childCount) { // passed as 0 from the RecyclerView) // Set the upper limit as the width of the device in order to prevent computing all // items in the adapter - needsToFill = mLayoutState.mInfinite ? + // or set the mSetAllItemsForced to true to force all items to show + needsToFill = mSetAllItemsForced ? 999999999 : mLayoutState.mInfinite ? mContext.getResources().getDisplayMetrics().widthPixels : mLayoutState.mAvailable; }