Skip to content

Commit d2a3515

Browse files
committed
fix(Picker): Picker 滑动后长按会出现一直滚动 fix #301
1 parent 94f4c61 commit d2a3515

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

packages/core/src/Picker/index.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,11 @@ const Picker = (props: PickerProps) => {
9292
containerHeight,
9393
};
9494
}, [containerStyle, textStyle]);
95-
const getItemHeight = (event: LayoutChangeEvent, index: number) => {
95+
const getItemHeight = (event: LayoutChangeEvent) => {
9696
const { height } = event.nativeEvent.layout;
9797
const round = Math.round(height);
98-
ItemHeights[index] = round * ItemHeights.length + round;
98+
ItemHeights.push(round * ItemHeights.length + round);
9999
};
100-
101100
const location = (scrollY: number, index: number) => {
102101
saveY.current = scrollY - (style.containerHeight as number);
103102
currentY.current = index;
@@ -113,7 +112,7 @@ const Picker = (props: PickerProps) => {
113112
setCurrent(0);
114113
return false;
115114
}
116-
const stringSpot = spot + '';
115+
const stringSpot = spot + '.0';
117116
const integer = Math.floor(spot);
118117
const decimal = Number(stringSpot[stringSpot.indexOf('.') + 1]);
119118
const itemIndex = decimal >= 6 ? integer + 1 : integer;
@@ -158,7 +157,7 @@ const Picker = (props: PickerProps) => {
158157
>
159158
{date.map((item, index) => (
160159
<Pressable
161-
onLayout={(event: LayoutChangeEvent) => getItemHeight(event, index)}
160+
onLayout={getItemHeight}
162161
key={index}
163162
onPressOut={Platform.OS === 'android' ? onTouchEnd : undefined}
164163
onPress={() => {

0 commit comments

Comments
 (0)