📺 Develpreneur YouTube Episode

Video + transcript

React Native - Put It All together Part 2

2021-12-09 •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]
so let's take the settings stack
let's add that navigation
let's go back to app
the first part here
paste
we can steal from home stack
okay so we got button we got create
navigator
and what else do we need we need
this
setting screen we actually need
screen
okay so settings
for stack
screen passing our navigation
looks good reloaded
so now if i come back over here
we can now delete
our stack because we don't need it
anymore
so we import
settings
name that wrong
no setting stack
there it is
all right so now we don't need our
button
we don't need to create
or the settings stack all that looks
good settings
sometimes
when you're making changes like this
you'll have to actually flush the
application to get a better idea of what
the problem is invalid component
property for screen settings so go to
screen
settings
navigation
[Music]
navigate to home
home stack
home
[Music]
settings stack setting
screen oh i forgot to convert it
constant
equal
so we convert it to a constant from a
function
need to export it
all right
now we've got the settings
home
stack screen
let's go back to app and let me reload
it
so as you make changes like this
sometimes when you get the error over
here you have to actually go back to the
console and hit the r button
which reloads the application so when
you're messing around with the navigator
or the drawers or the stacks
you will have to reload from time to
time
right and lastly we have this navigation
container
so we could actually
create this one
as another navigator
and this could be not navigation
container but this could actually be
our main stack
and we go back to app
so we copy this section right here
we go back to main stack
we need to make it
a constant
equals there's no parameters for this
one
we need to return
code
save there we go
then export
default
and stack
it's not going to work because we need
our imports
so we can come up here copy all of our
imports
main stack
okay we don't need create door navigator
we have navigation we have home stack we
have settings stack okay we save that
we don't need status bar
right now if we go to app
we can actually now get rid of all of
that
so let me leave the last one so i can
quickly reference it
so we have settings stack we'll change
this to main
stack
main stack
and now
all i have to do
is return
chain
stack
and i have to fix one thing in the stack
so because we moved our navigator down
we need to fix our imports
okay imports are fixed
and we now have our working application
and it's now organized so when we look
at app it says oh okay
our code is not here so we move it out
of here we can actually drop the reactor
[Music]
reload
import
forgot to import the drawer which we
needed
so now everything works again
our app is clean
and now all of our individual components
for navigation and screens
are now separated
now if we wanted to go even further we
could go further we could create like a
component so if you wanted to you could
create this screen component so you
could do like a stacked screen
and pass in some values
you could also do a
button so like if we go to the screen
here we could pull out button and create
button to be a different component we
could actually export a custom button
we could do custom text
you could also create styles so i could
take this style right
here and we can create a special style
for views so we could do
new file
view
style
js
our view let's copy the style
import
let me just copy this
quicker
all right so we need to import style
sheet
from react native
create a constant for our screen style
or in this case view style
and we export the constant
and we're going to set the margins top
margin menu item justify content
so we have view style
so now if i go back to the home screen
i can now import my style
from styles dot view style
and then to use it get rid of all this
garbage in here
and we can now do view style dot view
and our text moved up to the top because
i changed the layout
but yet our other notifications are not
impact
but what's nice about this is oh i now
have a common view
style so i can now apply this style
throughout my other screens
copy
the notifications
and do the same thing here
now if i go to notifications it's at the
top
but because i haven't applied to
settings yet settings is still here
so if we do it again
settings
and there we go so now if we want to
change the look and feel for any of our
screens we just change the view style
here
we can change view
i will bring up our other example
which is going to pretty much pull it
all together i've already pre-coded this
so we'll go through all the different
changes i made to the application so let
me stop the current application
and start this one
so as you can see here in this project
i've already broken things out for the
screens i've added some additional
styles
i have our navigation
we have our assets
so now i'm going to load it and you'll
see a splash screen
with development
and then we go to our home
which has an image
so in order to get that splash screen to
show up
we make a small change to the app.json
file
and all i had to do was find the splash
tag or the splash property and change
the image location to our assets
so i've also added a image to home i did
not have time to find our other
developer icon but i'll replace that
here
but all i had to do there was again find
my icon
and then on my home screen
i just needed to import
the image tag
need those
so we imported the image tag
i imported the image style
and i told it where to find the image so
we do source and since it's not a web
image i pointed it directly to the image
location
and the image style
just has some style sheets for the
specific image so if we go to image
we're setting it 466 and 58 i have small
image large image stretchy image
so if we wanted to change the image size
all we have to do is go change
style
and it shrunk a little bit
his code picks up all your different
styles so again it's selectable so i can
do stretchy image
and it doesn't look good so we'll go
back to the original image we had
i also added some additional styles for
the screens so if we go look at our
screens
i set it at the top got margin to 10
line item center
i also added some text styling
so this is a
title text so it's font 20 and it's bold
so we go back to home and look at text
text is using title text
and then we have our on button
still click
so now if we go to notifications
i made some changes here
so notifications
we used our image background tag that we
talked about
i think in class 2 or 3 about
fundamentals so the image background
allows us to put an image behind our
view
and then all you have to do is stack
elements on top of the background image
so you can layer them over the image so
we have our developer nerd as background
we also have a scrollable text here for
first part and last uh second part
i have my notifications and my
notifications button here
and one thing i wanted to show you here
is yes i am importing styles
but you can also still use internal
customized styles so we can actually
define additional styles for this page
here
don't really recommend it
really once you start breaking
components out you really want to make
sure you
reuse the
particular style sheets you want
because if you hard code a style this
way
if you need to change the theme or
overall look and feel of your
application you'll have to track down
where this code is within a given
component and change it there whereas if
you did everything under styles or you
had a themes folder if you changed it
there it would apply to everything
also this particular screen starting to
get a little big so one of the things we
could have done was we could have pulled
out this safe area view here
and pulled out the scroll view here in
two separate components and then we
could have imported those components
directly keeping this guy nice and small
and pulling the individual components
into their own separate files
so for instance we could do i don't
think i have a components folder i do
not
so if we do components
let's just do
[Music]
a new file
and this is just sample
scroll view
javascript paste
so we need a constant
we need to give it a name so we'll call
it what we call the files the sample
scroll view
we don't need to pass in any values so
it can be an empty
parameters
then we start our function
and then we need to return our element
return our view return
then we need to export our sample
and then lastly we need to import
our components
let's just make life easy we'll go up
here and copy
the top section
paste so it's telling us what we don't
need so we don't need image background
we don't need style sheet or view we
just need scroll view and text
you
Transcript Segments
1.35

