From 9aad722cf5feaf929a24391cd116ff1a93e521a5 Mon Sep 17 00:00:00 2001 From: Soon Wang Date: Tue, 7 Jul 2026 14:33:20 +0800 Subject: [PATCH 1/2] fix(picker-view): round item height calculations and update refs for timers --- .../react/mpx-picker-view-column/index.tsx | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-picker-view-column/index.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-picker-view-column/index.tsx index 60bd010771..8a9ed223ce 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-picker-view-column/index.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-picker-view-column/index.tsx @@ -66,14 +66,15 @@ const _PickerViewColumn = forwardRef, }) const { height: pickerH, itemHeight } = wrapperStyle - const [itemRawH, setItemRawH] = useState(itemHeight) + const [itemRawH, setItemRawH] = useState(Math.round(itemHeight)) + const itemRawHRef = useRef(itemRawH) const maxIndex = useMemo(() => columnData.length - 1, [columnData]) const prevScrollingInfo = useRef({ index: initialIndex, y: 0 }) const dragging = useRef(false) const scrolling = useRef(false) - const timerResetPosition = useRef(null) - const timerScrollTo = useRef(null) - const timerClickOnce = useRef(null) + const timerResetPosition = useRef | null>(null) + const timerScrollTo = useRef | null>(null) + const timerClickOnce = useRef | null>(null) const activeIndex = useRef(initialIndex) const prevIndex = usePrevious(initialIndex) const prevMaxIndex = usePrevious(maxIndex) @@ -88,9 +89,16 @@ const _PickerViewColumn = forwardRef, nodeRef: scrollViewRef }) + const updateItemRawH = useCallback((height: number) => { + if (height && height !== itemRawHRef.current) { + itemRawHRef.current = height + setItemRawH(height) + } + }, []) + const paddingHeight = useMemo( - () => Math.round((pickerH - itemHeight) / 2), - [pickerH, itemHeight] + () => (pickerH - itemRawH) / 2, + [pickerH, itemRawH] ) const snapToOffsets = useMemo( @@ -164,13 +172,14 @@ const _PickerViewColumn = forwardRef, }, isIOS ? 0 : 200) }, [itemRawH, maxIndex, initialIndex]) + useEffect(() => { + updateItemRawH(Math.round(itemHeight)) + }, [itemHeight, updateItemRawH]) + const onItemLayout = useCallback((e: LayoutChangeEvent) => { const { height: rawH } = e.nativeEvent.layout - const roundedH = Math.round(rawH) - if (roundedH && roundedH !== itemRawH) { - setItemRawH(roundedH) - } - }, [itemRawH]) + updateItemRawH(Math.round(rawH)) + }, [updateItemRawH]) const resetScrollPosition = useCallback((y: number) => { if (dragging.current || scrolling.current) { @@ -293,7 +302,7 @@ const _PickerViewColumn = forwardRef, key={index} item={item} index={index} - itemHeight={itemHeight} + itemHeight={itemRawH} visibleCount={visibleCount} onItemLayout={onItemLayout} />) @@ -301,7 +310,7 @@ const _PickerViewColumn = forwardRef, key={index} item={item} index={index} - itemHeight={itemHeight} + itemHeight={itemRawH} onItemLayout={onItemLayout} />) }) @@ -346,14 +355,14 @@ const _PickerViewColumn = forwardRef, const renderIndicator = () => ( ) const renderMask = () => ( ) From 44d560fd18c802736ec5a9a4b93a618ae6f3850b Mon Sep 17 00:00:00 2001 From: Soon Wang Date: Wed, 8 Jul 2026 17:35:40 +0800 Subject: [PATCH 2/2] fix(picker-view): simplify item height handling and remove unused references --- .../react/mpx-picker-view-column/index.tsx | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-picker-view-column/index.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-picker-view-column/index.tsx index 8a9ed223ce..9fe4c6b245 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-picker-view-column/index.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-picker-view-column/index.tsx @@ -67,7 +67,6 @@ const _PickerViewColumn = forwardRef, const { height: pickerH, itemHeight } = wrapperStyle const [itemRawH, setItemRawH] = useState(Math.round(itemHeight)) - const itemRawHRef = useRef(itemRawH) const maxIndex = useMemo(() => columnData.length - 1, [columnData]) const prevScrollingInfo = useRef({ index: initialIndex, y: 0 }) const dragging = useRef(false) @@ -89,13 +88,6 @@ const _PickerViewColumn = forwardRef, nodeRef: scrollViewRef }) - const updateItemRawH = useCallback((height: number) => { - if (height && height !== itemRawHRef.current) { - itemRawHRef.current = height - setItemRawH(height) - } - }, []) - const paddingHeight = useMemo( () => (pickerH - itemRawH) / 2, [pickerH, itemRawH] @@ -173,13 +165,19 @@ const _PickerViewColumn = forwardRef, }, [itemRawH, maxIndex, initialIndex]) useEffect(() => { - updateItemRawH(Math.round(itemHeight)) - }, [itemHeight, updateItemRawH]) + const roundedH = Math.round(itemHeight) + if (roundedH) { + setItemRawH(roundedH) + } + }, [itemHeight]) const onItemLayout = useCallback((e: LayoutChangeEvent) => { const { height: rawH } = e.nativeEvent.layout - updateItemRawH(Math.round(rawH)) - }, [updateItemRawH]) + const roundedH = Math.round(rawH) + if (roundedH) { + setItemRawH(roundedH) + } + }, []) const resetScrollPosition = useCallback((y: number) => { if (dragging.current || scrolling.current) {