📺 Develpreneur YouTube Episode

Video + transcript

React Native Fundamentals - Part1

2021-09-23 •Youtube

Detailed Notes

React-Native Fundamental Concepts Part 1 focuses on: View SafeAreaView ScrollView StyleSheets

For a full list of components and APIs goto https://reactnative.dev/docs/accessibilityinfo

Views

Views are containers that support layouts with flexbox, style, some touch handling, and accessibility controls.

View

A view Is the basic building block of UI. That is to say it is a small rectangular element on the screen which displays text, images, or respond to user input. I that case, even the smallest visual elements of an app, like a line of text or a button, are kinds of views. In addition, some kinds of views can contain other views. Such as, a container component like a web element div. Finally, it is also a good option for grouping or laying out children components.

SafeAreaView (iOS only)

In this case, the purpose of SafeAreaView is to render content within the safe area boundaries of a device. It is currently only applicable to iOS devices with iOS version 11 or later. Also, SafeAreaView renders nested content and automatically applies padding to reflect the portion of the view that is not covered by navigation bars, tab bars, toolbars, and other ancestor views. Moreover, and most importantly, Safe Area's paddings reflect the physical limitation of the screen, such as rounded corners or camera notches (i.e. the sensor housing area on iPhone X).

ScrollView

A generic scrolling container that can contain multiple components and views.

StyleSheet

With React Native, you style your application using JavaScript. Thus, all of the core components accept a prop named style. The style names and values usually match how CSS works on the web, except names are written using camel casing, e.g. backgroundColor rather than background-color.

What is React-Native

