📺 Develpreneur YouTube Episode

Video + transcript

React Native Fundamentals - Part 12 - Drawer Navigation Part 1

2021-11-02 •Youtube

Detailed Notes

In this video, we expand on React Navigation with Tab Navigation in React-Native. Specifically how to use Tabs to navigate around our screens instead of using the navigator.

Just in case you missed the last video you can find it here or you need a refresher you can find the first video Started Using React Native For Your Mobile Applications here.

Tab Navigation in React-Native focuses on: Required Dependencies Tabs IonIcons For a full list of components and APIs goto https://reactnative.dev/docs/accessibilityinfo

Tab Navigation

Possibly the most common style of navigation in mobile apps is tab-base navigation. Where the application displays tabs on the bottom of the screen or on the top below the header (or even instead of a header) for navigating between screens. Before we begin we need to install some additional dependencies for npm and expo.

Installation and setup

First, you need to install them in your project:

npm install @react-navigation/native React Tab Navigation is made up of some core utilities we use to create the navigation structures in our apps. These utilities include with @react-navigation/native are:

@react-navigation/bottom-tabs @react-navigation/stack @expo/vector-icons/Ionicons react-native-vector-icons/Ionicons Using the Stack Navigator With Tabs

Usually tabs don't just display one screen; For example, on your Facebook feed, you can tap on a post and it brings you to a new screen within that tab with all of the comments. Another way to think about would be to think of this as being a separate navigation stacks within each tab, and that's exactly how we will model it in React Navigation.

Customizing Tabs

This is similar to how you would customize a stack navigator. While there are some properties that get set when you initialize the tab navigator and others you customize per-screen in the options. One such option is using Ionicons.

Ionicons

Premium designed icons for use in web, iOS, Android, and desktop apps. Support for SVG and web font. Completely open source, MIT licensed and built by the Ionic Framework team.

Additional Resources React - https://reactjs.org/ Node - https://nodejs.org/en/ Visual Studio Code - https://code.visualstudio.com/ Android Development - https://developer.android.com/studio Xcode - https://apps.apple.com/us/app/xcode/id497799835?mt=12

