2017-01-02 02:22:45 -08:00
|
|
|
/**
|
2022-10-04 13:59:32 -07:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2017-01-02 02:22:45 -08:00
|
|
|
*
|
2018-02-16 18:24:55 -08:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2018-01-19 11:25:26 -08:00
|
|
|
*
|
|
|
|
* @format
|
2017-01-02 02:22:45 -08:00
|
|
|
*/
|
|
|
|
|
2023-05-04 08:11:04 -07:00
|
|
|
import type { MeasureFunction } from "yoga-layout";
|
|
|
|
import { Yoga } from "./globals";
|
|
|
|
|
|
|
|
export type MeasureCounter = {
|
|
|
|
inc: MeasureFunction;
|
|
|
|
get: () => number;
|
|
|
|
};
|
|
|
|
|
|
|
|
export function getMeasureCounter(
|
|
|
|
cb?: MeasureFunction | null,
|
|
|
|
staticWidth = 0,
|
|
|
|
staticHeight = 0
|
|
|
|
): MeasureCounter {
|
2022-12-28 01:27:12 -08:00
|
|
|
let counter = 0;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2018-01-19 11:25:26 -08:00
|
|
|
return {
|
2022-12-28 01:27:12 -08:00
|
|
|
inc: function (width, widthMode, height, heightMode) {
|
2018-01-19 11:25:26 -08:00
|
|
|
counter += 1;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2018-01-19 11:25:26 -08:00
|
|
|
return cb
|
|
|
|
? cb(width, widthMode, height, heightMode)
|
2022-12-28 01:27:12 -08:00
|
|
|
: { width: staticWidth, height: staticHeight };
|
2018-01-19 11:25:26 -08:00
|
|
|
},
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2022-12-28 01:27:12 -08:00
|
|
|
get: function () {
|
2018-01-19 11:25:26 -08:00
|
|
|
return counter;
|
|
|
|
},
|
|
|
|
};
|
2023-05-04 08:11:04 -07:00
|
|
|
}
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2023-05-04 08:11:04 -07:00
|
|
|
export function getMeasureCounterMax(): MeasureCounter {
|
|
|
|
return getMeasureCounter((width, widthMode, height, heightMode) => {
|
2022-12-28 01:27:12 -08:00
|
|
|
const measuredWidth =
|
|
|
|
widthMode === Yoga.MEASURE_MODE_UNDEFINED ? 10 : width;
|
|
|
|
const measuredHeight =
|
2018-01-19 11:25:26 -08:00
|
|
|
heightMode === Yoga.MEASURE_MODE_UNDEFINED ? 10 : height;
|
|
|
|
|
2022-12-28 01:27:12 -08:00
|
|
|
return { width: measuredWidth, height: measuredHeight };
|
2018-01-19 11:25:26 -08:00
|
|
|
});
|
2023-05-04 08:11:04 -07:00
|
|
|
}
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2023-05-04 08:11:04 -07:00
|
|
|
export function getMeasureCounterMin(): MeasureCounter {
|
|
|
|
return getMeasureCounter((width, widthMode, height, heightMode) => {
|
2022-12-28 01:27:12 -08:00
|
|
|
const measuredWidth =
|
2018-01-19 11:25:26 -08:00
|
|
|
widthMode === Yoga.MEASURE_MODE_UNDEFINED ||
|
|
|
|
(widthMode == Yoga.MEASURE_MODE_AT_MOST && width > 10)
|
|
|
|
? 10
|
|
|
|
: width;
|
2022-12-28 01:27:12 -08:00
|
|
|
const measuredHeight =
|
2018-01-19 11:25:26 -08:00
|
|
|
heightMode === Yoga.MEASURE_MODE_UNDEFINED ||
|
|
|
|
(heightMode == Yoga.MEASURE_MODE_AT_MOST && height > 10)
|
|
|
|
? 10
|
|
|
|
: height;
|
|
|
|
|
2022-12-28 01:27:12 -08:00
|
|
|
return { width: measuredWidth, height: measuredHeight };
|
2018-01-19 11:25:26 -08:00
|
|
|
});
|
2023-05-04 08:11:04 -07:00
|
|
|
}
|