React Native is an open-source mobile application framework created by Facebook, Inc. It is used to develop applications for Android, Android TV, iOS, macOS, tvOS, Web, Windows and UWP by enabling developers to use React's framework along with native platform capabilities.

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]
so the more i work with this uh more i
work with react native the more
i find that i can have so many different
topics to talk about to introduce you to
react native so today so in our first
lesson actually we talked about getting
started how to set up an environment how
to install the libraries the apis and
then configure your desktop in order for
you to actually run your react native
application
on ios android or the web
so today we're going to be talking about
some of the fundamental concepts
uh before i talk about fundamental
concepts let me reiterate what react
native is
so react native is an open source mobile
application framework created by
facebook now this is used or was created
to help developers develop applications
for android
android tv ios mac os tv os web windows
and so on and it allows users to use the
react native framework along with its
native platform capabilities
so today we're going to be getting into
those fundamental concepts we're going
to actually talk about the different
types of components that you can add to
a mobile application or in a sense a
react native application
and this
table here is taken straight from the
react native website and it i like this
table because it really highlights the
differences between react native android
ios and the web and really it's just
essentially a new set of tags that does
the same thing on different devices so
in react native we have the main
container so to speak which is our view
in android is a view group ios is a ui
view and if we think about web pages
this is essentially a non-scrolling div
so
as they describe it here it's a
container that supports layouts with
flexbox
style some touch handling and
accessibility controls
now in order to actually display some
additional information like text images
and so on we have to use some additional
tags so in react native we have the text
tag and it's commonly
more
familiar with if you think back to web
it's the p tag the paragraph tag and in
android and ios it's text view or ui
text view so if you notice here really
the only differences between android and
ios
except for view group is the tags are
prefixed with ui for ios
they're pretty much the same
and then edit text is text field ua text
field for ios view
and our text field again allows us to
display text styles nested strings of
text and even handle touch events
images
same as img for web
allows us to display different types of
images
scroll view is a scrolling container so
we can actually scroll and view elements
that are off the page
again same as div the only difference is
in mobile it's something that you can
actually scroll up and down
whereas with divs because of a web page
the browser uh controls the scrolling
then we have text input which is the
equivalent of a form input in web of
input type tech and this allows the user
to enter text
so these are the basic core components
that we're going to look at today along
with a few additionals but we're mainly
just going to focus on the different
components and how we can use it
i muted them for you thank you
all right now so the first thing we want
to do is we're going to go out to our
desktop
and we're going to create a react uh
native project for us to start with so
we're going to use expo again so we'll
do expo init and we're just going to
call this one sample project or sample
app
again we have our choices we can do
blank blank type script tab type script
minimal or minimal typescript i'm just
going to keep it using blank for now we
will get into these others
in future lessons
so we'll start with blank
and it only takes a few seconds
to install everything and load
and what it's doing is installing all
the javascript dependencies it's
building the project
if you think about java this is kind of
similar to like a maven install uh where
you use maven to generate your projects
so it's going to pull in all your
dependencies
build your
project structure build the folders and
then install any additional dependencies
that you need
there we go
now i like
walking through this again because
last time we quickly went over how to
create projects with expo so once it
finished installing and building your
project it's going to walk you through
some different steps here to actually
start your project or work with it so
you first need to actually go into the
folder because you're still in your
workspace
so we'll go into cd sample app
now you can do
you can use the
npm you can use the node commands to
start this or you can use expo now
before i do that i'm going to type code
dot so that we can actually work with
our project code in visual studios
well that opens up
i'm going to also follow up with this
command with expo start
and what this is going to do is this is
going to start
our
native uh
our native application
okay it started the development tools
but here again we have our qr code we
can take a picture of that with their
phone and load our app on our phone
we could also
uh share this url to our expo apps on
our devices
now if
everything is working hunky-dory on our
systems
uh with android we can kick off android
we can kick off ios and we can kick off
web now because big sur has a major
update android is still not running
friendly on
my mac right now i need to get the
linux or the arm
emulator set
for
the android
application the simulators to
essentially kick off
so i won't be able to do android today
instead i'm going to show you uh two
different versions of ios so we'll start
the first one just hit
i
and this one's going to open
a
iphone 8
it's gonna install expo and then it's
going to start the project
all right now it's running now if i hit
question or if i do question mark
it gives me the list of all the commands
again
now we want to test this on two
different simulators so we have the
iphone 8 without the notch
and i want to select an ios emulator
that actually contains the notch at the
top so i can do shift i
and i can go down here to iphone 12
and it will start up a second simulator
running iphone 12.
and as you can see here now we have that
annoying little notch that apple
introduced with the iphone 12.
and i'm showing this because once we uh
start playing around with the components
you're going to see that there's some
things we need to watch out for when we
use certain views on different devices
and lastly if you want to actually debug
the application or actually look at the
developer tools you can do shift d to
toggle opening the developer tools on
startup which is currently disabled and
then you can open the developer tools by
pressing d
and this opens up our
emulator here that essentially gives you
a browser version of what we see in the
console
all right so we have our applications
running so let's go into visual studio
code
oh one other thing
if you go to this
link
this gives you a list of all the
components
that you can get or that you can use for
react native now we're not going to
cover all of these today but we are
going to highlight
pretty much the ones you're going to use
the most
all right
go back in xcode here
so here if we go under our app.js now
this is the main component of our expo
app where
the main screen the first screen is
loaded
now in order for us to use any of the
react native components we need to make
sure that we import them
so here by default it's going to start
you with a simple page called stylesheet
text and view so it's going to contain
three components
and we're importing them from react
native
we're also going to have to import react
from the react libraries
and it also is including the status bar
for the expo status bar
now
for your applications you may not need
this one
if you're not running an expo but if you
are running an expo this here will give
you the little status bar down here if
the application is running connected or
has any problems
now the other thing is
uh it created a sample style sheet for
us now we'll come back to this in a
minute but just know that this is where
some of the styling
information is contained for our
application
all right so the first thing i want to
talk about is this view component so
views are a container that supports
different layouts with
flexbox style some touch handling and
access controls
our view
is a basic building block of our ui
it's essentially a small rectangular
element on the screen which can be used
to display text images or respond to
users input
even the smallest
visual element of an app like a line of
text or a button are kinds of views
also some kinds of views can contain
other views
now if we think of views if we like if
we go back to the
right here
u is essentially a div in html and divs
are just a placement container or holder
container where we can put a whole bunch
of different elements inside of it and
build out our application
so it's a good
little component for grouping
or layering out of children
so if we look at this we can do a sim
simple view
and as i make the changes we see it real
time
so we have view
now if we go inside of view
and hit control space we get a list of
all the different attributes that we can
attach to a view now i'm not going to go
into all these today but these are just
some of the ones that you can actually
get in and actually play around with
now if we want to add some style we can
use the style
attribute
followed by equal
and it requires
these curly brackets
and let's just say we want to change the
background color of
our view so we'll do an inline style
right now this is similar to what you
can do inside of
html
so we'll do style
we'll use background color
and
colon
and let's make it blue
save
all right let's also
add some
dimensions to our view
so let's also add
a height
and let's
say
100 pixels
and then let's also add a width
and let's give it 20 pixels
and there's our bar
so here's our view let's make that a
little bit wider let's make it a hundred
off oh thousand yeah that's way too big
there we go
all right so as you can see we now have
a view
but if you notice our view
is also
being displayed behind the status bar so
it's being displayed at the topmost
section of the application well we
really don't want that because we want
all of our information or all of our
view to be displayed
so the alternative to a view for ios
is to use something called safe view or
safe area view
simply type safe
area view
now here's the cool part in visual code
if you're
if you use the little helper tool here
when you select
a component that is not in your import
list it will automatically import it for
you
that way you don't have to constantly
remember that you have to import
wrap this around our view
save
and just by doing that just by wrapping
our view in a safe area view
all of a sudden our view on ios at least
is now below the status bar
so we didn't have to do any additional
styling to make our view visible
so the safe area view component
is used to render or to render the
content within the safe area boundaries
of your device
now it's currently only uh applies to
ios devices with ios versions 11 or
later
now the safe view safe area view renders
nested content and automatically applies
the padding to reflect the portion of
the view that is not covered by the
navigation bars tab bars toolbars and
other
ancestor views
so moreover the most importantly the
safe area padding reflects the physical
limitations of the screen
such as the rounded corners or camera
notches
essentially the sensor housing area of
the iphone x
now another view
we can add is a scroll view
a curve safe area view
we can add a scroll view
and i want to wrap that around our main
view
now what this does is
it allows us to actually scroll
our view up and down now you can't
really see it much but it's kind of
shrinking here
so if i click inside of my view i can
move it up and down
now this is useful when you have a view
that has multi
multiple components that cannot all be
displayed in one section
and then that allows the users to press
and
slide the view up or down
so the scroll view is the generic
scrolling container that can contain
multiple components and views
so we could actually throw in a couple
of views here
right thank you
two more views
change that one to red
one to yellow
save
so we now have three views now if you
notice
you can now see that
i'm able to scroll the whole view
up and down
now if i added an additional scroll view
let's just do this copy the whole
section here
so if i take a second one
and let's change this one to be green
black
purple
so if i
click on the top view
i can scroll it up and down does not
impact the second scroll view and then i
can click the second scroll view and
scroll up and down
you
Transcript Segments
0.42

