📺 Develpreneur YouTube Episode

Video + transcript

React Native - Put It All Together Part 1

2021-12-07 •Youtube

Detailed Notes

In this final segment on React Native: Putting it all together, we revisit all the concepts we have covered to this point. Then we go through how to set up and organize your projects so you can break down your code into smaller more manageable components.

Prior to watching this video please see the previous video on React Navigation here or if you need a refresher check out the first video in the series "Started Using React Native For Your Mobile Applications" here.

React Native: Putting It All Together focuses on: Required Dependencies Text SafeAreaView Image Background Image ScrollView TouchableOpacity Button View NavigationContainer Navigator createStackNavigator Tab navigation Const createBottomTabNavigator Drawer navigation Screen createDrawerNavigator Tab navigation Ionicons {useState} For a full list of components and APIs go to https://reactnative.dev/docs/accessibilityinfo

Additional Resources

React is an open-source, front-end, JavaScript library for building user interfaces or UI components. In addition, Facebook and a community of individual developers and companies help maintain it. Additionally, React can be useful as a base in the development of single-page or mobile applications. Node.js is an open-source, cross-platform, back-end JavaScript runtime environment that runs on the Chrome V8 engine and executes JavaScript code outside a web browser. Visual Studio Code is a free source-code editor made by Microsoft for Windows, Linux, and macOS. In addition, it includes support for debugging, syntax highlighting, intelligent code completion, snippets, code refactoring, and embedded Git. Android software development is the process by which applications are created for devices running the Android operating system. Xcode is Apple's integrated development environment for macOS and is used to develop software for macOS, iOS, iPadOS, watchOS, and tvOS. Finally, this series comes from our mentoring/mastermind classes.  These classes are virtual meetings that focus on how to improve our technical skills and build our businesses.  After all the goals of each member vary.  However, this diversity makes for great discussions and a ton of educational value every time we meet.  We hope you enjoy viewing this series as much as we enjoy creating it.  As always, this may not be all new to you, but we hope it helps you be a better developer.

