Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


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

    react-nativeReact Native
    0.35 - 0.37

    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.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    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.

    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.

    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.