[Music]

27.359

so the more i work with this uh more i

30.72

work with react native the more

33.92

i find that i can have so many different

36.719

topics to talk about to introduce you to

38.879

react native so today so in our first

42.16

lesson actually we talked about getting

44

started how to set up an environment how

45.84

to install the libraries the apis and

49.12

then configure your desktop in order for

51.039

you to actually run your react native

54.8

application

56

on ios android or the web

59.52

so today we're going to be talking about

61.199

some of the fundamental concepts

64.479

uh before i talk about fundamental

66.08

concepts let me reiterate what react

68.24

native is

69.6

so react native is an open source mobile

72.72

application framework created by

74.799

facebook now this is used or was created

78.32

to help developers develop applications

80.72

for android

82.159

android tv ios mac os tv os web windows

87.6

and so on and it allows users to use the

90.799

react native framework along with its

93.36

native platform capabilities

95.92

so today we're going to be getting into

98.24

those fundamental concepts we're going

100.079

to actually talk about the different

101.36

types of components that you can add to

104.399

a mobile application or in a sense a

107.2

react native application

109.92

and this

111.119

table here is taken straight from the

112.96

react native website and it i like this

117.119

table because it really highlights the

118.96

differences between react native android

122.24

ios and the web and really it's just

126.159

essentially a new set of tags that does

128.8

the same thing on different devices so

132.08