[Music]

26.4

so let's take the settings stack

28.88

let's add that navigation

34.8

let's go back to app

37.6

the first part here

41.76

paste

43.12

we can steal from home stack

53.039

okay so we got button we got create

55.039

navigator

56.559

and what else do we need we need

59.12

this

60.079

setting screen we actually need

74.08

screen

80.479

okay so settings

83.36

for stack

84.84

screen passing our navigation

87.92

looks good reloaded

90.56

so now if i come back over here

92.799

we can now delete

94.56

our stack because we don't need it

95.92

anymore

97.759

so we import

101.04

settings

103.52

name that wrong

104.96

no setting stack

110.399

there it is

124.88

all right so now we don't need our

127.119

button

128.8

we don't need to create

130.879

or the settings stack all that looks

133.44

good settings

136.48

sometimes

137.84

when you're making changes like this

139.52

you'll have to actually flush the

141.12

application to get a better idea of what

143.84

the problem is invalid component

145.84

property for screen settings so go to

148.319

screen

150.8

settings

152.8

navigation

153.65

[Music]

155.519

navigate to home

159.12

home stack

161.44

home

161.77

[Music]

163.44

settings stack setting

166.08

screen oh i forgot to convert it

170.879

constant

174.64

equal

177.12

so we convert it to a constant from a

179.04

function

180.879

need to export it

185.599

all right

188.319

now we've got the settings

191.92

home

195.76

stack screen

200.56

let's go back to app and let me reload

202.959

it

204.159

so as you make changes like this

205.92

sometimes when you get the error over

207.599

here you have to actually go back to the

209.519

