Skip to content

Commit d82a2b2

Browse files
committed
fix:(DatePicker): 修复第一次选中无效
1 parent 3cc7fe9 commit d82a2b2

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

packages/core/src/Picker/components/WheelPicker/WheelPickerItem.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { memo } from 'react';
22
import { Animated, StyleSheet, Text } from 'react-native';
33
import { WhellPickerItemProps } from './type';
44
import { Theme } from '../.././../theme';
@@ -46,11 +46,10 @@ function WheelPickerItem({ textStyle, style, visibleRest, height, option, index,
4646
return (
4747
<Animated.View style={[styles.option, style, { height, opacity, transform: [{ rotateX }, { scale }] }]}>
4848
<Text style={[{ color: textColor }, textStyle]}>{option?.label}</Text>
49-
</Animated.View >
49+
</Animated.View>
5050
);
5151
}
52-
53-
export default WheelPickerItem;
52+
export default memo(WheelPickerItem, () => true);
5453

5554
const styles = StyleSheet.create({
5655
option: {

packages/core/src/Picker/components/WheelPicker/index.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,8 @@ export default function WheelPicker({
5151
const currentScrollIndex = Animated.add(Animated.divide(scrollY, itemHeight), 2);
5252

5353
const handleMomentumScrollEnd = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
54-
// Due to list bounciness when scrolling to the start or the end of the list
55-
// the offset might be negative or over the last item.
56-
// We therefore clamp the offset to the supported range.
5754
const offsetY = Math.min(itemHeight * (data.length - 1), Math.max(event.nativeEvent.contentOffset.y, 0));
5855
let index = offsetY / itemHeight + 1;
59-
6056
const currentItem = data[index - 1];
6157
if (currentItem) {
6258
onChange?.(currentItem.value);

0 commit comments

Comments
 (0)