fateh999 / react-native-paper-dropdown

Dropdown using react native paper TextInput and Menu
MIT License
130 stars 74 forks source link

TextInput.Icon: Support for defaultProps will be removed from function components in a future major release. #109

Closed vndpal closed 1 month ago

vndpal commented 1 month ago

Dropdown component is throwing an error as " ERROR Warning: TextInput.Icon: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead."

image

Sample usage:

 <View style={styles.formContainer}>
      <Dropdown
        label="Gender"
        placeholder="Select Gender"
        options={teams}
        value={selectedTeam}
        onSelect={setSelectedTeam}
        mode="outlined"
      />

library version: ^2.1.0 expo version: ^51.0.11

fateh999 commented 1 month ago

@vndpal actually it is due to a issue in react-native-paper library itself.

https://github.com/callstack/react-native-paper/issues/4428

vndpal commented 1 month ago

Thanks for the confirmation. I checked the issue in the react-native-paper library, it seems they have fixed this issue and will release it soon.

In the meantime, I did a workaround for react-native-paper-dropdown to continue working on my project. I copied the files from the src folder and manually added them to my project. Then in my local copy, I changed the problematic element <TextInput.Icon> to <Icon/>. Although it doesn't show the icons, dropdowns are working just fine.

function Dropdown(props: DropdownProps, ref: React.Ref<DropdownRef>) {
  const {
    options,
    mode,
    placeholder,
    label,
    menuUpIcon = <Icon source="camera" color={MD3Colors.error50} size={20} />, // changed this
    menuDownIcon = <Icon source="camera" color={MD3Colors.error50} size={20} />, // and this
    value,
    onSelect,
    maxMenuHeight,
    menuContentStyle,
    CustomDropdownItem = DropdownItem,
    CustomDropdownInput = DropdownInput,
    Touchable = TouchableRipple,
    disabled = false,
    error = false,
    testID,
    menuTestID,
  } = props;

I will again install react-native-paper-dropdown once the issue is fixed by react-native-paper.

Let me know if there is any better workaround. Thanks!

fateh999 commented 1 month ago

@vndpal i mean it is just a warning for now so you can either ignore that or if you don't want the icon you can replace it with Fragment also. Closing this as this issue has to be closed from react-native-paper.