Skip to content

Commit 38e1e60

Browse files
authored
Merge pull request #925 from thundersdata-frontend/rn-issue
fix: 修复不小心提交的bug
2 parents 4ea3c3c + 2bce597 commit 38e1e60

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

packages/react-native-picker/src/picker/components/Normal/index.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ function NormalPicker<T>(props: ImperativeModalChildrenProps<NormalPickerProps<T
1313
const {
1414
title,
1515
data,
16-
request,
1716
value,
1817
onChange,
1918
cancelText = '取消',
@@ -23,15 +22,16 @@ function NormalPicker<T>(props: ImperativeModalChildrenProps<NormalPickerProps<T
2322
...restProps
2423
} = props;
2524

26-
const { selectedValue, handleOk, handleChange, handleClose, options } = useNormalPicker({
27-
data,
28-
request,
25+
const initialValue = data.length > 0 ? data[0].value : undefined;
26+
27+
const { selectedValue, handleOk, handleChange, handleClose } = useNormalPicker({
2928
value,
29+
initialValue,
3030
onChange,
3131
closeModal,
3232
});
3333

34-
if (options.length === 0) return null;
34+
if (data.length === 0) return null;
3535

3636
return (
3737
<>
@@ -59,7 +59,7 @@ function NormalPicker<T>(props: ImperativeModalChildrenProps<NormalPickerProps<T
5959
</Pressable>
6060
</Flex>
6161
<Box height={px(200)}>
62-
<WheelPicker {...restProps} data={options} value={selectedValue} onChange={handleChange} />
62+
<WheelPicker {...restProps} data={data} value={selectedValue} onChange={handleChange} />
6363
</Box>
6464
</>
6565
);

packages/react-native-picker/src/picker/components/Normal/useNormalPicker.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ import { NormalPickerProps } from '../../type';
66

77
export default function useNormalPicker<T>({
88
value,
9+
initialValue,
910
onChange,
1011
closeModal,
11-
}: ImperativeModalChildrenProps<Omit<NormalPickerProps<T>, 'data'>>) {
12-
const initialValue = data.length > 0 ? data[0].value : undefined;
13-
12+
}: ImperativeModalChildrenProps<Omit<NormalPickerProps<T>, 'data'> & { initialValue?: T }>) {
1413
const [selectedValue, selectValue] = useSafeState<T | undefined>(value || initialValue);
1514

1615
const handleChange = (val: PickerData<T>) => {

packages/react-native-picker/src/picker/type.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,13 @@ import { CascadePickerItemProps, WheelPickerPropsBase } from '../components/Whee
22

33
export interface PickerProps<T> extends WheelPickerPropsBase {
44
/** 选择项列表 */
5-
data?: CascadePickerItemProps<T>[];
6-
/** 请求数据 */
7-
request?: () => Promise<CascadePickerItemProps<T>[]>;
5+
data: CascadePickerItemProps<T>[];
86
/** 是否级联 */
97
cascade?: boolean;
108
/** 展示几列 */
119
cols?: number;
1210
value?: T[] | T;
1311
onChange?: (value?: T extends (infer U)[] ? U[] : T) => void;
14-
/** 字段名 */
15-
fieldNames?: {
16-
label?: string;
17-
value?: string;
18-
children?: string;
19-
};
2012
}
2113

2214
/** 弹窗Picker的属性 */

0 commit comments

Comments
 (0)