console and hit the r button

214.4

which reloads the application so when

217.36

you're messing around with the navigator

219.84

or the drawers or the stacks

222.319

you will have to reload from time to

223.92

time

227.28

right and lastly we have this navigation

230.48

container

232.319

so we could actually

233.84

create this one

235.519

as another navigator

239.68

and this could be not navigation

241.68

container but this could actually be

243.84

our main stack

248.48

and we go back to app

250.4

so we copy this section right here

254.08

we go back to main stack

257.519

we need to make it

259.84

a constant

264.8

equals there's no parameters for this

266.56

one

269.919

we need to return

274

code

276.08

save there we go

277.68

then export

280.16

default

282

and stack

284.24

it's not going to work because we need

285.52

our imports

286.8

so we can come up here copy all of our

288.88

imports

290.8

main stack

295.04

okay we don't need create door navigator

297.44

we have navigation we have home stack we

300

have settings stack okay we save that

303.28

we don't need status bar

305.759

right now if we go to app

307.84

we can actually now get rid of all of

310.639

that

311.84

so let me leave the last one so i can

313.919

quickly reference it

315.84

so we have settings stack we'll change

317.68

this to main

319.759

stack

323.039

main stack

325.6

and now

326.88

all i have to do

328.8

is return

332.08

chain

333.12

stack

335.199

and i have to fix one thing in the stack

338.24

so because we moved our navigator down

340.88

we need to fix our imports

343.199

okay imports are fixed

346.96

and we now have our working application

352.479

and it's now organized so when we look

355.039

at app it says oh okay

357.199

our code is not here so we move it out

359.44

of here we can actually drop the reactor

374.06

[Music]

378.8

reload

383.68

import

399.6

forgot to import the drawer which we

402.96

needed

404.88

so now everything works again

407.759

our app is clean

409.52

and now all of our individual components

411.52

for navigation and screens

413.84

are now separated

415.52

now if we wanted to go even further we

417.36

could go further we could create like a

419.12

component so if you wanted to you could

422.16

create this screen component so you

424.16

could do like a stacked screen

426.639

and pass in some values

429.36

you could also do a

431.52

button so like if we go to the screen

433.28

here we could pull out button and create

436.639

button to be a different component we

439.84

could actually export a custom button

442.24

we could do custom text

445.28

you could also create styles so i could

447.199

take this style right

448.84

here and we can create a special style

452.479

for views so we could do

454.72

new file

456.24

view

458.4

style

459.84

js

462.8

our view let's copy the style

469.44

import

471.28

let me just copy this

472.96

quicker

474.879

all right so we need to import style

476.479

sheet

478.08

from react native

479.919

create a constant for our screen style

482.879

or in this case view style

485.68

and we export the constant

488.08

and we're going to set the margins top

490.479

margin menu item justify content

494.639

so we have view style

496.8

so now if i go back to the home screen

499.36

i can now import my style

506.16

from styles dot view style

509.12

and then to use it get rid of all this

512.08

garbage in here

515.2

and we can now do view style dot view

518.959

and our text moved up to the top because

520.959

i changed the layout

524.8

but yet our other notifications are not

527.12

impact

528.48

but what's nice about this is oh i now

530.72

have a common view

533.04

style so i can now apply this style

535.279

throughout my other screens

538.72

copy

540.16

the notifications

542.959

and do the same thing here

552.16

now if i go to notifications it's at the

554.32

top

555.6

but because i haven't applied to

557.04

settings yet settings is still here

560.08

so if we do it again

563.04

settings

584

and there we go so now if we want to

586.48

change the look and feel for any of our

588.399

screens we just change the view style

591.6

here

594.24

we can change view

598

i will bring up our other example

601.2

which is going to pretty much pull it

603.6

all together i've already pre-coded this

607.92

so we'll go through all the different

609.839

changes i made to the application so let

611.839

me stop the current application

614.959

and start this one

617.44

so as you can see here in this project

619.76

i've already broken things out for the

621.839

screens i've added some additional

623.68

styles

625.12

i have our navigation

627.6

we have our assets

630.8

so now i'm going to load it and you'll

