List View: Render Row
Finally, let's define how our rows get rendered in our ListView.
We've already passed renderRow
into our ListView component above, and now we need to define it in Pokedex. We'll pass all the information we need to a MediaObject subcomponent that we'll create in a moment.
Note: You'll also need to define your goToPokemonDetail
action if you haven't already.
Now that we have the information we need, we'll render it out in our MediaObject component, which we can place at /src/components/MediaObject.js
. We'll use a couple of new pieces:
TouchableOpacity is a wrapper used for making views respond properly to touches. You can think of it as onClick, but with a visual feedback mechanism added in. Here, we'll use the onPress mechanism to react to touches and redirect the user to the desired pokemon details page.
Image is a core React Native component for loading local or remote images with one neat trick: It's non-blocking. That means we can feed our image into our layout without too much concern for UI stutters or hiccups.
Again, don't forget to do housekeeping like defining your styles and properly exporting your component as a module here. We've also used a bgColor function above that you can define:
That's it! Everything's in place. Just one more thing left to do.
Last updated