Transcript Text
[Music]
today is the final lesson in our
discussion on react native where we're
going to kind of put it all together
review all the components we've
currently worked with installed and set
up for
building our react native apps
and we're going to essentially
deconstruct
some of the applications we've built and
actually
organize them more effectively into a
different type of organization structure
so that we can reuse components
throughout our application instead of
having to constantly copy and paste
components
so last time we
talked about container navigations we
talked about using drawers to kind of
stack our applications our different
screens
and where we could actually nest some
different types of navigation like stack
navigation with drawer navigation
and just create components for our
different screens here
so we started down this path to where we
could actually create green objects or
functions and pass these around through
the applications we can then pass them
into our stack we can then take this
stack
and we can add it to the drawer
and the result was this application over
here where we
load the application we get a home page
we click home we go to notifications we
can go back and forth that way
we can go to menu so this is the drawer
this is kind of that menu that was
hiding behind the scenes we can click
settings and from settings we can go to
home
we can go back to menu we can go to home
and so on so we kind of combined all of
the navigation components into one app
so today i want to take this structure
take our app here and i want to break it
down into its components
so i picked this one because we had
already started this last time we had
already started organizing our app based
on screens and
based upon navigation menus
so to start with one of the things you
can do is over here in your project you
can create a couple different folders
for different things so since we're
doing expo we don't have a source folder
so everything can go into the root so we
can create a new folder
and we'll call this one navigation
we already have an assets folder and
this
assets folder contains all of our images
or different icons that we want to
display in our application
so we now have navigation which will
move all of our stacks
our drawer navigation here
[Music]
and our navigators into navigation
we also can create another folder for
our screens
folder
that's all these screens
or just
screen and we'll do screens
then we could also do one for components
so like say if we want to create custom
views or custom text or custom buttons
we can create a components folder
if we had different translations
different languages different text we
could also create what's called i 18n or
language
i'm not going to create this one because
the latest update to react native we'll
build that for you based upon your
particular operating system
it was something new that they added
if we had javascript we could do it like
an actions folder we want to do styles
we could do a custom styles folder we
want to do specific theme based so under
styles we could have a separate theme or
under styles have a theme folder and
underneath that folder you could have
like fonts colors matrix
if we were doing any api connections
where we were calling like third-party
apis into our app we could create an api
folder or even a hook folder and if you
had a shopping cart you would have like
a shop folder as well since we haven't
covered any of those topics yet i'm
going to stick to the ones that were
primarily have seen so far so we've got
our navigation we've got our styles and
we've got our screens we already had
assets and i added components we may or
may not get to that today
so let's start from the top
so here we have our home screen
now the whole purpose of organizing your
project is so that one file does not
have
the entire application we don't have
everything in one place
we want to actually break things down so
we're actually working on specific
features within our application so if we
only want to touch the home screen we
really only want the home screen code we
don't want any of this other code
so we can take the home screen here take
this section here
go under screens
and create a new file and we'll call
this one
on screen
dot js so everything needs to be js
we will paste our code in here
and we need to change this from a
function so since this is an actual now
a javascript object we need to pass it
as an object so we need to make a
constant
home screen
equals
any
parameters we need to pass and go here
and then we need to use
the notation equal greater than
and then we build
our function or the constant
in order to reuse this we need to export
people
on screen
so by default they'll take this home
screen and export it
now this won't work
because we haven't actually imported the
components we need for it yet so let's
come back over here
so we don't need status bar that only
needs to be in the main app uh react
let's see it actually highlights what we
need so we need button view text and
react we don't have styles in here so
we'll get rid of styles
and we don't have any navigation so we
can actually get rid of all these
imports
now just by looking at this we see that
our home screen
contains a view
and inside of that view we have a text
and a button
so our text tag displays our text and we
can add style to that button same thing
we can add styles but to actually
activate the button we have to add an on
press function
and we are going to pass the navigation
tab around because we're going to be
using that navigation stack
all right and we set the title for our
button so this is the text of our button
and so if i save that we now have home
screen
now if i want to use home screen on the
main app
first we will get rid of the old
function
and now we need to import our new screen
so we have home screen from
root
because app lives in the root
and then we need to
go to our screens folder
and then we need to pull home screen
so now i can reference home screen
within the application
so if i re save this it refreshes
and home still works
so we've created our home screen
over here
so now let's pull out the notification
screen so we'll do notification real
quick
file
notifications
spring
dot js
this section here
under notifications paste
and we'll start with the imports from
home screen
change our function to a constant
format
function to a constant
and we need to make sure that we export
our new constant
okay we have view text button view text
button react all looks good
so we'll save that
back to our app
click that
paste
notifications
screen
okay
and because i'm naming them the exact
same as their functions
i do not need to update any of the code
down here it just fits
all right so we have one more screen we
have settings screen so we'll copy the
function name
new file
dot js
so we have our settings
again copy it over
take our imports
enter function to a constant
um
settings screen
back to our app
click that
settings
screen
screen
save the app still works
still happy
all right so now we've got our screens
we're importing them
well we really don't need them here
because we
want to create some navigation stacks
so we have this home stack
and we'll go under navigation
and we'll create a new file here so do
new
home homestack.js
here copy
now this one because we need stack we
need that first part so we'll copy the
stack
stack
some of these
all right so now we got home stack
turn this guy into a constant
obviously just modifying the function
again export
all
stack
because we want to return this guy when
we're calling this javascript
it needs some imports
so what's cool about using visual code
with all the plugins we've talked about
it actually shows you what you need to
include and what you don't need to
include
so in
home stack we don't need the status bar
we don't need stylesheet
we don't need view or text because
they're not being used
don't need to create drawer navigation
or the navigate container
or settings
so now when we load this screen we're
only loading the components that we need
okay so there's home stack
so now i can import home stack
so if i delete this section here
so if i save it
we're going to fail because currently it
cannot find home stack
so now if i go here and i do import
stack it will automatically
insert the location
and we now see we don't need home screen
or notification anymore because those
are in home stack
so we can drop those we can also drop
style sheet
and we can also drop view and text
now we could technically also drop the
status bar but we kind of need that guy
for the expo for debugging
all right let's
pull that in oh we have another error
here
none of these files exist so in our
navigation screen home screen it now
cannot find the path to home screen
so home stack
we have to change our path here to
actually go up a level not from root
because we're down a folder
when we were in app we could use dot
which would say start at the root
and go find the folder
however here we're
under a folder off of the root under
navigation so we need to use dot dot to
go back up a level in order to find the
folder that we're looking for so all you
have to do is just change it to dot dot
so it's nice about this as we walk the
stack as we start cleaning things up the
expo debugger is pretty clean about
telling us what we forgot to do or what
else we need to do
you
Transcript Segments
1.3

[Music]

26.96

today is the final lesson in our

29.679

discussion on react native where we're

32.239

going to kind of put it all together

34.48

review all the components we've

36.8

currently worked with installed and set

38.96

up for

40.239

building our react native apps

42.8

and we're going to essentially

45.039

deconstruct

46.559

some of the applications we've built and

48.48

actually

49.36

organize them more effectively into a

52.8

different type of organization structure

54.96

so that we can reuse components

56.719

throughout our application instead of

58.32

having to constantly copy and paste

60.239

components

62.64

so last time we

64.96

talked about container navigations we

67.52

talked about using drawers to kind of

