📺 Develpreneur YouTube Episode

Video + transcript

React Native Fundamentals Part 5

2021-10-07 •Youtube

Detailed Notes

React-Native Fundamental Concepts 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]
all right guys welcome back so last time
we covered fundamental concepts of react
native and in this
section we're going to actually continue
our discussion on fundamental concepts
and actually get into
talking about the next component in our
list here the last time we covered views
scroll views and some other views uh for
building out our mobile applications for
android ios
using react native this time we're going
to focus on the text component here
which displays
our styles and nested strings of text
on our screen
on our mobile apps or on our web apps
now just a quick recap the text
component in react native is similar to
the text view
in android view
ue text view in ios view
and it's also equivalent to the p tag or
paragraph tag of html
so that's it for our slides we're going
to jump out and actually go back to our
code examples
again i'm going to be using visual
studio
and after looking at the
video from last time i noticed the text
was a little bit smaller so uh does this
look better to you guys today is it
clear
yes it looks really clear
excellent
all right so last time we looked at
things like safe area view which allows
us to uh not have to configure our
mobile app our container for different
devices uh for ios for instance it
actually covers uh removes our view
beneath the
header information on mobile app for
instance the little notch here
uh our little carrier information the
time and our battery
so using safe area view it puts our main
container beneath the mobile restricted
areas
however with android we had to actually
customize this so for that we switched
over to
our
snack.expo
to look at android
now in android
we couldn't use safe area view safe area
view is ios specific so what we did
instead was we came down here and
created a custom style using stylesheets
for a
graded a attribute called container
and we use the padding top
along with the platform
which we imported
the platform
class and the status bar class which
allows us to check to see if the ios is
android windows mac
mac os ios or web and in this case we
wanted to check for android and then we
use the status bar class to get the
status bar's current height and if it's
not
if this comes back as null we'll set it
as zero if this is if it does find a
status bar then it's going to return the
status bar height and use that
so if we're android it's going to use
the current height and it's going to
drop it down beneath the title
information or the status bar of our
device
we also looked at things like scroll
view which allows us to actually scroll
or set our view containers
we also looked at views
and each of these little components here
is a view
we have to put all of our context inside
of our views which will be looking at
that today so additional tags go inside
of views and views essentially help us
control the layout of our applications
now i'm still not getting into the more
complex layout designs of our mobile
apps yet we're still going to focus
primarily today on component
and we also talked about inline
versus
javascript object styles but we could
actually do an inline style using the
squiggly bracket
or double squiggly bracket to actually
define an inline style using the style
attribute
we could actually call or use the style
beat to create a javascript object
called styles
which we can then
call using style
and we can nest these together using the
array attribute inside of our squirrely
bracket
so in an inline style we had to use two
early brackets to define the array
however for
a styles object we have to use the array
container or the array block to define
our style containers so we have styles
using the style object and the container
now the inline style can also be added
to this array so we have our outer
curly brace we have our array
and then we have a inline style again
denoted by the curly brace for
background color blue and then we're
also combining it with a styles object
so that's just a quick recap of last
time does anyone have any questions on
what we did here before we move on to
today's
component
nope
make this get a little bit bigger
there we go
all right so the next topic we're going
to look at
is a text
so
in react
text or the text tag
is
so text is denoted by the text tag
view here
and it has to go inside of a container
view
of some kind
and it's the text
tag
now if we hover over text
um
import as text
back over here
one of these actually gave me the
a little
nope i guess not
one of the tools i was working with
actually was nice and it gives you the
definition of the tags as you work but i
might have that on another machine
so
just to briefly tell you what text is so
text
is a react component for displaying text
on your screen
so the text supports nesting styling and
touch handles
it also has an attribute for the number
of lines so if we want to create like a
text area
of text where we have multiple lines of
text we can use the attribute number of
lines
so for instance if we want to define a
static text reference we can
do something like this
so we can go up here and we can
import
so if we want to use something
statically we have to import what is
called use state
from react
and what this state does is it now
allows us to define a constant and store
it into
basically into static memory
now if we use a constant
let's say we do a title
text
ray so there's our label
our
basically our
key to reference our title
we're going to call set or create a
variable set title
text
this is going to equal use state
and we'll say hello world
okay since this is the
title
we will just do sample app
now you don't need to save this uh like
i just did but um it's just a fourth of
habit when i write code i save
and then we'll define another constant
here and we will call this one
body text
and this one is just going to be a
straight up
variable and we're going to use state
and some really long text here
okay so we now have a constant defined
in a
kind of an array map so we have a key
value pair
and we can also define a constant
straight up with the constant
variable name and use the state
now what's nice about this is we can
come down here
and inside of our text here
i can actually put
using the early braces
body
text
and as you can see we've now added our
constant text here our static text
inside of our text or inside of our view
here
what's nice that allows us to define
text directly we can also add text
directly into the container so let me
clean up this view here
let's get rid of the other views for now
and just pick with the one view
and let's make this view a little bit
taller so let's say
1000
a little bit to 500
there we go
and we'll increase the width to say 300.
right
so far so good
nice and clean
let's make that a little more readable
now let's do plate
now we have some text
inside of our view using some styles
and using a constant
now we can also nest our text tags
right here do another text
actually if you don't mind i'm going to
take this and move this over to
visual code a little easier to code over
here
need the
constants
um
okay if i save this
our apps get updated
and our text is getting formatted all
right so let's add another text block
here
okay we now have a nested text
and let's use title text here
let's see so i've got title text
add some break points so if you want to
add
any special characters you need to make
sure you put them inside squarely braces
and by special characters i mean things
like new line
backlash n
we want to add two spaces between or two
line breaks between our
text
and do it like that we can also
type text directly into
uh our tag so we can do hello world
save and as you can see we can add it
directly in
so this works to allow us to create
static constant text that we can reuse
throughout our applications
uh and what's nice about the constants
is these can be defined at each
screen or each modal
module inside of our application or they
can be defined globally throughout the
application so we can actually have
static text to make buttons um common
throughout the application or we can
create custom components uh they get
reused
all right so we have inline text
actually let's just uh put that one back
add a break in there
cleaner
all right so now we have inline text we
have our constant text and we have a
really long text that wraps
now for this guy here i want to also add
the number
of line
ah here we go so when you hover over so
this is used to truncate the text with
ellipses after computing the text layout
so what would happen here is if it goes
down five lines so if i say equal to
let me set equal to one since we know it
wrap so if i save this
oh because the containers
right so if the number of lines exceeds
the container
then the text would be followed by
ellipsis dot dot dot
if it's not
our container is so big
the text just continues to get displayed
something else to consider
so
we have our container here so we have
our styles of our view but we can also
add styles to our text
so here we'll create a base text
attribute
and let's set our font so we can type in
font and you'll see the different font
attributes you can add so we're going to
start with font family and this allows
us to change the uh
font to
say time to roman arial courier
we'll do a function for this example
okay
so you can see that our text changed now
if i
delete that real quickly
oh i guess that's the default let's try
a different one let's try
earlier
it slightly changes
all right and then next let's change our
title text
and change its font size
and make it 20
and also let's change its font weight
to be both
all right so now we need to apply these
styles so we'll come up here and go to
our topper topmost
and actually let's wrap this whole thing
into
another text
i want to actually show you how the text
can act as a container
so if we have an outermost text
we can actually define
our base tag
at the parent level and then
this style will apply to all children of
this text text
so if we start here and we do style
and
we say equal to
styles dot
page text
save
and as you can see it has now applied
courier to all of our text
now if i just apply this
at this level
and save
oh that guy is inside of that one so
this guy
if we play at that level
it only applies to that tag so as you
can see it's nested so the
all the children of the parent tag will
inherit the styles of the parent
now that being said
if
an underlining style gets applied to a
child that overrides
or changes say for example the font
family then that
attribute is going to be what is applied
at that level and for any of its
children
so it's kind of a cool way where you can
actually define a common look and feel
at the beginning and then apply it to
custom tags so anytime you use your
custom tag or component
it will your look and feel of your app
will be the same
all right so let's finish this up let's
add the last
uh style here so let's do styles
dot inline
uh
title text
okay i got bolded not quite what we
wanted
oh yeah i separated one
this guy
will put outside of that
title text save
now
you can see that the title
is bold
and our text is final text
the reason it was uh
updating it before was because i
accidentally had put our body text
inside of our
title tag or pedal pitch tag
you
Transcript Segments
1.28

