Skip to content

Commit

Permalink
Merge pull request #908 from thundersdata-frontend/rn-issue
Browse files Browse the repository at this point in the history
fix: 修复有时候没有滚动到value对应的选项的bug
  • Loading branch information
chj-damon authored Oct 14, 2024
2 parents 5e33a2a + e23a233 commit 6cea685
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-games-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@td-design/react-native-picker': patch
---

fix: 修复有时候没有滚动到value对应的选项的bug
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useMemo } from 'react';
import React from 'react';
import { StyleSheet, View } from 'react-native';
import { PanGestureHandler } from 'react-native-gesture-handler';
import Animated, {
Expand Down Expand Up @@ -27,13 +27,8 @@ export default function WheelPicker<T>({
onChange,
...props
}: WheelPickerProps<T>) {
const translateY = useSharedValue(0);

const initialIndex = useMemo(() => (value ? data.findIndex(item => item.value === value) : 0), [value, data]);

useEffect(() => {
translateY.value = -itemHeight * initialIndex;
}, [itemHeight, initialIndex]);
const initialIndex = value ? data.findIndex(item => item.value === value) : 0;
const translateY = useSharedValue(-itemHeight * initialIndex);

const snapPoints = new Array(data.length).fill(0).map((_, index) => -itemHeight * index);

Expand Down

0 comments on commit 6cea685

Please sign in to comment.