google / flexbox-layout

Flexbox for Android
Apache License 2.0
18.22k stars 1.79k forks source link

Is there possible to set "needsToFill" not only mContext.getResources().getDisplayMetrics().heightPixels? #629

Open LiuBeixi opened 10 months ago

LiuBeixi commented 10 months ago

Issues and steps to reproduce

RecyclerView(height is wrap_content) + FlexboxLayoutManager and use a custom maxHeight to change RecyclerView heightMeasureSpec by makeMeasureSpec. when FlexboxLayoutManager updateFlexLines,it will use display height to judged sumCrossSize,so all child will be create and measure. But i just want to measure the child at maxHeight. create all child will drop RecyclerView performance

Expected behavior

measure those childviews that are needed. In my opinion, Is there possible to set needsToFill to getHeight()/getWidth() when spec mode is AT_MOST

Version of the flexbox library

3.0.0

Link to code

 if (isMainAxisDirectionHorizontal()) {
            isMainSizeChanged = mLastWidth != Integer.MIN_VALUE && mLastWidth != width;

            // If the mInfinite flag is set to true (that usually happens when RecyclerViews are
            // nested and inner RecyclerView's layout_height is set to wrap_content, thus height is
            // 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 ?
                    mContext.getResources().getDisplayMetrics().heightPixels
                    : mLayoutState.mAvailable;
        } else {
            isMainSizeChanged = mLastHeight != Integer.MIN_VALUE && mLastHeight != height;

            // If the mInfinite flag is set to true (that usually happens when RecyclerViews are
            // nested and inner RecyclerView's layout_width is set to wrap_content, thus width is
            // 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 ?
                    mContext.getResources().getDisplayMetrics().widthPixels
                    : mLayoutState.mAvailable;
        }