[Music]

27.039

all right guys welcome back so last time

29.599

we covered fundamental concepts of react

32.32

native and in this

34.8

section we're going to actually continue

36.64

our discussion on fundamental concepts

39.84

and actually get into

42.96

talking about the next component in our

45.36

list here the last time we covered views

48.64

scroll views and some other views uh for

51.92

building out our mobile applications for

54.32

android ios

56

using react native this time we're going

58.719

to focus on the text component here

61.92

which displays

63.52

our styles and nested strings of text

66.64

on our screen

68.159

on our mobile apps or on our web apps

71.2

now just a quick recap the text

73.68

component in react native is similar to

76.24

the text view

78

in android view

79.84

ue text view in ios view

82.799

and it's also equivalent to the p tag or

85.68

paragraph tag of html

89.84

so that's it for our slides we're going

91.28

to jump out and actually go back to our

93.52

code examples

99.2

again i'm going to be using visual

102

studio

103.6

and after looking at the

105.759

video from last time i noticed the text

107.759

was a little bit smaller so uh does this

110.479

look better to you guys today is it

112.399

clear

116.32

yes it looks really clear

118.64

excellent

119.68

all right so last time we looked at

121.84

things like safe area view which allows

124.719

us to uh not have to configure our

130

mobile app our container for different

