Skip to content

Commit

Permalink
fix: 修复不小心提交的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
chj-damon committed Jan 15, 2025
1 parent c7c10df commit 2bce597
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function NormalPicker<T>(props: ImperativeModalChildrenProps<NormalPickerProps<T
const {
title,
data,
request,
value,
onChange,
cancelText = '取消',
Expand All @@ -23,15 +22,16 @@ function NormalPicker<T>(props: ImperativeModalChildrenProps<NormalPickerProps<T
...restProps
} = props;

const { selectedValue, handleOk, handleChange, handleClose, options } = useNormalPicker({
data,
request,
const initialValue = data.length > 0 ? data[0].value : undefined;

const { selectedValue, handleOk, handleChange, handleClose } = useNormalPicker({
value,
initialValue,
onChange,
closeModal,
});

if (options.length === 0) return null;
if (data.length === 0) return null;

return (
<>
Expand Down Expand Up @@ -59,7 +59,7 @@ function NormalPicker<T>(props: ImperativeModalChildrenProps<NormalPickerProps<T
</Pressable>
</Flex>
<Box height={px(200)}>
<WheelPicker {...restProps} data={options} value={selectedValue} onChange={handleChange} />
<WheelPicker {...restProps} data={data} value={selectedValue} onChange={handleChange} />
</Box>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import { NormalPickerProps } from '../../type';

export default function useNormalPicker<T>({
value,
initialValue,
onChange,
closeModal,
}: ImperativeModalChildrenProps<Omit<NormalPickerProps<T>, 'data'>>) {
const initialValue = data.length > 0 ? data[0].value : undefined;

}: ImperativeModalChildrenProps<Omit<NormalPickerProps<T>, 'data'> & { initialValue?: T }>) {
const [selectedValue, selectValue] = useSafeState<T | undefined>(value || initialValue);

const handleChange = (val: PickerData<T>) => {
Expand Down
10 changes: 1 addition & 9 deletions packages/react-native-picker/src/picker/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,13 @@ import { CascadePickerItemProps, WheelPickerPropsBase } from '../components/Whee

export interface PickerProps<T> extends WheelPickerPropsBase {
/** 选择项列表 */
data?: CascadePickerItemProps<T>[];
/** 请求数据 */
request?: () => Promise<CascadePickerItemProps<T>[]>;
data: CascadePickerItemProps<T>[];
/** 是否级联 */
cascade?: boolean;
/** 展示几列 */
cols?: number;
value?: T[] | T;
onChange?: (value?: T extends (infer U)[] ? U[] : T) => void;
/** 字段名 */
fieldNames?: {
label?: string;
value?: string;
children?: string;
};
}

/** 弹窗Picker的属性 */
Expand Down

0 comments on commit 2bce597

Please sign in to comment.