@@ -209,10 +209,11 @@ private int[] sortOrdersIntoReorderedIndices(int childCount, List<Order> orders,
209209 * Calculate how many flex lines are needed in the flex container.
210210 * This method should calculate all the flex lines from the existing flex items.
211211 *
212- * @see #calculateFlexLines(int, int, int, int, int, List)
212+ * @see #calculateFlexLines(FlexLinesResult, int, int, int, int, int, List)
213213 */
214- FlexLinesResult calculateHorizontalFlexLines (int widthMeasureSpec , int heightMeasureSpec ) {
215- return calculateFlexLines (widthMeasureSpec , heightMeasureSpec , Integer .MAX_VALUE ,
214+ void calculateHorizontalFlexLines (FlexLinesResult result , int widthMeasureSpec ,
215+ int heightMeasureSpec ) {
216+ calculateFlexLines (result , widthMeasureSpec , heightMeasureSpec , Integer .MAX_VALUE ,
216217 0 , NO_POSITION , null );
217218 }
218219
@@ -221,6 +222,9 @@ FlexLinesResult calculateHorizontalFlexLines(int widthMeasureSpec, int heightMea
221222 * Stop calculating it if the calculated amount along the cross size reaches the argument
222223 * as the needsCalcAmount.
223224 *
225+ * @param result an instance of {@link FlexLinesResult} that is going to contain a
226+ * list of flex lines and the child state used by
227+ * {@link View#setMeasuredDimension(int, int)}.
224228 * @param widthMeasureSpec the width measure spec imposed by the flex container
225229 * @param heightMeasureSpec the height measure spec imposed by the flex container
226230 * @param needsCalcAmount the amount of pixels where flex line calculation should be stopped
@@ -233,10 +237,10 @@ FlexLinesResult calculateHorizontalFlexLines(int widthMeasureSpec, int heightMea
233237 * @param fromIndex the index of the child from which the calculation starts
234238 * @param existingLines If not null, calculated flex lines will be added to this instance
235239 */
236- FlexLinesResult calculateHorizontalFlexLines (int widthMeasureSpec ,
240+ void calculateHorizontalFlexLines (FlexLinesResult result , int widthMeasureSpec ,
237241 int heightMeasureSpec , int needsCalcAmount , int fromIndex ,
238242 @ Nullable List <FlexLine > existingLines ) {
239- return calculateFlexLines (widthMeasureSpec , heightMeasureSpec , needsCalcAmount ,
243+ calculateFlexLines (result , widthMeasureSpec , heightMeasureSpec , needsCalcAmount ,
240244 fromIndex , NO_POSITION , existingLines );
241245 }
242246
@@ -247,6 +251,9 @@ FlexLinesResult calculateHorizontalFlexLines(int widthMeasureSpec,
247251 * flex lines which includes the view who has the index as the {@code toIndex} argument.
248252 * (First calculate to the toIndex, then calculate the amount of pixels as needsCalcAmount)
249253 *
254+ * @param result an instance of {@link FlexLinesResult} that is going to contain a
255+ * list of flex lines and the child state used by
256+ * {@link View#setMeasuredDimension(int, int)}.
250257 * @param widthMeasureSpec the width measure spec imposed by the flex container
251258 * @param heightMeasureSpec the height measure spec imposed by the flex container
252259 * @param needsCalcAmount the amount of pixels where flex line calculation should be stopped
@@ -262,22 +269,25 @@ FlexLinesResult calculateHorizontalFlexLines(int widthMeasureSpec,
262269 * to the index, calculate the amount of pixels as the needsCalcAmount
263270 * argument in addition to that
264271 */
265- FlexLinesResult calculateHorizontalFlexLinesToIndex (int widthMeasureSpec , int heightMeasureSpec ,
266- int needsCalcAmount , int toIndex , List <FlexLine > existingLines ) {
267- return calculateFlexLines (widthMeasureSpec , heightMeasureSpec , needsCalcAmount ,
272+ void calculateHorizontalFlexLinesToIndex (FlexLinesResult result , int widthMeasureSpec ,
273+ int heightMeasureSpec , int needsCalcAmount , int toIndex , List <FlexLine > existingLines ) {
274+ calculateFlexLines (result , widthMeasureSpec , heightMeasureSpec , needsCalcAmount ,
268275 0 , toIndex , existingLines );
269276 }
270277
271278 /**
272279 * Calculate how many flex lines are needed in the flex container.
273280 * This method should calculate all the flex lines from the existing flex items.
274281 *
282+ * @param result an instance of {@link FlexLinesResult} that is going to contain a
283+ * list of flex lines and the child state used by
284+ * {@link View#setMeasuredDimension(int, int)}.
275285 * @param widthMeasureSpec the width measure spec imposed by the flex container
276286 * @param heightMeasureSpec the height measure spec imposed by the flex container
277- * @see #calculateFlexLines(int, int, int, int, int, List)
287+ * @see #calculateFlexLines(FlexLinesResult, int, int, int, int, int, List)
278288 */
279- FlexLinesResult calculateVerticalFlexLines (int widthMeasureSpec , int heightMeasureSpec ) {
280- return calculateFlexLines (heightMeasureSpec , widthMeasureSpec , Integer .MAX_VALUE ,
289+ void calculateVerticalFlexLines (FlexLinesResult result , int widthMeasureSpec , int heightMeasureSpec ) {
290+ calculateFlexLines (result , heightMeasureSpec , widthMeasureSpec , Integer .MAX_VALUE ,
281291 0 , NO_POSITION , null );
282292 }
283293
@@ -286,6 +296,9 @@ FlexLinesResult calculateVerticalFlexLines(int widthMeasureSpec, int heightMeasu
286296 * Stop calculating it if the calculated amount along the cross size reaches the argument
287297 * as the needsCalcAmount.
288298 *
299+ * @param result an instance of {@link FlexLinesResult} that is going to contain a
300+ * list of flex lines and the child state used by
301+ * {@link View#setMeasuredDimension(int, int)}.
289302 * @param widthMeasureSpec the width measure spec imposed by the flex container
290303 * @param heightMeasureSpec the height measure spec imposed by the flex container
291304 * @param needsCalcAmount the amount of pixels where flex line calculation should be stopped
@@ -298,10 +311,10 @@ FlexLinesResult calculateVerticalFlexLines(int widthMeasureSpec, int heightMeasu
298311 * @param fromIndex the index of the child from which the calculation starts
299312 * @param existingLines If not null, calculated flex lines will be added to this instance
300313 */
301- FlexLinesResult calculateVerticalFlexLines (int widthMeasureSpec ,
314+ void calculateVerticalFlexLines (FlexLinesResult result , int widthMeasureSpec ,
302315 int heightMeasureSpec , int needsCalcAmount , int fromIndex ,
303316 @ Nullable List <FlexLine > existingLines ) {
304- return calculateFlexLines (heightMeasureSpec , widthMeasureSpec , needsCalcAmount ,
317+ calculateFlexLines (result , heightMeasureSpec , widthMeasureSpec , needsCalcAmount ,
305318 fromIndex , NO_POSITION , existingLines );
306319 }
307320
@@ -312,6 +325,9 @@ FlexLinesResult calculateVerticalFlexLines(int widthMeasureSpec,
312325 * flex lines which includes the view who has the index as the {@code toIndex} argument.
313326 * (First calculate to the toIndex, then calculate the amount of pixels as needsCalcAmount)
314327 *
328+ * @param result an instance of {@link FlexLinesResult} that is going to contain a
329+ * list of flex lines and the child state used by
330+ * {@link View#setMeasuredDimension(int, int)}.
315331 * @param widthMeasureSpec the width measure spec imposed by the flex container
316332 * @param heightMeasureSpec the height measure spec imposed by the flex container
317333 * @param needsCalcAmount the amount of pixels where flex line calculation should be stopped
@@ -327,9 +343,9 @@ FlexLinesResult calculateVerticalFlexLines(int widthMeasureSpec,
327343 * to the index, calculate the amount of pixels as the needsCalcAmount
328344 * argument in addition to that
329345 */
330- FlexLinesResult calculateVerticalFlexLinesToIndex (int widthMeasureSpec , int heightMeasureSpec ,
331- int needsCalcAmount , int toIndex , List <FlexLine > existingLines ) {
332- return calculateFlexLines (heightMeasureSpec , widthMeasureSpec , needsCalcAmount ,
346+ void calculateVerticalFlexLinesToIndex (FlexLinesResult result , int widthMeasureSpec ,
347+ int heightMeasureSpec , int needsCalcAmount , int toIndex , List <FlexLine > existingLines ) {
348+ calculateFlexLines (result , heightMeasureSpec , widthMeasureSpec , needsCalcAmount ,
333349 0 , toIndex , existingLines );
334350 }
335351
@@ -341,6 +357,9 @@ FlexLinesResult calculateVerticalFlexLinesToIndex(int widthMeasureSpec, int heig
341357 * attributes are done in a later procedure, so the views' measured width and measured
342358 * height may be changed in a later process.
343359 *
360+ * @param result an instance of {@link FlexLinesResult} that is going to contain a
361+ * list of flex lines and the child state used by
362+ * {@link View#setMeasuredDimension(int, int)}.
344363 * @param mainMeasureSpec the main axis measure spec imposed by the flex container,
345364 * width for horizontal direction, height otherwise
346365 * @param crossMeasureSpec the cross axis measure spec imposed by the flex container,
@@ -359,11 +378,9 @@ FlexLinesResult calculateVerticalFlexLinesToIndex(int widthMeasureSpec, int heig
359378 * to the index, calculate the amount of pixels as the needsCalcAmount
360379 * argument in addition to that
361380 * @param existingLines If not null, calculated flex lines will be added to this instance
362- * @return an instance of {@link FlexLinesResult} that contains a list of flex lines and the
363- * child state used by {@link View#setMeasuredDimension(int, int)}.
364381 */
365- FlexLinesResult calculateFlexLines (int mainMeasureSpec , int crossMeasureSpec ,
366- int needsCalcAmount , int fromIndex , int toIndex ,
382+ void calculateFlexLines (FlexLinesResult result , int mainMeasureSpec ,
383+ int crossMeasureSpec , int needsCalcAmount , int fromIndex , int toIndex ,
367384 @ Nullable List <FlexLine > existingLines ) {
368385
369386 boolean isMainHorizontal = mFlexContainer .isMainAxisDirectionHorizontal ();
@@ -380,7 +397,6 @@ FlexLinesResult calculateFlexLines(int mainMeasureSpec, int crossMeasureSpec,
380397 flexLines = existingLines ;
381398 }
382399
383- FlexLinesResult result = new FlexLinesResult ();
384400 result .mFlexLines = flexLines ;
385401
386402 boolean reachedToIndex = toIndex == NO_POSITION ;
@@ -603,7 +619,6 @@ FlexLinesResult calculateFlexLines(int mainMeasureSpec, int crossMeasureSpec,
603619 }
604620
605621 result .mChildState = childState ;
606- return result ;
607622 }
608623
609624 /**
@@ -1981,5 +1996,10 @@ static class FlexLinesResult {
19811996 List <FlexLine > mFlexLines ;
19821997
19831998 int mChildState ;
1999+
2000+ void reset () {
2001+ mFlexLines = null ;
2002+ mChildState = 0 ;
2003+ }
19842004 }
19852005}
0 commit comments