70.4

stack our applications our different

72.479

screens

73.76

and where we could actually nest some

75.28

different types of navigation like stack

77.2

navigation with drawer navigation

79.68

and just create components for our

82.159

different screens here

83.92

so we started down this path to where we

86.56

could actually create green objects or

88.72

functions and pass these around through

90.88

the applications we can then pass them

92.56

into our stack we can then take this

94.799

stack

96.159

and we can add it to the drawer

98.4

and the result was this application over

100.24

here where we

101.68

load the application we get a home page

104.479

we click home we go to notifications we

107.28

can go back and forth that way

109.439

we can go to menu so this is the drawer

111.6

this is kind of that menu that was

113.28

hiding behind the scenes we can click

115.439

settings and from settings we can go to

117.84

home

119.04

we can go back to menu we can go to home

122.32

and so on so we kind of combined all of

125.68

the navigation components into one app

129.039

so today i want to take this structure

132.959

take our app here and i want to break it

134.8

down into its components

136.64

so i picked this one because we had

138.879

already started this last time we had

140.64

already started organizing our app based

143.68

on screens and

146

based upon navigation menus

148.64

so to start with one of the things you

151.04

can do is over here in your project you

154.239

can create a couple different folders

156

for different things so since we're

157.76

doing expo we don't have a source folder

159.76

so everything can go into the root so we

162.08

can create a new folder

163.84

and we'll call this one navigation

167.68

we already have an assets folder and

169.68

this

170.48

assets folder contains all of our images

172.64

or different icons that we want to

174.319

display in our application

176.319

so we now have navigation which will

178.239

move all of our stacks

180.4

our drawer navigation here

181.95

[Music]

183.36

and our navigators into navigation

186.959

we also can create another folder for

189.68

our screens

191.519

folder

193.84

that's all these screens

195.599

or just

196.84

screen and we'll do screens

200.319

then we could also do one for components

202.319

so like say if we want to create custom

204.72

views or custom text or custom buttons

208.08

we can create a components folder

210.72

if we had different translations

213.28

different languages different text we

215.68

could also create what's called i 18n or

219.599

language

220.56

i'm not going to create this one because

222.56

the latest update to react native we'll

226.159

build that for you based upon your

228.239

particular operating system

230.56

it was something new that they added

232.799

if we had javascript we could do it like

234.64

an actions folder we want to do styles

237.599

we could do a custom styles folder we

240.4

want to do specific theme based so under

243.36

styles we could have a separate theme or

245.439

under styles have a theme folder and

247.599

underneath that folder you could have

248.879

like fonts colors matrix

251.36

if we were doing any api connections

254.4

where we were calling like third-party

255.92

apis into our app we could create an api

258.72

folder or even a hook folder and if you

261.6

had a shopping cart you would have like

263.52

a shop folder as well since we haven't

265.84

covered any of those topics yet i'm

267.84

going to stick to the ones that were

269.199

primarily have seen so far so we've got

271.919

our navigation we've got our styles and

274.24

we've got our screens we already had

276.56

assets and i added components we may or

279.199

may not get to that today

281.12

so let's start from the top

283.36

so here we have our home screen

286.639

now the whole purpose of organizing your

289.36

project is so that one file does not

292.08

have

292.96

the entire application we don't have

294.8

everything in one place

296.479

we want to actually break things down so

298.56

we're actually working on specific

300.56

features within our application so if we

303.039

only want to touch the home screen we

305.039

really only want the home screen code we

307.52

don't want any of this other code

309.759

so we can take the home screen here take

312.16

this section here

313.6

go under screens

315.759

and create a new file and we'll call

318.24

this one

319.28

on screen

321.36

dot js so everything needs to be js

324.72

we will paste our code in here

327.36

and we need to change this from a

329.039

function so since this is an actual now

331.52

a javascript object we need to pass it

334.08

as an object so we need to make a

335.6

constant

337.12

home screen

339.44

equals

342.72

any

343.68

parameters we need to pass and go here

346.24

and then we need to use

348.16

the notation equal greater than

351.36

and then we build

352.96

our function or the constant

355.759

in order to reuse this we need to export

359.84

people

361.68

on screen

363.6

so by default they'll take this home

365.12

screen and export it

367.28

now this won't work

369.28

because we haven't actually imported the

371.28

components we need for it yet so let's

373.199

come back over here

376.4

so we don't need status bar that only

378.72

needs to be in the main app uh react

382.4

let's see it actually highlights what we

384.4

need so we need button view text and

386.4

react we don't have styles in here so

388.319

we'll get rid of styles

390.88

and we don't have any navigation so we

392.88

can actually get rid of all these

394.96

imports

397.6

now just by looking at this we see that

400.24