in react native we have the main

134.56

container so to speak which is our view

137.599

in android is a view group ios is a ui

141.76

view and if we think about web pages

144.64

this is essentially a non-scrolling div

147.68

so

148.72

as they describe it here it's a

150.72

container that supports layouts with

153.04

flexbox

154.319

style some touch handling and

156.72

accessibility controls

161.12

now in order to actually display some

163.76

additional information like text images

166.16

and so on we have to use some additional

168

tags so in react native we have the text

172.08

tag and it's commonly

174.72

more

176

familiar with if you think back to web

178.319

it's the p tag the paragraph tag and in

181.92

android and ios it's text view or ui

185.36

text view so if you notice here really

188.08

the only differences between android and

190.319

ios

192.159

except for view group is the tags are

196

prefixed with ui for ios

198.72

they're pretty much the same

201.36

and then edit text is text field ua text

205.2

field for ios view

207.84

and our text field again allows us to

210.159

display text styles nested strings of

212.56

text and even handle touch events

216.319

images

217.44

same as img for web

220.08

allows us to display different types of

222.159

images

223.68

scroll view is a scrolling container so

226.799

we can actually scroll and view elements

228.72

that are off the page

231.12

again same as div the only difference is

234.319

in mobile it's something that you can

236.48

actually scroll up and down

239.2

whereas with divs because of a web page

242.159

the browser uh controls the scrolling

247.12

then we have text input which is the

249.36

equivalent of a form input in web of

252.72

input type tech and this allows the user

255.439

to enter text

257.28

so these are the basic core components

260.079

that we're going to look at today along

261.919

with a few additionals but we're mainly

264.56

just going to focus on the different

266.72

components and how we can use it

290.4

i muted them for you thank you

293.36

all right now so the first thing we want

295.6

to do is we're going to go out to our

298.08

desktop

299.199

and we're going to create a react uh

303.039

native project for us to start with so

305.44

we're going to use expo again so we'll

307.12

do expo init and we're just going to

309.84

call this one sample project or sample

312.32

app

317.12

again we have our choices we can do

319.28

blank blank type script tab type script

322.8

minimal or minimal typescript i'm just

325.36

going to keep it using blank for now we

327.28

will get into these others

329.68

in future lessons

331.28

so we'll start with blank

336.479

and it only takes a few seconds

338.4

to install everything and load

351.6

and what it's doing is installing all

353.199

the javascript dependencies it's

355.039

building the project

356.72

if you think about java this is kind of

359.12

similar to like a maven install uh where

362.4

you use maven to generate your projects

365.199

so it's going to pull in all your

366.4

dependencies

368.08

build your

369.28

project structure build the folders and

371.52

then install any additional dependencies

374.08

that you need

376.4

there we go

379.759

now i like

381.12

walking through this again because

384.24

last time we quickly went over how to

386.08

create projects with expo so once it

389.199

finished installing and building your

391.12

project it's going to walk you through

392.72

some different steps here to actually

394.88

start your project or work with it so

397.199

you first need to actually go into the

399.039

folder because you're still in your

401.039

workspace

402.4

so we'll go into cd sample app

404.88

now you can do

406.72

you can use the

408.96

npm you can use the node commands to

411.759

start this or you can use expo now

414.96

before i do that i'm going to type code

417.599

dot so that we can actually work with

420

our project code in visual studios

423.84

well that opens up

425.919

i'm going to also follow up with this

427.919

command with expo start

430.96

and what this is going to do is this is

432.72

going to start

434.24

our

435.599

native uh

437.52

our native application

445.28

okay it started the development tools

447.919

but here again we have our qr code we

450

can take a picture of that with their

451.28

phone and load our app on our phone

453.919

we could also

455.28

uh share this url to our expo apps on

458.96

our devices

461.039

now if

462.96

everything is working hunky-dory on our

465.199

systems

466.4

uh with android we can kick off android

470

we can kick off ios and we can kick off

472.8

web now because big sur has a major

476.24

update android is still not running

479.36

friendly on

481.12

my mac right now i need to get the

484.319

linux or the arm

486.16

emulator set

488.24

for

490

the android

491.28

application the simulators to

492.879

