react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Can I interact with ListView Rows Directly?

Open nosensezzz opened this issue 11 years ago • 3 comments

Hi, all

I am trying to achieve a function like, after listview rows rendered, when user click the row, I want another function fired, I tried to add onpress or onclick on component that rendered each row, but seems it is not fired at all.

I am not sure if the View component do not receive onpress props at all, or it just not reach because it is inside the row render function

anyway, is there a good practice or solution to do the job?

Thanks

nosensezzz avatar Aug 25 '15 11:08 nosensezzz

There's nothing special about a View component that is wrapped in a ListView. They undergo the same touch event bubbling, which you can capture with 'onTouchStart', which gives you the raw touch start event.

If you want to interact with these rows, the easiest way is to wrap them in one of the Touchable variants. These are sophisticated enough to handle things like cancelling a "press" if you touch inside a button, but releasing the touch outside the button.

hayeah avatar Aug 25 '15 12:08 hayeah

@hayeah Thanks for the tip, I think I just don't know the props "onTouchStart", so I fail to implement it, I tried onpress and onclick, nono of both worked, so...

this can be closed now.

BTW, do you have a documentation or example site to show me those props? I didn't read them from the react native site.

nosensezzz avatar Aug 25 '15 12:08 nosensezzz

@nosensezzz Touchable* are well documented. To really understand the event responder stuff you HAVE to look at the code, which has extensive discussion in the comments.

hayeah avatar Aug 26 '15 00:08 hayeah