From c791a8e36309ce4887297fe711348f427e12954d Mon Sep 17 00:00:00 2001 From: Yiyue Tao <106640896+TinaPeach@users.noreply.github.com> Date: Wed, 31 Jan 2024 20:08:42 +0800 Subject: [PATCH] fix: `Ellipsis` optimize line height caculation (#227) --- .../components/ellipsis/components/js-ellipsis.tsx | 6 +++--- packages/common-widgets/utils/bezier-easing.ts | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/arcodesign/components/ellipsis/components/js-ellipsis.tsx b/packages/arcodesign/components/ellipsis/components/js-ellipsis.tsx index be3e1b55..dfd0496e 100644 --- a/packages/arcodesign/components/ellipsis/components/js-ellipsis.tsx +++ b/packages/arcodesign/components/ellipsis/components/js-ellipsis.tsx @@ -3,6 +3,7 @@ import ResizeObserver from 'resize-observer-polyfill'; import { JsEllipsisProps, JsEllipsisRef } from '../type'; import { getLineHeight, wrapTextChildNodesWithSpan } from '../utils/dom'; +import { useLatestRef } from '../../_helpers'; const JsEllipsis = forwardRef((props: JsEllipsisProps, ref: Ref) => { const { @@ -24,13 +25,12 @@ const JsEllipsis = forwardRef((props: JsEllipsisProps, ref: Ref) const domRef = useRef(null); const textRef = useRef(null); const ellipsisRef = useRef(null); - const ellipsisValueRef = useRef(ellipsis); - ellipsisValueRef.current = ellipsis; + const ellipsisValueRef = useLatestRef(ellipsis); const lineHeightRef = useRef(0); const setCurLineHeight = useCallback(() => { if (domRef.current) { - lineHeightRef.current = getLineHeight(domRef.current); + lineHeightRef.current = Math.round(getLineHeight(domRef.current)); } }, []); useEffect(() => { diff --git a/packages/common-widgets/utils/bezier-easing.ts b/packages/common-widgets/utils/bezier-easing.ts index e301c1d8..138c45f5 100644 --- a/packages/common-widgets/utils/bezier-easing.ts +++ b/packages/common-widgets/utils/bezier-easing.ts @@ -12,7 +12,6 @@ const SUBDIVISION_MAX_ITERATIONS = 10; const kSplineTableSize = 11; const kSampleStepSize = 1.0 / (kSplineTableSize - 1.0); - const float32ArraySupported = typeof Float32Array === 'function'; function A(aA1: number, aA2: number) {