Skip to content
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

Generic type on renderListItem #382

Open
AntonnyAGS opened this issue Jul 26, 2021 · 10 comments · May be fixed by #738
Open

Generic type on renderListItem #382

AntonnyAGS opened this issue Jul 26, 2021 · 10 comments · May be fixed by #738

Comments

@AntonnyAGS
Copy link

Should it receive generic type.. so we can put more arguments on item list

@mikehardy
Copy link
Collaborator

Hi there!

Do you mean specifically this signature?

renderListItem?: (props: RenderListItemPropsInterface) => JSX.Element;

What would you propose, expressed as a valid signature to use in its place?

@AntonnyAGS
Copy link
Author

Hi there!

Do you mean specifically this signature?

renderListItem?: (props: RenderListItemPropsInterface) => JSX.Element;

What would you propose, expressed as a valid signature to use in its place?

yes, i wanted use it to customize list item with my own attributes

@mikehardy
Copy link
Collaborator

@AntonnyAGS

What would you propose, expressed as a valid signature to use in its place?

@peterchibunna
Copy link

I found out that in my use case, if I replace the renderListItem with the list item that makes the selector to fit in with my project, the onPress of the List Item does not fire thus making it impossible for the selection of items to propagate fully.

function getItemsArray() {
  return  [{label: 'Apple', value: 'apple'},
	  {label: 'Banana', value: 'banana'},
	  {label: 'Cranberry', value: 'cranberry'},
	  {label: 'Durian', value: 'durian'},
	  {label: 'Eggplant', value: 'eggplant'}]
}

const [open, setOpen] = useState(false);

const [value, setValue] = useState(null);
const [items, setItems] = useState(getItemsArray());
const [canSubmit, setCanSubmit] = useState(false);
const [cropsLoading, setCropsLoading] = useState(false);
...

<DropDownPicker
    open={open}
    value={value}
    items={items}
    setOpen={setOpen}
    setValue={setValue}
    setItems={setItems}
    loading={cropsLoading}
    ActivityIndicatorComponent={({color, size}) => <ActivityIndicator color={color} size={size} />}
    activityIndicatorColor={Colors.blue300}
    searchable={true}
    
    listMode={'MODAL'}
    placeholder={'Choose Food'}
    placeholderStyle={{color: Colors.grey600,fontSize: 16}}
    itemSeparator={true}
    itemSeparatorStyle={{
	    backgroundColor: Colors.grey200, //marginVertical: 5,
    }}
    modalProps={{
	    animationType: 'slide'
    }}
    renderListItem={(props) =><List.Item description={`Category: DEMO`} title={props.label} {...props} />}
/>

If I comment out the renderListItem line, the picker works fine.
PS. The <List.Item /> I'm using accepts onPress props.

@mikehardy
Copy link
Collaborator

@peterchibunna that's an interesting finding - but I'm not sure what it has to do with generic typing in the typescript definitions? 🤔

@ShyamKatti
Copy link

@mikehardy I have the same issue, providing a custom renderListItem makes the items in the list unselectable. Is there a suggestion on how to make it work?

@mikehardy
Copy link
Collaborator

@ShyamKatti that is the same unrelated problem to this actual issue. You saying "I have the same issue" makes me read the title of this issue, which is in reference to a typescript definition. But then your next statement has nothing to do with typescript definitions 🤔 so I'm confused.

Probably best to open a new issue with https://stackoverflow.com/help/minimal-reproducible-example but please note that even better than that is to do the work in node_modules with the javascript files to figure out the problem and post a PR. I don't use custom renderListItems so this is not a use case of mine, I won't have time fix it other than just in general collaborating with developers that propose reasonable PRs to help get them merged and released.

Future people: If you have a PR that fixes types, please discuss here. If you want to write something that is not about a generic type on renderListItems, then post elsewhere please so the issue is focused and actionable.

@ShyamKatti
Copy link

@mikehardy Sorry for the confusion, I meant the issue where the a list item cannot be selected on passing custom renderListItem.

@biancadragomir
Copy link

hi, is there a solution for this?

@VolkerLieber
Copy link

This happens because an invalid type definition in interface RenderListItemPropsInterface<T>.
onPress is defined as (value: T) => void, but is used as (item: ItemType<T>, custom?: boolean) => void in RenderListItem.js

I've submitted a PR with the correct definition. Until it's accepted, you can either just call the onPress function like this:

onPress={() => {
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore
    props.onPress(props.item, props.custom);
}}

or update the interface yourself if you only build locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants