Can I interact with ListView Rows Directly?
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
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
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 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 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.