Add a Clear All Complete Button to the Footer with React Native TouchableOpacity

Jason Brown
InstructorJason Brown
Share this video with your friends

Social Share Links

Send Tweet
Published 8 years ago
Updated 6 years ago

In this lesson we'll add a button to the footer that will clear all completed items. We'll use TouchableOpacity and we'll examine how flex space-around property works.

[00:00] We'll start by rendering a TouchableOpacity. Inside of there, we'll create a text element and say ClearCompleted. Now if we go over and we refresh, you can see that we have a ClearCompleted button rendering and there's space around all of the items. Now we'll go add an onPress to our TouchableOpacity and say this.props.onClearCompleted.

[00:23] Now, we'll switch back to our app and we'll add a handle ClearCompleted to be a function. Go ahead and bind this, this.handleClearCompleted = this.handleClearCompleted.bind(this). Now, we'll type const newItems = filterItems active, so we'll filter our items for only the active items, which will remove our completed items. We'll then say this.setSource and give it our new items, so we'll replace our array of items.

[01:04] We'll also filter items, this.state.filter and apply the filter to the new, the only active items. Now, we'll pass this into our footer. We'll say onClearCompleted = this.handleClearCompleted. When we go and we refresh our emulator, we can add an item, add another, you can toggle one of these to complete and click ClearCompleted and see that it disappeared.

egghead
egghead
~ 16 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today