132.64

devices uh for ios for instance it

135.84

actually covers uh removes our view

138.8

beneath the

140.8

header information on mobile app for

142.8

instance the little notch here

144.879

uh our little carrier information the

147.68

time and our battery

149.52

so using safe area view it puts our main

152.959

container beneath the mobile restricted

156.879

areas

157.92

however with android we had to actually

161.04

customize this so for that we switched

163.76

over to

165.28

our

165.959

snack.expo

167.84

to look at android

170.64

now in android

173.04

we couldn't use safe area view safe area

176.239

view is ios specific so what we did

179.36

instead was we came down here and

181.92

created a custom style using stylesheets

186.4

for a

188.239

graded a attribute called container

190.8

and we use the padding top

193.2

along with the platform

195.68

which we imported

197.28

the platform

198.959

class and the status bar class which

202.319

allows us to check to see if the ios is

206

android windows mac

209.28

mac os ios or web and in this case we

213.04

wanted to check for android and then we

215.519

use the status bar class to get the

218.4

status bar's current height and if it's

221.519

not

222.4

if this comes back as null we'll set it

224.56

as zero if this is if it does find a

228.48

status bar then it's going to return the

230.72

status bar height and use that

233.28

so if we're android it's going to use

235.28

the current height and it's going to

237.04

drop it down beneath the title

239.519

information or the status bar of our

242

device

243.68

we also looked at things like scroll

245.12

view which allows us to actually scroll

250.319

or set our view containers

254

we also looked at views

256.88

and each of these little components here

258.88

is a view

260.239

we have to put all of our context inside

263.12

of our views which will be looking at

264.639

that today so additional tags go inside

267.6

of views and views essentially help us

271.28

control the layout of our applications

274.08

now i'm still not getting into the more

276.4

complex layout designs of our mobile

278.24

apps yet we're still going to focus

280.16

primarily today on component

284.639

and we also talked about inline

287.6

versus

288.72

javascript object styles but we could

291.68

actually do an inline style using the

294.16

squiggly bracket

296.56

or double squiggly bracket to actually

298.479

define an inline style using the style

301.199

attribute

302.32

we could actually call or use the style

306.72

beat to create a javascript object

309.36

called styles

311.12

which we can then

312.479

call using style

314.639

and we can nest these together using the

317.039

array attribute inside of our squirrely

320.16

bracket

321.199

so in an inline style we had to use two

324.639

early brackets to define the array

327.759

however for

329.199

a styles object we have to use the array

332.96

container or the array block to define

335.759

our style containers so we have styles

338.72

using the style object and the container

342.16

now the inline style can also be added

344.479

to this array so we have our outer

347.36

curly brace we have our array

351.36

and then we have a inline style again

354.88

denoted by the curly brace for

357.12

background color blue and then we're

359.36

also combining it with a styles object

364.72

so that's just a quick recap of last

367.12

time does anyone have any questions on

369.52

what we did here before we move on to