632.64

see a splash screen

634.56

with development

636.88

and then we go to our home

639.519

which has an image

641.2

so in order to get that splash screen to

643.279

show up

644.32

we make a small change to the app.json

647.36

file

649.2

and all i had to do was find the splash

651.44

tag or the splash property and change

654.399

the image location to our assets

657.519

so i've also added a image to home i did

661.44

not have time to find our other

663.44

developer icon but i'll replace that

665.92

here

667.04

but all i had to do there was again find

669.6

my icon

672.48

and then on my home screen

675.44

i just needed to import

677.92

the image tag

679.92

need those

682.56

so we imported the image tag

685.44

i imported the image style

688.72

and i told it where to find the image so

690.959

we do source and since it's not a web

693.36

image i pointed it directly to the image

696.079

location

698.32

and the image style

700.959

just has some style sheets for the

702.88

specific image so if we go to image

705.04

we're setting it 466 and 58 i have small

708.56

image large image stretchy image

711.279

so if we wanted to change the image size

714.079

all we have to do is go change

716.88

style

718.639

and it shrunk a little bit

724.32

his code picks up all your different

726.24

styles so again it's selectable so i can

729.12

do stretchy image

731.6

and it doesn't look good so we'll go

733.04

back to the original image we had

737.92

i also added some additional styles for

740.32

the screens so if we go look at our

742.399

screens

744.639

i set it at the top got margin to 10

748.32

line item center

750.8

i also added some text styling

753.76

so this is a

755.519

title text so it's font 20 and it's bold

760.32

so we go back to home and look at text

762.959

text is using title text

765.92

and then we have our on button

768.24

still click

769.68

so now if we go to notifications

772.48

i made some changes here

774.8

so notifications

776.8

we used our image background tag that we

779.36

talked about

780.48

i think in class 2 or 3 about

783.279

fundamentals so the image background

785.68

allows us to put an image behind our

789.279

view

790.48

and then all you have to do is stack

792.399

elements on top of the background image

795.04

so you can layer them over the image so

797.04

we have our developer nerd as background

800

we also have a scrollable text here for

803.519

first part and last uh second part

806.48

i have my notifications and my

808.32

notifications button here

810.72

and one thing i wanted to show you here

812.399

is yes i am importing styles

815.76

but you can also still use internal

817.92

customized styles so we can actually

819.6

define additional styles for this page

822

here

823.199

don't really recommend it

824.959

really once you start breaking

826.639

components out you really want to make

828.48

sure you

829.519

reuse the

831.36

particular style sheets you want

833.76

because if you hard code a style this

835.44

way

836.24

if you need to change the theme or

837.68

overall look and feel of your

838.8

application you'll have to track down

841.12

where this code is within a given

843.519

component and change it there whereas if

846.079

you did everything under styles or you

848

had a themes folder if you changed it

850.32

there it would apply to everything

852.399

also this particular screen starting to

854.48

get a little big so one of the things we

857.12

could have done was we could have pulled

859.6

out this safe area view here

862.8

and pulled out the scroll view here in

864.959

two separate components and then we

866.48

could have imported those components

868.24

directly keeping this guy nice and small

871.199

and pulling the individual components

873.04

into their own separate files

875.839

so for instance we could do i don't

878.24

think i have a components folder i do

880.399

not

881.36

so if we do components

884.32

let's just do

885.32

[Music]

886.56

a new file

888.639

and this is just sample

891.44

scroll view

896.839

javascript paste

899.36

so we need a constant

902.24

we need to give it a name so we'll call

904.56

it what we call the files the sample

907.44

scroll view

909.44

we don't need to pass in any values so

912

it can be an empty

915.12

parameters

916.48

then we start our function

918.959

and then we need to return our element

922.079

return our view return

925.04

then we need to export our sample

928.48

and then lastly we need to import

930.88

our components

932.639

let's just make life easy we'll go up

934.639

here and copy

936.24

the top section

938.24

paste so it's telling us what we don't

940.56

need so we don't need image background

942.48

we don't need style sheet or view we

944.079

just need scroll view and text

961.519

you