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 Modal Screen that Pops Up from the Bottom with React Navigation

    react-nativeReact Native

    We’ll use React Navigation to add a modal screen to our app, which will pop up from the bottom, and cover the entire screen.



    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




    Instructor: Import TouchableOpacity into restaurant-info.js. Add a button that can add a review for the restaurant. We'll use the same styles that we used on the restaurant row for the button.

    When we reload, we have an add review button. We want it to pop up a screen so that we can add a review. In app.js, we want to make a new modal screen, but we can't make it in the restaurant stack navigator because that stack navigator is within the tab navigator.

    We want the modal to pop over everything, including the tabs. We actually have to make a new base stack navigator. We'll set our tab navigator to a const and make and export a new stack navigator.

    The first screen of that navigator will be the tabs. We'll specify this as a modal stack navigator by setting the mode to modal. We'll also set the header mode to none so that we don't get a header on the top of our tabs.

    Then, we can make a new component that we'll use for the modal screen, called add-review.js. We can import that into app.js and set it as a screen in our new modal stack navigator.

    Now, on the add review button in restaurant info, we can add an onPress action and make that function, which will navigate like normal to the new add review screen. The restaurant info screen isn't in the same stack navigator as the add review screen, but React navigation will walk up the navigation stack to look for it. It can still navigate there.

    When we reload, we can go to the info and press the button to add a review. On iOS, we can drag down from the top to dismiss the modal, but let's also add an X button that we can use to close the modal.

    First, if we want to, we can turn off that drag-down-to-close gesture in app.js by adding navigation options to the modal stack navigator options and setting gestures enabled to false.

    Then, in the add review component, we can import icon and add a close button and some styling. Then we can specify an onPress for the close button. To actually close the modal, we can call the goBack function on the navigation prop. When we reload, we can open the modal and close it with the close button.