Skip to content

Commit ac96a29

Browse files
committed
chore(Picker): fix android onMomentumScrollEnd in ScrollViewPorps 失效
1 parent ae676a4 commit ac96a29

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/core/src/Picker/index.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ const Picker = (props: PickerProps) => {
9494
}, [containerStyle, textStyle]);
9595
const location = (scrollY: number, index: number) => {
9696
scrollView.current?.scrollTo({ x: 0, y: scrollY - (style.containerHeight as number), animated: true });
97+
saveY.current = scrollY - (style.containerHeight as number);
9798
currentY.current = index;
99+
if (Platform.OS === 'android') {
100+
setCurrent(index);
101+
}
98102
};
99103
const scrollYEnd = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
100104
if (onPressORonScroll.current === 'onScroll') {
@@ -117,6 +121,7 @@ const Picker = (props: PickerProps) => {
117121
}
118122
if (saveY.current <= ItemHeights[0] / 1.1) {
119123
scrollView.current?.scrollTo({ x: 0, y: 0, animated: true });
124+
saveY.current = 0;
120125
setCurrent(0);
121126
return false;
122127
}
@@ -126,6 +131,7 @@ const Picker = (props: PickerProps) => {
126131
const itemIndex = decimal >= 9 ? integer + 1 : integer;
127132
scrollView.current?.scrollTo({ x: 0, y: ItemHeights[itemIndex] - ItemHeights[0], animated: true });
128133
setCurrent(itemIndex);
134+
saveY.current = ItemHeights[itemIndex] - ItemHeights[0];
129135
isScroll.current = false;
130136
isTouchEnd.current = false;
131137
};
@@ -148,6 +154,9 @@ const Picker = (props: PickerProps) => {
148154
if (onPressORonScroll.current === 'onPress' || flag) {
149155
return false;
150156
}
157+
if (saveY.current === event.nativeEvent.contentOffset.y) {
158+
return false;
159+
}
151160
isScroll.current = false;
152161
saveY.current = event.nativeEvent.contentOffset.y;
153162
if (timer.current) {

0 commit comments

Comments
 (0)