371.6

today's

372.96

component

375.12

nope

385.28

make this get a little bit bigger

391.12

there we go

392.96

all right so the next topic we're going

394.639

to look at

395.759

is a text

398

so

399.6

in react

401.28

text or the text tag

404.56

is

406.72

so text is denoted by the text tag

412.56

view here

413.68

and it has to go inside of a container

416

view

417.12

of some kind

418.56

and it's the text

420.4

tag

422.96

now if we hover over text

425.199

um

427.039

import as text

429.36

back over here

431.599

one of these actually gave me the

434.639

a little

444.16

nope i guess not

446.88

one of the tools i was working with

449.36

actually was nice and it gives you the

451.039

definition of the tags as you work but i

453.599

might have that on another machine

456.4

so

457.36

just to briefly tell you what text is so

459.68

text

460.639

is a react component for displaying text

463.36

on your screen

464.879

so the text supports nesting styling and

468.24

touch handles

469.919

it also has an attribute for the number

473.36

of lines so if we want to create like a

475.199

text area

477.199

of text where we have multiple lines of

478.879

text we can use the attribute number of

481.52

lines

482.479

so for instance if we want to define a

485.039

static text reference we can

488.16

do something like this

489.919

so we can go up here and we can

493.599

import

499.52

so if we want to use something

501.12

statically we have to import what is

503.68

called use state

508.639

from react

520.479

and what this state does is it now

523.039

allows us to define a constant and store

526.24

it into

527.68

basically into static memory

530.64

now if we use a constant

534.399

let's say we do a title

537.36

text

539.04

ray so there's our label

541.839

our

543.12

basically our

544.64

key to reference our title

547.12

we're going to call set or create a

550

variable set title

555.839

text

558

this is going to equal use state

566.88

and we'll say hello world

569.839

okay since this is the

573.279

title

574.399

we will just do sample app

580.88

now you don't need to save this uh like

583.04

i just did but um it's just a fourth of

585.36

habit when i write code i save

587.44

and then we'll define another constant

589.279

here and we will call this one

593.44

body text

599.839

and this one is just going to be a

601.279

straight up

602.839

variable and we're going to use state

612.8

and some really long text here

632.56

okay so we now have a constant defined

635.92

in a

637.36

kind of an array map so we have a key

639.44

value pair

641.36

and we can also define a constant

643.04

straight up with the constant

645.6

variable name and use the state

651.36

now what's nice about this is we can

653.6

come down here

655.12

and inside of our text here

657.279

i can actually put

660.24

using the early braces

664.72

body

665.76

text

668.72

and as you can see we've now added our

671.68

constant text here our static text

674

inside of our text or inside of our view

676.56

here

678.399

what's nice that allows us to define

681.68

text directly we can also add text

685.2

directly into the container so let me

689.04

clean up this view here

693.44

let's get rid of the other views for now

698.399

and just pick with the one view

704.88

and let's make this view a little bit

706.72

taller so let's say

710.079

1000

712.8

a little bit to 500

717.2

there we go

718.399

and we'll increase the width to say 300.

724.399

right

727.04

so far so good

728.639

nice and clean

730.639

let's make that a little more readable

732.16

now let's do plate

737.12

now we have some text

739.44

inside of our view using some styles

742.56

and using a constant

750.88

now we can also nest our text tags

760.079

right here do another text

767.519

actually if you don't mind i'm going to

770.639

take this and move this over to

774.56

visual code a little easier to code over

776.88

here

786

need the

791.44

constants

802.079

um

818.8

okay if i save this

820.959

our apps get updated

824

and our text is getting formatted all

826.32

right so let's add another text block

828.32

here

835.44

okay we now have a nested text

840.16

and let's use title text here

853.6

let's see so i've got title text

859.44

add some break points so if you want to

862.16

add

863.839

any special characters you need to make

866.56

sure you put them inside squarely braces

869.279

and by special characters i mean things

870.959

like new line

873.36

backlash n

876.16

we want to add two spaces between or two

878.72

line breaks between our

881.199

text

882.48

and do it like that we can also

885.279

type text directly into

887.6

uh our tag so we can do hello world

892.399

save and as you can see we can add it

895.12

directly in

899.76

so this works to allow us to create

902.079

static constant text that we can reuse