Transcript Text
[Music]
today we're going to continue our
discussion on react native
and we're going to wrap up our
navigation discussion by talking about
the next piece in the react native
navigation which is the menuing or the
drawer navigation
so previously we have talked about the
different kind of dependencies you need
for react native we've talked about
uh react navigation we've talked about
tab navigation we've talked about things
like stack navigation
so
we basically continue on talking about
the react native library here
and of course every time we want to use
navigation we have to use the base stack
or the base library which is native
the optional dependencies you typically
need for any type of navigation will be
things like reanimated gesture handlers
we definitely need screens if we're
going to be adding screens safe area
content and mass views now some of these
are
ios or android specific but they are
nice to have when you're trying to make
your application feel more mobile
friendly on the device that you're
working on
the basic navigation we talked about is
the navigation container
we talked about using buttons to use the
navigation
property to jump between
screens we talked about using stacks
where we could actually stack
navigations where we could add different
screens together in kind of like a
container and then as we click through
the container and go from screen to
screen we kind of have that back button
that appears at the top of our
navigation
and then last time we talked about tab
navigation which is probably the most
common form of navigation on mobile
devices this is where we have those
little tabs or little menu buttons at
the top and bottom of the
application to where we can just jump
quickly between different uh navigation
stats or stack sets
and that's whoops and that looks almost
identical to the react native the stack
navigation
and today it's almost going to be not
much different when we deal with the
drawer navigation so
essentially just depending upon the type
of navigation you want is just going to
be the different library that you use so
for stacking we use stack for tab we use
tab and today you'll see that we use
drawer for
adding that menu
so as i mentioned before we're going to
be talking about the drawer navigation
of react native and it's essentially the
component that renders the navigation
drawer which can be opened and closed
via gestures
or simply looks like this you have a
little menu button or you can swipe from
the left to the right and then you can
see the menu options or the drawer
so you have your home button your
settings the different screens that you
can jump to within your application that
you want to select from your menu
now door navigation can be thought of as
like a wardrobe or a dresser of drawers
what you do is you open up the door when
you want to get something out you find
your item you pull it out on this case
you click your screen or you click your
the screen you want to go to and then
you close the door so when you open the
drawer you have the option to select one
of the items in the door in this case
one of the screens once you select it
the drawer automatically closes
if you
made a mistake by clicking the menu and
you don't want anything in the drawer
all you have to do is click in this
little gray area here and the drawer
closes
the requirements we need for today to
talk about react native drawer is we
still need the react native native
library and we also need the react
navigation door library
the additional imports we're going to
need is we're still going to need that
navigation container but we're also
going to now need the create for
navigator
and that's going to come from the react
navigation drawer library
does anyone have any questions about
react native and the react
native drawer navigator that we're going
to be looking at today
not at this time
yeah
everyone's clear we will jump out into
the demo like the previous ones this is
going to be more hands-on we're going to
get our hands dirty and kind of build on
what we've been learning
one other thing i would like to mention
though
about react
so we talked about react native uh
before with the stack navigation so the
stack navigator
how it works is it works by pushing and
popping the screens
into
the main window here so when you
actually push on the stack it moves the
screen over to another screen
now that's nice however with drawer when
you select one of the screens here
you're replacing the screen that is in
the main window you're not actually
adding or removing from the stack it's a
replacement
so it's just one distinction i wanted to
point out here
it's off
all right so let's go to terminal
what happens when you have multiple
strings
all right everyone clearly see this
that big enough
yep
cool thank you
all right so i'm going to navigate to my
development folder
and inside my development folder i have
a reactive workspace
all right and just to show you what
we're going to be building today
let me start an existing project i've
already built
and we still use expo
so when expo starts we start it within
our
application directory
and then we can open up an ios simulator
or an android simulator
and once we do expo start it will load
the
application into our emulator
take just a second to load
i didn't mean to close this before class
but i accidentally did
loading all the updates
this is one thing you will run into
every now and then when dealing with
expo or react native they're constantly
updating the libraries so you will have
to constantly keep updating your
emulators as well
so today we are going to build this
application here we're going to have a
home screen we are going to have a
notification screen
and then we are also going to have a
settings screen so we're going to start
by building three screens
then we're going to add some navigation
to those screens
where we can click a button and go to
the different screen
and then we're going to add a slide deck
here the drawer for the main menu with
some
options to go to our different screen
and then finally we're going to add the
little menu button here so that we can
very quickly just click the button to
bring up our door
otherwise we'd have to mainly swipe left
and right
minimize this
all right we'll stop the existing one
let's create a new
project here
all right so we're going to do expo
init
and we will call this one
example
no space
app
we're going to create a blank
project
this will just build our basic template
for us to
work with react native
take just a second to install the
dependencies
well this installs
let me go briefly over what we're going
to do in this first example
so in our first example here we're going
to create a basic drawer based
navigation so we're going to create that
mobile app
here
with three screens we're going to have
home
navigation and settings
and we're going to add all three of
those screens to the dashboard
our application finished
so we're going to go into our
application like it says here cd our
example drawer
app
now the first thing we need to do in
here though
is we have to actually install 3x
navigation libraries so that we can use
them
with our
application
so we need to first install
minimize this chest
minimize that
you minimize the text
all right we'll just leave it as is
all right so the first thing we're going
to do is we're going to install the
react navigation
navigate library
and you have to do this for each of your
projects you can't do this globally and
you really don't want to do this
globally because if we actually install
these dependencies at a global level of
your machine then that means when you go
to build your application and push them
out to the stores you might actually be
installing a whole bunch of libraries
and packages that you don't need
essentially bloating your app
so next we want to install
the navigation stack
because we'll need that for
the third example today
we will also need
to install the drawer
and i will go ahead and also install all
the
optional dependencies that we need like
react native reanimated gestures
screens context and the community mask
view
i find more often than not i end up
needing something from one of these
libraries so i just include it with my
build
all right so that
gave us
our react native
our
stack our drawer
our
optional dependencies
so now we have everything installed
so let's go look at the code
i'm using visual studio so we'll just
type code
walmart console and this will open up
visual studios code
all right that's open
and while
i have visual studios open let me
actually start the app so we can see our
changes real time
all right and i
reload
there we go
sometimes when you have the emulator up
when you start a new app you have to
deploy it to
the ios or to the device and then you
have to force a reload in order to
reload your application
the emulator is nice but it can be a
little buggy
you
Transcript Segments
0.42

[Music]

27.119

today we're going to continue our

28.64

discussion on react native

30.4

and we're going to wrap up our

32.079

navigation discussion by talking about

35.84

the next piece in the react native

39.04

navigation which is the menuing or the

41.12

drawer navigation

46.16

so previously we have talked about the

48.079

different kind of dependencies you need

49.76

for react native we've talked about

52.48

uh react navigation we've talked about

55.28

tab navigation we've talked about things

