Skip to content

Commit e8bc3b2

Browse files
authored
deprecate children, migrate picker props (#3078)
* deprecate children, migrate picker props * deprecation of onShow prop
1 parent 48ffdc9 commit e8bc3b2

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

src/components/picker/helpers/usePickerMigrationWarnings.tsx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
import {useEffect} from 'react';
2-
import _ from 'lodash';
32
import {LogService} from '../../../services';
4-
import {PickerProps, PickerModes} from '../types';
3+
import {PickerProps} from '../types';
54

6-
// @ts-expect-error TODO: Remove this whole file when migration is completed
7-
type UsePickerMigrationWarnings = Pick<PickerProps, 'value' | 'mode' | 'useNativePicker'>;
5+
// TODO: Remove this whole file when migration is completed
6+
type UsePickerMigrationWarnings = Pick<
7+
PickerProps,
8+
'children' | 'migrate' | 'getItemLabel' | 'getItemValue' | 'onShow'
9+
>;
810

911
const usePickerMigrationWarnings = (props: UsePickerMigrationWarnings) => {
10-
const {value, mode, useNativePicker} = props;
12+
const {children, migrate, getItemLabel, getItemValue, onShow} = props;
1113
useEffect(() => {
12-
if (mode === PickerModes.SINGLE && Array.isArray(value)) {
13-
LogService.warn('Picker in SINGLE mode cannot accept an array for value');
14+
if (children) {
15+
LogService.warn(`UILib Picker will stop supporting the 'children' prop in the next major version, please pass 'items' prop instead`);
1416
}
15-
if (mode === PickerModes.MULTI && !Array.isArray(value)) {
16-
LogService.warn('Picker in MULTI mode must accept an array for value');
17+
18+
if (migrate) {
19+
LogService.warn(`UILib Picker will stop supporting the 'migrate' prop in the next major version, please stop using it. The picker uses the new implementation by default.`);
20+
}
21+
22+
if (getItemLabel) {
23+
LogService.warn(`UILib Picker will stop supporting the 'getItemLabel' prop in the next major version, please pass the 'getItemLabel' prop to the specific item instead`);
1724
}
1825

19-
if (_.isPlainObject(value)) {
20-
LogService.warn('UILib Picker will stop supporting passing object as value in the next major version. Please use either string or a number as value');
26+
if (getItemValue) {
27+
LogService.warn(`UILib Picker will stop supporting the 'getItemValue' prop in the next major version, please stop using it. The value will be extract from 'items' prop instead`);
2128
}
2229

23-
if (useNativePicker) {
24-
LogService.warn(`UILib Picker will stop supporting the 'useNativePicker' prop soon, please pass instead the 'useWheelPicker' prop and handle relevant TextField migration if required to`);
30+
if (onShow) {
31+
LogService.warn(`UILib Picker will stop supporting the 'onShow' prop in the next major version, please pass the 'onShow' prop from the 'pickerModalProps' instead`);
2532
}
2633
}, []);
2734
};

src/components/picker/index.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// TODO: deprecate getItemLabel prop
44
// TODO: Add initialValue prop
55
// TODO: consider deprecating renderCustomModal prop
6-
// TODO: deprecate onShow cause it's already supported by passing it in pickerModalProps
76
import _ from 'lodash';
87
import React, {useMemo, useState, useRef, useCallback, useEffect} from 'react';
98
import {LayoutChangeEvent} from 'react-native';
@@ -23,7 +22,7 @@ import usePickerSelection from './helpers/usePickerSelection';
2322
import usePickerLabel from './helpers/usePickerLabel';
2423
import usePickerSearch from './helpers/usePickerSearch';
2524
import useImperativePickerHandle from './helpers/useImperativePickerHandle';
26-
// import usePickerMigrationWarnings from './helpers/usePickerMigrationWarnings';
25+
import usePickerMigrationWarnings from './helpers/usePickerMigrationWarnings';
2726
import {extractPickerItems} from './PickerPresenter';
2827
import {
2928
PickerProps,
@@ -107,8 +106,8 @@ const Picker = React.forwardRef((props: PickerProps, ref) => {
107106

108107
const pickerExpandable = useRef<ExpandableOverlayMethods>(null);
109108

110-
// TODO: Remove
111-
// usePickerMigrationWarnings({value, mode});
109+
// TODO: Remove this when migration is completed, starting of v8
110+
usePickerMigrationWarnings({children, migrate, getItemLabel, getItemValue});
112111

113112
const pickerRef = useImperativePickerHandle(ref, pickerExpandable);
114113
const {

src/components/picker/types.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export type PickerBaseProps = Omit<NewTextFieldProps, 'value' | 'onChange'> & {
5555
*/
5656
useDialog?: boolean;
5757
/**
58+
* @deprecated
5859
* Temporary prop required for migration to Picker's new API
5960
*/
6061
migrate?: boolean;
@@ -172,6 +173,7 @@ export type PickerBaseProps = Omit<NewTextFieldProps, 'value' | 'onChange'> & {
172173
*/
173174
containerStyle?: StyleProp<ViewStyle>;
174175
/**
176+
* @deprecated
175177
* Callback for modal onShow event
176178
*/
177179
onShow?: () => void;
@@ -187,6 +189,9 @@ export type PickerBaseProps = Omit<NewTextFieldProps, 'value' | 'onChange'> & {
187189
* Component test id
188190
*/
189191
testID?: string;
192+
/**
193+
* @deprecated
194+
*/
190195
children?: ReactNode | undefined;
191196
};
192197

0 commit comments

Comments
 (0)