Skip to content

Commit

Permalink
fix:(DatePicker): 修复第一次选中无效
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenlingasMx committed Apr 24, 2023
1 parent 3cc7fe9 commit d82a2b2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { memo } from 'react';
import { Animated, StyleSheet, Text } from 'react-native';
import { WhellPickerItemProps } from './type';
import { Theme } from '../.././../theme';
Expand Down Expand Up @@ -46,11 +46,10 @@ function WheelPickerItem({ textStyle, style, visibleRest, height, option, index,
return (
<Animated.View style={[styles.option, style, { height, opacity, transform: [{ rotateX }, { scale }] }]}>
<Text style={[{ color: textColor }, textStyle]}>{option?.label}</Text>
</Animated.View >
</Animated.View>
);
}

export default WheelPickerItem;
export default memo(WheelPickerItem, () => true);

const styles = StyleSheet.create({
option: {
Expand Down
4 changes: 0 additions & 4 deletions packages/core/src/Picker/components/WheelPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,8 @@ export default function WheelPicker({
const currentScrollIndex = Animated.add(Animated.divide(scrollY, itemHeight), 2);

const handleMomentumScrollEnd = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
// Due to list bounciness when scrolling to the start or the end of the list
// the offset might be negative or over the last item.
// We therefore clamp the offset to the supported range.
const offsetY = Math.min(itemHeight * (data.length - 1), Math.max(event.nativeEvent.contentOffset.y, 0));
let index = offsetY / itemHeight + 1;

const currentItem = data[index - 1];
if (currentItem) {
onChange?.(currentItem.value);
Expand Down

0 comments on commit d82a2b2

Please sign in to comment.