57.28

like stack navigation

59.12

so

60.64

we basically continue on talking about

63.28

the react native library here

65.84

and of course every time we want to use

68.96

navigation we have to use the base stack

71.439

or the base library which is native

74.4

the optional dependencies you typically

76.479

need for any type of navigation will be

79.28

things like reanimated gesture handlers

82.56

we definitely need screens if we're

84.08

going to be adding screens safe area

86.72

content and mass views now some of these

89.84

are

90.799

ios or android specific but they are

93.28

nice to have when you're trying to make

95.119

your application feel more mobile

97.84

friendly on the device that you're

99.2

working on

101.84

the basic navigation we talked about is

103.92

the navigation container

105.759

we talked about using buttons to use the

108.079

navigation

109.92

property to jump between

112.24

screens we talked about using stacks

114.799

where we could actually stack

116.479

navigations where we could add different

118.799

screens together in kind of like a

120.24

container and then as we click through

122.24

the container and go from screen to

124.24

screen we kind of have that back button

126.32

that appears at the top of our

127.6

navigation

129.039

and then last time we talked about tab

130.72

navigation which is probably the most

133.76

common form of navigation on mobile

135.84

devices this is where we have those

137.52

little tabs or little menu buttons at

140.64

the top and bottom of the

142.56

application to where we can just jump

144.48

quickly between different uh navigation

147.12

stats or stack sets

149.28

and that's whoops and that looks almost

151.599

identical to the react native the stack

154.48

navigation

155.76

and today it's almost going to be not

157.76

much different when we deal with the

159.2

drawer navigation so

161.2

essentially just depending upon the type

162.959

of navigation you want is just going to

164.959

be the different library that you use so

168

for stacking we use stack for tab we use

170.879

tab and today you'll see that we use

172.959

drawer for

174.72

adding that menu

178.48

so as i mentioned before we're going to

180

be talking about the drawer navigation

182.08

of react native and it's essentially the

184.72

component that renders the navigation

187.599

drawer which can be opened and closed

189.36

via gestures

194.4

or simply looks like this you have a

196.72

little menu button or you can swipe from

199.28

the left to the right and then you can

201.04

see the menu options or the drawer

204.319

so you have your home button your

206.239

settings the different screens that you

208.799

can jump to within your application that

211.12

you want to select from your menu

214.08

now door navigation can be thought of as

216.64

like a wardrobe or a dresser of drawers

221.12

what you do is you open up the door when

222.879

you want to get something out you find

224.64

your item you pull it out on this case

227.12

you click your screen or you click your

229.44

the screen you want to go to and then

231.2

you close the door so when you open the

233.68

drawer you have the option to select one

236.319

of the items in the door in this case

238.4

one of the screens once you select it

240.64

the drawer automatically closes

242.879

if you

243.84

made a mistake by clicking the menu and

245.68

you don't want anything in the drawer

247.36

all you have to do is click in this

248.799

little gray area here and the drawer

250.959

closes

256.4

the requirements we need for today to

258.479

talk about react native drawer is we

261.519

still need the react native native

263.28

library and we also need the react

265.759

navigation door library

268.479

the additional imports we're going to

269.919

need is we're still going to need that

272

navigation container but we're also

274.32

going to now need the create for

276.16

navigator

277.6

and that's going to come from the react

279.36

navigation drawer library

283.04

does anyone have any questions about

285.36

react native and the react

288.8

native drawer navigator that we're going

290.72

to be looking at today

296.32

not at this time

298

yeah

298.88

everyone's clear we will jump out into

301.199

the demo like the previous ones this is

303.759

going to be more hands-on we're going to

305.759

get our hands dirty and kind of build on

307.919

what we've been learning

317.759

one other thing i would like to mention

319.44

though

320.32

about react

324.16

so we talked about react native uh

326.72

before with the stack navigation so the

329.36

stack navigator

331.12

how it works is it works by pushing and

333.52

popping the screens

335.759

into

336.8

the main window here so when you

338.24

actually push on the stack it moves the

341.12

screen over to another screen

343.199

now that's nice however with drawer when

346.16

you select one of the screens here

348.88

you're replacing the screen that is in

351.84

the main window you're not actually

353.52

adding or removing from the stack it's a

355.52

replacement

356.8

so it's just one distinction i wanted to

358.72

point out here

363.199

it's off

367.12

all right so let's go to terminal

380.24

what happens when you have multiple

381.44

strings

391.68

all right everyone clearly see this

395.759

that big enough

397.28

yep

398.319

