Skip to content

Commit

Permalink
chore: adjust code
Browse files Browse the repository at this point in the history
  • Loading branch information
TinaPeach committed Sep 13, 2023
1 parent df01464 commit 6ab6579
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions packages/arcodesign/components/picker/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useEffect, useState, useRef, forwardRef, Ref, useImperativeHandle } from 'react';
import React, { useEffect, useRef, forwardRef, Ref, useImperativeHandle } from 'react';
import { cls, componentWrapper, nextTick } from '@arco-design/mobile-utils';
import { ContextLayout } from '../context-provider';
import Popup from '../popup';
import PickerView, { PickerViewRef, ValueType, PickerCellMovingStatus } from '../picker-view';
import { PickerProps } from './type';
import { useListenResize } from '../_helpers';
import { useLatestRef, useListenResize } from '../_helpers';

export * from './type';
export { MultiPicker, PickerCell, Cascader } from '../picker-view';
Expand Down Expand Up @@ -70,7 +70,7 @@ const Picker = forwardRef((props: PickerProps, ref: Ref<PickerRef>) => {
...otherProps
} = props;

const [scrollValue, setScrollValue] = useState(value);
const scrollValueRef = useLatestRef(value);
const domRef = useRef<HTMLDivElement | null>(null);
const pickerViewRef = useRef<PickerViewRef>(null);

Expand All @@ -95,7 +95,7 @@ const Picker = forwardRef((props: PickerProps, ref: Ref<PickerRef>) => {
const handleConfirm = () => {
pickerViewRef.current?.scrollToCurrentIndex();
nextTick(() => {
const val = pickerViewRef.current?.getAllColumnValues() || scrollValue || [];
const val = pickerViewRef.current?.getAllColumnValues() || scrollValueRef.current || [];
if (onOk) {
onOk(val);
}
Expand All @@ -108,10 +108,6 @@ const Picker = forwardRef((props: PickerProps, ref: Ref<PickerRef>) => {
});
};

useEffect(() => {
setScrollValue(value);
}, [value]);

useListenResize(updateLayoutByVisible, [visible]);

// 每次visible从false变为true时需要重新设置scrollValue的值为当前value的值(初始值)
Expand Down

0 comments on commit 6ab6579

Please sign in to comment.