essentially kick off

494.319

so i won't be able to do android today

497.12

instead i'm going to show you uh two

499.36

different versions of ios so we'll start

502.639

the first one just hit

504.84

i

506.639

and this one's going to open

508.96

a

510.24

iphone 8

513.039

it's gonna install expo and then it's

515.599

going to start the project

522.56

all right now it's running now if i hit

525.04

question or if i do question mark

528

it gives me the list of all the commands

529.92

again

531.04

now we want to test this on two

533.6

different simulators so we have the

535.2

iphone 8 without the notch

538.08

and i want to select an ios emulator

541.2

that actually contains the notch at the

543.6

top so i can do shift i

546.48

and i can go down here to iphone 12

550.399

and it will start up a second simulator

553.04

running iphone 12.

557.68

and as you can see here now we have that

560.08

annoying little notch that apple

562.24

introduced with the iphone 12.

565.12

and i'm showing this because once we uh

568.08

start playing around with the components

569.76

you're going to see that there's some

570.88

things we need to watch out for when we

573.44

use certain views on different devices

578.48

and lastly if you want to actually debug

581.44

the application or actually look at the

583.76

developer tools you can do shift d to

586.48

toggle opening the developer tools on

588.48

startup which is currently disabled and

590.8

then you can open the developer tools by

592.8

pressing d

595.68

and this opens up our

597.76

emulator here that essentially gives you

599.92

a browser version of what we see in the

602.24

console

606.24

all right so we have our applications

608.16

running so let's go into visual studio

611.36

code

621.839

oh one other thing

625.44

if you go to this

627.839

link

629.839

this gives you a list of all the

631.92

components

634.8

that you can get or that you can use for

637.279

react native now we're not going to

639.12

cover all of these today but we are

641.2

going to highlight

642.64

pretty much the ones you're going to use

643.92

the most

646.399

all right

648.16

go back in xcode here

651.279

so here if we go under our app.js now

654.24

this is the main component of our expo

657.6

app where

659.36

the main screen the first screen is

661.44

loaded

662.64

now in order for us to use any of the

666.399

react native components we need to make

668.959

sure that we import them

670.959

so here by default it's going to start

673.04

you with a simple page called stylesheet

677.6

text and view so it's going to contain

680.16

three components

681.839

and we're importing them from react

683.36

native

684.64

we're also going to have to import react

687.6

from the react libraries

690.48

and it also is including the status bar

693.6

for the expo status bar

696.32

now

698.959

for your applications you may not need

701.44

this one

702.64

if you're not running an expo but if you

705.279

are running an expo this here will give

707.519

you the little status bar down here if

709.6

the application is running connected or

712.72

has any problems

715.44

now the other thing is

717.76

uh it created a sample style sheet for

721.12

us now we'll come back to this in a

722.8

minute but just know that this is where

724.88

some of the styling

726.48

information is contained for our

728.399

application

734

all right so the first thing i want to

735.279

talk about is this view component so

738.24

views are a container that supports

741.2

different layouts with

742.839

flexbox style some touch handling and

746.48

access controls

748.16

our view

749.36

is a basic building block of our ui

753.12

it's essentially a small rectangular

755.76

element on the screen which can be used

758.16

to display text images or respond to

760.959

users input

762.88

even the smallest

764.48

visual element of an app like a line of

767.76

text or a button are kinds of views

772.32

also some kinds of views can contain

774.959

other views

778.8

now if we think of views if we like if

782.48

we go back to the

786.079

right here

787.36

u is essentially a div in html and divs

792

are just a placement container or holder

794.48

container where we can put a whole bunch

796.16

of different elements inside of it and

798.24

build out our application

801.92

so it's a good

803.44

little component for grouping

806.24

or layering out of children

809.12

so if we look at this we can do a sim

811.839

simple view

820.56

and as i make the changes we see it real

822.56

time

823.68

so we have view

827.44

now if we go inside of view

832.399

and hit control space we get a list of

835.519

all the different attributes that we can

837.519

attach to a view now i'm not going to go

840.16

into all these today but these are just

842.56

some of the ones that you can actually

845.279

get in and actually play around with

852.48