cool thank you

400

all right so i'm going to navigate to my

401.36

development folder

410.479

and inside my development folder i have

412.16

a reactive workspace

418.8

all right and just to show you what

420.639

we're going to be building today

422.4

let me start an existing project i've

424.319

already built

431.44

and we still use expo

440.96

so when expo starts we start it within

443.919

our

445.12

application directory

446.88

and then we can open up an ios simulator

450.479

or an android simulator

456.479

and once we do expo start it will load

458.479

the

459.68

application into our emulator

467.36

take just a second to load

469.36

i didn't mean to close this before class

471.12

but i accidentally did

475.759

loading all the updates

480.56

this is one thing you will run into

482.8

every now and then when dealing with

484.479

expo or react native they're constantly

487.28

updating the libraries so you will have

489.759

to constantly keep updating your

491.759

emulators as well

493.759

so today we are going to build this

495.44

application here we're going to have a

497.759

home screen we are going to have a

500.08

notification screen

501.919

and then we are also going to have a

504.56

settings screen so we're going to start

506.56

by building three screens

508.72

then we're going to add some navigation

510.56

to those screens

511.919

where we can click a button and go to

513.839

the different screen

516.719

and then we're going to add a slide deck

518.64

here the drawer for the main menu with

521.519

some

522.399

options to go to our different screen

525.36

and then finally we're going to add the

526.88

little menu button here so that we can

529.2

very quickly just click the button to

531.36

bring up our door

532.8

otherwise we'd have to mainly swipe left

535.12

and right

540.08

minimize this

545.36

all right we'll stop the existing one

553.279

let's create a new

555.04

project here

556.48

all right so we're going to do expo

560.24

init

561.44

and we will call this one

563.68

example

567.76

no space

571.04

app

575.2

we're going to create a blank

577.36

project

578.72

this will just build our basic template

580.959

for us to

582.72

work with react native

585.04

take just a second to install the

586.48

dependencies

589.279

well this installs

591.44

let me go briefly over what we're going

593.6

to do in this first example

595.6

so in our first example here we're going

597.68

to create a basic drawer based

599.44

navigation so we're going to create that

602.16

mobile app

604.959

here

606.16

with three screens we're going to have

608.399

home

609.36

navigation and settings

611.44

and we're going to add all three of

613.519

those screens to the dashboard

618.16

our application finished

621.2

so we're going to go into our

623.2

application like it says here cd our

625.839

example drawer

627.279

app

636.88

now the first thing we need to do in

638.72

here though

641.12

is we have to actually install 3x

643.44

navigation libraries so that we can use

645.76

them

646.56

with our

648

application

649.12

so we need to first install

652.8

minimize this chest

664.32

minimize that

666.72

you minimize the text

670.16

all right we'll just leave it as is

676.32

all right so the first thing we're going

677.839

to do is we're going to install the

679.68

react navigation

681.839

navigate library

685.92

and you have to do this for each of your

688.399

projects you can't do this globally and

690.88

you really don't want to do this

692.24

globally because if we actually install

694.24

these dependencies at a global level of

696.399

your machine then that means when you go

699.36

to build your application and push them

701.519

out to the stores you might actually be

703.68

installing a whole bunch of libraries

705.2

and packages that you don't need

707.04

essentially bloating your app

709.92

so next we want to install

712.16

the navigation stack

714.399

because we'll need that for

716.399

the third example today

721.68

we will also need

723.76

to install the drawer

727.12

and i will go ahead and also install all

730.32

the

732.32

optional dependencies that we need like

734.72

react native reanimated gestures

737.76

screens context and the community mask

740.48

view

744.959

i find more often than not i end up

746.88

needing something from one of these

748.24

libraries so i just include it with my

750.639

build

751.76

all right so that

752.959

gave us

754.48

our react native

756.079

our

756.839

stack our drawer

759.839

our

761.04

optional dependencies

762.88

so now we have everything installed

765.2

so let's go look at the code

767.76

i'm using visual studio so we'll just

769.68

type code

772.32

walmart console and this will open up

774.48

visual studios code

780

all right that's open

782.16

and while

783.92

i have visual studios open let me

786

actually start the app so we can see our

788.48

changes real time

794.079

all right and i

814.56

reload

816.72

there we go

820

sometimes when you have the emulator up

822.24

when you start a new app you have to

825.36

deploy it to

826.8

the ios or to the device and then you

829.12

have to force a reload in order to

831.04

reload your application

833.519

the emulator is nice but it can be a

835.199

little buggy

851.68

you