our home screen

402

contains a view

403.68

and inside of that view we have a text

407.199

and a button

409.199

so our text tag displays our text and we

411.84

can add style to that button same thing

414.639

we can add styles but to actually

416.96

activate the button we have to add an on

419.12

press function

421.12

and we are going to pass the navigation

423.12

tab around because we're going to be

424.479

using that navigation stack

427.039

all right and we set the title for our

429.68

button so this is the text of our button

433.52

and so if i save that we now have home

435.52

screen

437.84

now if i want to use home screen on the

440.08

main app

441.759

first we will get rid of the old

443.36

function

444.88

and now we need to import our new screen

447.759

so we have home screen from

452.8

root

453.68

because app lives in the root

456.08

and then we need to

457.52

go to our screens folder

459.919

and then we need to pull home screen

463.039

so now i can reference home screen

465.759

within the application

468.24

so if i re save this it refreshes

471.52

and home still works

475.36

so we've created our home screen

478.96

over here

480.16

so now let's pull out the notification

482.24

screen so we'll do notification real

484.16

quick

486.16

file

487.759

notifications

489.68

spring

491.28

dot js

495.919

this section here

497.52

under notifications paste

500.4

and we'll start with the imports from

503.68

home screen

508.4

change our function to a constant

514.719

format

515.76

function to a constant

518.32

and we need to make sure that we export

524.48

our new constant

529.76

okay we have view text button view text

532.8

button react all looks good

535.68

so we'll save that

537.12

back to our app

538.8

click that

541.519

paste

546.399

notifications

549.68

screen

559.36

okay

561.68

and because i'm naming them the exact

563.76

same as their functions

565.839

i do not need to update any of the code

568.16

down here it just fits

571.76

all right so we have one more screen we

573.839

have settings screen so we'll copy the

576.32

function name

579.6

new file

582.24

dot js

583.68

so we have our settings

590.399

again copy it over

593.12

take our imports

599.44

enter function to a constant

611.12

um

621.12

settings screen

625.839

back to our app

627.44

click that

633.839

settings

636

screen

643.6

screen

645.76

save the app still works

648.399

still happy

653.6

all right so now we've got our screens

656.16

we're importing them

657.839

well we really don't need them here

660.24

because we

661.6

want to create some navigation stacks

664.24

so we have this home stack

666.959

and we'll go under navigation

669.12

and we'll create a new file here so do

671.6

new

672.88

home homestack.js

678.88

here copy

680.88

now this one because we need stack we

683.2

need that first part so we'll copy the

685.12

stack

687.6

stack

688.959

some of these

691.839

all right so now we got home stack

693.839

turn this guy into a constant

700.079

obviously just modifying the function

704.88

again export

707.6

all

710.639

stack

711.839

because we want to return this guy when

713.519

we're calling this javascript

716.88

it needs some imports

724

so what's cool about using visual code

726.079

with all the plugins we've talked about

728.079

it actually shows you what you need to

730.24

include and what you don't need to

731.6

include

732.56

so in

734.079

home stack we don't need the status bar

736.639

we don't need stylesheet

743.12

we don't need view or text because

745.44

they're not being used

750.079

don't need to create drawer navigation

752.48

or the navigate container

755.279

or settings

756.8

so now when we load this screen we're

758.88

only loading the components that we need

763.12

okay so there's home stack

765.839

so now i can import home stack

769.6

so if i delete this section here

774.72

so if i save it

776.399

we're going to fail because currently it

778.399

cannot find home stack

780.56

so now if i go here and i do import

786.24

stack it will automatically

788.959

insert the location

790.959

and we now see we don't need home screen

793.2

or notification anymore because those

795.36

are in home stack

797.44

so we can drop those we can also drop

799.839

style sheet

801.839

and we can also drop view and text

805.279

now we could technically also drop the

807.2

status bar but we kind of need that guy

809.36

for the expo for debugging

813.04

all right let's

814.32

pull that in oh we have another error

817.279

here

818

none of these files exist so in our

819.839

navigation screen home screen it now

822.56

cannot find the path to home screen

825.6

so home stack

827.6

we have to change our path here to

830.8

actually go up a level not from root

833.839

because we're down a folder

835.519

when we were in app we could use dot

838

which would say start at the root

840.32

and go find the folder

842.48

however here we're

844.399

under a folder off of the root under

846.32

navigation so we need to use dot dot to

848.959

go back up a level in order to find the

851.519

folder that we're looking for so all you

853.68

have to do is just change it to dot dot

858.72

so it's nice about this as we walk the

861.36

stack as we start cleaning things up the

864.56

expo debugger is pretty clean about

866.48

telling us what we forgot to do or what

868.639

else we need to do

885.279

you