Skip to content

remove migrate prop, finish deprecation #3075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions demo/src/screens/realExamples/ProductPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class Product extends Component {

<View marginT-s2>
<Picker
migrate
value={selectedColor}
onChange={(value: PickerValue) => this.setState({selectedColor: value})}
trailingAccessory={
Expand All @@ -94,7 +93,6 @@ class Product extends Component {
})}
</Picker>
<Picker
migrate
value={selectedSize}
onChange={(value: PickerValue) => this.setState({selectedSize: value})}
>
Expand Down
11 changes: 0 additions & 11 deletions eslint-rules/tests/component_prop_deprecation.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,5 @@
"fix": {"propName": "subtitle"}
}
]
},
{
"component": "Picker",
"source": "module-with-deprecations",
"props": [
{
"prop": "migrate",
"message": "Please make sure to pass the 'migrate' prop.",
"isRequired": true
}
]
Comment on lines -83 to -91
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be taken as an example, it can stay here even after the removal of the migrate prop (or you can add a different example instead; this also fails a test that is run on this package)

}
]
18 changes: 6 additions & 12 deletions src/components/picker/PickerItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Image from '../image';
import Text from '../text';
import {getItemLabel, isItemSelected} from './PickerPresenter';
import PickerContext from './PickerContext';
import {PickerItemProps, PickerSingleValue} from './types';
import {PickerItemProps} from './types';