now if we want to add some style we can

855.04

use the style

856.639

attribute

859.279

followed by equal

861.6

and it requires

863.68

these curly brackets

867.839

and let's just say we want to change the

869.76

background color of

871.92

our view so we'll do an inline style

874.399

right now this is similar to what you

875.92

can do inside of

878.32

html

879.839

so we'll do style

881.519

we'll use background color

887.76

and

888.8

colon

890.48

and let's make it blue

895.279

save

910.88

all right let's also

912.399

add some

913.839

dimensions to our view

916.079

so let's also add

919.199

a height

922.48

and let's

923.76

say

924.72

100 pixels

927.36

and then let's also add a width

932.959

and let's give it 20 pixels

938.88

and there's our bar

942

so here's our view let's make that a

944

little bit wider let's make it a hundred

948.8

off oh thousand yeah that's way too big

951.12

there we go

952.399

all right so as you can see we now have

954.24

a view

955.6

but if you notice our view

959.199

is also

960.639

being displayed behind the status bar so

963.6

it's being displayed at the topmost

965.68

section of the application well we

968.24

really don't want that because we want

971.279

all of our information or all of our

972.959

view to be displayed

974.8

so the alternative to a view for ios

979.839

is to use something called safe view or

982.959

safe area view

985.519

simply type safe

987.839

area view

989.36

now here's the cool part in visual code

992.56

if you're

993.839

if you use the little helper tool here

996.88

when you select

998.399

a component that is not in your import

1000.72

list it will automatically import it for

1003.279

you

1005.68

that way you don't have to constantly

1007.759

remember that you have to import

1011.04

wrap this around our view

1015.279

save

1017.199

and just by doing that just by wrapping

1019.759

our view in a safe area view

1022.079

all of a sudden our view on ios at least

1025.28

is now below the status bar

1028.079

so we didn't have to do any additional

1029.919

styling to make our view visible

1033.36

so the safe area view component

1036.079

is used to render or to render the

1039.679

content within the safe area boundaries

1042.24

of your device

1045.76

now it's currently only uh applies to

1049.039

ios devices with ios versions 11 or

1052.08

later

1053.36

now the safe view safe area view renders

1056.799

nested content and automatically applies

1059.52

the padding to reflect the portion of

1061.36

the view that is not covered by the

1063.2

navigation bars tab bars toolbars and

1067.12

other

1068.24

ancestor views

1070.48

so moreover the most importantly the

1072.64

safe area padding reflects the physical

1075.6

limitations of the screen

1077.679

such as the rounded corners or camera

1080.88

notches

1082.24

essentially the sensor housing area of

1084.32

the iphone x

1091.039

now another view

1092.72

we can add is a scroll view

1098.4

a curve safe area view

1100.64

we can add a scroll view

1112.32

and i want to wrap that around our main

1114.72

view

1118.24

now what this does is

1120.24

it allows us to actually scroll

1124.16

our view up and down now you can't

1126.08

really see it much but it's kind of

1127.679

shrinking here

1129.12

so if i click inside of my view i can

1131.52

move it up and down

1133.28

now this is useful when you have a view

1136.32

that has multi

1137.6

multiple components that cannot all be

1140.08

displayed in one section

1142.559

and then that allows the users to press

1144.559

and

1145.44

slide the view up or down

1149.36

so the scroll view is the generic

1151.84

scrolling container that can contain

1154.559

multiple components and views

1157.44

so we could actually throw in a couple

1159.6

of views here

1160.96

right thank you

1164

two more views

1165.84

change that one to red

1168.88

one to yellow

1171.12

save

1172.24

so we now have three views now if you

1174.64

notice

1177.2

you can now see that

1178.96

i'm able to scroll the whole view

1182.48

up and down

1183.76

now if i added an additional scroll view

1192.48

let's just do this copy the whole

1194.24

section here

1197.039

so if i take a second one

1199.28

and let's change this one to be green

1204.48

black

1208.48

purple

1211.919

so if i

1213.28

click on the top view

1215.679

i can scroll it up and down does not

1217.52

impact the second scroll view and then i

1219.679

can click the second scroll view and

1222

scroll up and down

1240.88

you