905.04

throughout our applications

906.959

uh and what's nice about the constants

909.199

is these can be defined at each

913.12

screen or each modal

916.24

module inside of our application or they

918.959

can be defined globally throughout the

921.279

application so we can actually have

923.04

static text to make buttons um common

926.399

throughout the application or we can

927.839

create custom components uh they get

930.24

reused

931.759

all right so we have inline text

933.519

actually let's just uh put that one back

937.199

add a break in there

941.6

cleaner

943.279

all right so now we have inline text we

945.279

have our constant text and we have a

947.68

really long text that wraps

952.079

now for this guy here i want to also add

956.32

the number

958.48

of line

962.32

ah here we go so when you hover over so

964.639

this is used to truncate the text with

966.8

ellipses after computing the text layout

969.759

so what would happen here is if it goes

973.04

down five lines so if i say equal to

977.68

let me set equal to one since we know it

979.759

wrap so if i save this

987.199

oh because the containers

989.199

right so if the number of lines exceeds

993.12

the container

995.12

then the text would be followed by

996.959

ellipsis dot dot dot

999.36

if it's not

1001.6

our container is so big

1003.92

the text just continues to get displayed

1011.12

something else to consider

1013.199

so

1014.24

we have our container here so we have

1016

our styles of our view but we can also

1018.56

add styles to our text

1020.88

so here we'll create a base text

1024.64

attribute

1030.799

and let's set our font so we can type in

1033.919

font and you'll see the different font

1036.4

attributes you can add so we're going to

1038.88

start with font family and this allows

1041.6

us to change the uh

1043.839

font to

1045.439

say time to roman arial courier

1049.52

we'll do a function for this example

1054.08

okay

1056.559

so you can see that our text changed now

1059.6

if i

1061.12

delete that real quickly

1066.32

oh i guess that's the default let's try

1068.48

a different one let's try

1072.559

earlier

1076.72

it slightly changes

1084.32

all right and then next let's change our

1087.52

title text

1095.36

and change its font size

1098.72

and make it 20

1102.64

and also let's change its font weight

1108.559

to be both

1120.16

all right so now we need to apply these

1122.16

styles so we'll come up here and go to

1125.44

our topper topmost

1129.12

and actually let's wrap this whole thing

1131.6

into

1132.559

another text

1145.84

i want to actually show you how the text

1148.799

can act as a container

1151.2

so if we have an outermost text

1154.32

we can actually define

1156.24

our base tag

1158.24

at the parent level and then

1161.44

this style will apply to all children of

1165.52

this text text

1166.96

so if we start here and we do style

1171.6

and

1172.24

we say equal to

1176.84

styles dot

1178.799

page text

1180.559

save

1181.6

and as you can see it has now applied

1183.76

courier to all of our text

1186.799

now if i just apply this

1192.48

at this level

1195.039

and save

1200.64

oh that guy is inside of that one so

1208

this guy

1208.88

if we play at that level

1211.36

it only applies to that tag so as you

1214.64

can see it's nested so the

1217.52

all the children of the parent tag will

1220.24

inherit the styles of the parent

1223.44

now that being said

1225.12

if

1225.919

an underlining style gets applied to a

1228.4

child that overrides

1231.52

or changes say for example the font

1233.919

family then that

1236.88

attribute is going to be what is applied

1239.039

at that level and for any of its

1241.12

children

1242.799

so it's kind of a cool way where you can

1244.32

actually define a common look and feel

1247.76

at the beginning and then apply it to

1250.4

custom tags so anytime you use your

1252.559

custom tag or component

1255.52

it will your look and feel of your app

1257.12

will be the same

1260.48

all right so let's finish this up let's

1262.559

add the last

1264.559

uh style here so let's do styles

1272.559

dot inline

1276.96

uh

1279.52

title text

1288.48

okay i got bolded not quite what we

1290.799

wanted

1311.52

oh yeah i separated one

1315.2

this guy

1316.48

will put outside of that

1325.2

title text save

1327.84

now

1329.12

you can see that the title

1331.36

is bold

1332.48

and our text is final text

1335.679

the reason it was uh

1337.919

updating it before was because i

1339.6

accidentally had put our body text

1342.4

inside of our

1344.48

title tag or pedal pitch tag

1363.039

you