/**
* @description: Picker.Item, for configuring the Picker's selectable options
Expand All @@ -29,10 +29,8 @@ const PickerItem = (props: PickerItemProps) => {
testID
} = props;
const context = useContext(PickerContext);
const {migrate} = context;
const customRenderItem = context.renderItem || props.renderItem;
// @ts-expect-error TODO: fix after removing migrate prop completely
const itemValue = !migrate && typeof value === 'object' ? value?.value : value;
const itemValue = value;
const isSelected = isItemSelected(itemValue, context.value);
const itemLabel = getItemLabel(label, value, props.getItemLabel || context.getItemLabel);
const selectedCounter = context.selectionLimit && _.isArray(context.value) && context.value?.length;
Expand Down Expand Up @@ -65,16 +63,12 @@ const PickerItem = (props: PickerItemProps) => {
const _onPress = useCallback(async (props: any) => {
// Using !(await onPress?.(item)) does not work properly when onPress is not sent
// We have to explicitly state `false` so a synchronous void (undefined) will still work as expected
if (onPress && await onPress(context.isMultiMode ? !isSelected : undefined, props) === false) {
if (onPress && (await onPress(context.isMultiMode ? !isSelected : undefined, props)) === false) {
return;
}
if (migrate) {
context.onPress(value);
} else {
// @ts-expect-error TODO: fix after removing migrate prop completely
context.onPress(typeof value === 'object' || context.isMultiMode ? value : ({value, label: itemLabel}) as PickerSingleValue);
}
}, [migrate, value, context.onPress, onPress]);
context.onPress(value);
},
[value, context.onPress, onPress]);

const onSelectedLayout = useCallback((...args: any[]) => {
_.invoke(context, 'onSelectedLayout', ...args);
Expand Down
3 changes: 1 addition & 2 deletions src/components/picker/PickerPresenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export function isItemSelected(childValue: PickerSingleValue, selectedValue?: Pi
if (Array.isArray(selectedValue)) {
isSelected =
_.find(selectedValue, v => {
// @ts-expect-error TODO: fix after removing migrate prop completely
return v === childValue || (typeof v === 'object' && v?.value === childValue);
return v === childValue;
}) !== undefined;
} else {
isSelected = childValue === selectedValue;
Expand Down
12 changes: 3 additions & 9 deletions src/components/picker/helpers/usePickerSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import _ from 'lodash';
import {PickerProps, PickerValue, PickerSingleValue, PickerMultiValue, PickerModes} from '../types';

interface UsePickerSelectionProps
extends Pick<PickerProps, 'migrate' | 'value' | 'onChange' | 'getItemValue' | 'topBarProps' | 'mode'> {
extends Pick<PickerProps, 'value' | 'onChange' | 'getItemValue' | 'topBarProps' | 'mode'> {
pickerExpandableRef: RefObject<any>;
setSearchValue: (searchValue: string) => void;
}

const usePickerSelection = (props: UsePickerSelectionProps) => {
const {migrate, value, onChange, topBarProps, pickerExpandableRef, getItemValue, setSearchValue, mode} = props;
const {value, onChange, topBarProps, pickerExpandableRef, getItemValue, setSearchValue, mode} = props;
const [multiDraftValue, setMultiDraftValue] = useState(value as PickerMultiValue);
const [multiFinalValue, setMultiFinalValue] = useState(value as PickerMultiValue);

Expand All @@ -29,14 +29,8 @@ const usePickerSelection = (props: UsePickerSelectionProps) => {
[onChange]);

const toggleItemSelection = useCallback((item: PickerSingleValue) => {
let newValue;
const itemAsArray = [item];
if (!migrate) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't remove code from public without changing the major version - this should be part of the v8 effort

newValue = _.xorBy(multiDraftValue, itemAsArray, getItemValue || 'value');
} else {
newValue = _.xor(multiDraftValue, itemAsArray);
}

const newValue = _.xor(multiDraftValue, itemAsArray);
setMultiDraftValue(newValue);
},
[multiDraftValue, getItemValue]);
Expand Down
7 changes: 1 addition & 6 deletions src/components/picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ const Picker = React.forwardRef((props: PickerProps, ref) => {
children,
useSafeArea,
// TODO: Remove migrate props and migrate code
migrate = true,
accessibilityLabel,
accessibilityHint,
items: propItems,
Expand Down Expand Up @@ -117,7 +116,6 @@ const Picker = React.forwardRef((props: PickerProps, ref) => {
onSearchChange: _onSearchChange
} = usePickerSearch({showSearch, onSearchChange, getItemLabel, children});
const {multiDraftValue, onDoneSelecting, toggleItemSelection, cancelSelect} = usePickerSelection({
migrate,
value,
onChange,
pickerExpandableRef: pickerExpandable,
Expand All @@ -143,10 +141,8 @@ const Picker = React.forwardRef((props: PickerProps, ref) => {
}, []);

const contextValue = useMemo(() => {
// @ts-expect-error cleanup after removing migrate prop
const pickerValue = !migrate && typeof value === 'object' && !_.isArray(value) ? value?.value : value;
const pickerValue = value;
return {
migrate,
value: mode === PickerModes.MULTI ? multiDraftValue : pickerValue,
onPress: mode === PickerModes.MULTI ? toggleItemSelection : onDoneSelecting,
isMultiMode: mode === PickerModes.MULTI,
Expand All @@ -157,7 +153,6 @@ const Picker = React.forwardRef((props: PickerProps, ref) => {
selectionLimit
};
}, [
migrate,
mode,
value,
multiDraftValue,
Expand Down
8 changes: 2 additions & 6 deletions src/components/picker/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ export type PickerBaseProps = Omit<NewTextFieldProps, 'value' | 'onChange'> & {
* Use dialog instead of modal picker
*/
useDialog?: boolean;
/**
* Temporary prop required for migration to Picker's new API
*/
migrate?: boolean;
/**
* Pass for different field type UI (form, filter or settings)
*/
Expand Down Expand Up @@ -149,7 +145,7 @@ export type PickerBaseProps = Omit<NewTextFieldProps, 'value' | 'onChange'> & {
/**
* Render a custom header for Picker's dialog
*/
renderCustomDialogHeader?: (callbacks: {onDone?: () => void, onCancel?: ()=> void}) => React.ReactElement;
renderCustomDialogHeader?: (callbacks: {onDone?: () => void; onCancel?: () => void}) => React.ReactElement;
// /**
// * @deprecated pass useWheelPicker prop instead
// * Allow to use the native picker solution (different style for iOS and Android)
Expand Down Expand Up @@ -252,7 +248,7 @@ export interface PickerItemProps extends Pick<TouchableOpacityProps, 'customValu
}

export interface PickerContextProps
extends Pick<PickerProps, 'migrate' | 'value' | 'getItemValue' | 'getItemLabel' | 'renderItem' | 'selectionLimit'> {
extends Pick<PickerProps, 'value' | 'getItemValue' | 'getItemLabel' | 'renderItem' | 'selectionLimit'> {
onPress: (value: PickerSingleValue) => void;
isMultiMode: boolean;
onSelectedLayout: (event: any) => any;
Expand Down