📺 Develpreneur YouTube Episode

Video + transcript

React Native Fundamentals - Part2

2021-09-28 •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]
does anyone have any questions on the
views
uh or scroll view areas
just real quick just to
reiterate now you you've used this to
cross um numerous platforms and it it
functions the same across like for
example uh
like android versus uh ios stuff
yeah so
so here's the thing since i can't get
android to work locally let me copy this
edge
let me go back over here
so if i paste this code in here
tap play
make sure this works
oh
bear with me
going off script for a moment
okay
oh um again forget
this is kind of cool it um this is also
how you can debug your application so
when you try to run it it will tell you
when you're missing imports
there we go
all right so here's ios
hey take a second here
so
you
there we go
all right so yeah good point so the safe
area view
only works for ios does not work on
android if you notice it's
covered by the status bar here
it kind of jumped ahead on me a little
bit but i'll go ahead and i'll address
this here that's okay
uh
that was just it's it's one of those
that
it is it's it's interesting how powerful
uh react native is when you look at
you know the variants in the devices so
all right cool i didn't mean that didn't
mean to steal your thunder but since you
opened it up for questions so
i'll go quiet and let you return thanks
oh no no that's fine um and because of
time i think i'm going to go ahead and
uh
cover that because
we're actually
i'm not on 11 um 30 already
so i may not cover all the components
today
all right so
what we're going to do now is so in
order to
create a custom style or handle the
status bar here for android what we're
going to do is we're going to create a
style
down here so this is this type of style
here is an inline style so that's where
you're actually putting the style at the
component
uh useful for testing not useful for
overall maintenance if you want to reuse
this style for other buttons views
and so on so what you can do is you can
create a
[Music]
you can actually create a javascript
object for styles now i'll get in to
more about the overall styles in a
moment but uh or possibly next time
given time constraints here but what i'm
going to do here though is i'm going to
show you how you can actually uh
add a custom style that will handle this
for android so in our container here
we will uh need to import
a few things one i need to import
a module called platform
and i need let's see
status
bar
so status bar will return you and all
the information about the status bar
that is
on your device and platform allows you
to get the platform information for the
device that is running so then here
under container we will add
uh padding for the top of our
application
we will use the platform object
or the platform module
we will use the os property
and three equals for comparison
and we're going to check for android
and here what's interesting uh how rant
native does this
what they do is uh they allow you to do
in line uh conditions so you do
essentially an inline if so if this
condition
is true the question mark here will
return
uh if it's true it will return the first
value
which is going to be our status bar
dot
current height
otherwise we'll return zero
all right so let me go over that again
so here i've created a
style for padding top
checking the platform
operating system is equal to
android now if you notice if i hover
over os here you this will also be
visible in visual code as well but the
different properties you can look for is
ios android windows mac or web
now
status bar dot current height will give
you the
current height of the status bar on the
device
and if it's uh not found it will return
or if we're not on android it will
return zero
now to apply this style we'll come up
here to our safe view
and we will add
dial
equals
now because we're going to be calling a
javascript object we do not need to
do double curly braces instead we need
to call our stylesheet or our styles
object here
dot container
and as you can see our status or view
is now handled cleanly
uh on android
now if i take this exact same code here
and let me put this individual
code
you'll see it also does not impact
ios ios is using the safe area view
and android is using our custom style
here
to get the status bar header and to
shift it down
does that answer your question rob
yes yes
cool
but since we're
kind of tight on time let me just go
over some additional style sheet
information
and
next class i will pick up with the
components and we'll go through the rest
of them
unfortunately we lost time because of
the uh zoom
yeah issue we had
no biggie all right so
i've introduced the inline style here
i've talked about that
and
you can also define and pass a
javascript object
here
for our styles
but what are style sheets you know what
is this actual style sheet well with
react native you style your application
using javascript so the core components
accept a prop a property name style
this little style here so all
every component in react native has a
style attribute
and the style names and values usually
match
how css worked on the web
however
these names are not the same as css they
are similar
so rather than background dash color we
use
background color no dash no hyphen
so the style prop can be a plain old
java object now that's what we usually
use for example
code you can also pass an array of
styles
where the last style in the array has
the pers
basically the order present so the last
style will
inherit all the previous styles
also as the components grow in
complexity it is often cleaner to use
style sheets here stylesheet.create to
create
several different styles in one place
making it easier to
maintain and configure your applications
now again these are not css they are
javascript properties
we can do it in line
like here using the style background
color
type
or we can do it with styles create we
could have a container
and say
body
say this one to be our background color
so here if we wanted to
[Music]
and
you
mentioned
so what we can do is we can do
styles.container
we can add a comma and then do stuff
dial
dot
body
that works
now you can also
put them inside of an array
that works as well
the documentation recommends doing it
this way using the array bracket
the hard bracket
but it also works without so i don't
know if it's just uh
if it pertains to maybe one
device or another
so the recommended approach used to add
the uh square bracket
around your array
now you can also even include these
inside
of
an actual style here
what we'll do here is
take this
now
this is going to be cool so here's a
shortcut for visual code
on it there we go
so if you
uh
hold
band and b
oh
there we go all right so if you select
a tag here
so say we want to change
this view tag to
say scroll view
if you hold
on windows and do control d or on mac
you do command d after highlighting it
it will allow you to update
both the beginning and the ending tag
so you could type once and it updates
both tags
unfortunately it doesn't quite work for
styles the way i hoped it would but what
we can do here is we can do styles
body
styles dot
few dimensions
all right so what i did here is i
combined
my styles
so you can actually combine inline
styles with style objects as well
so
given time that's pretty much
all we're going to be able to get to
today so we looked at
the different scrolling view areas we
looked at safe area view we looked at
scroll view
and we looked at view
we also looked at some of the different
style options you have where you can use
inline styles to set your background
color the dimensions the height the
width we also looked at using the
platform
and the status bar modules to get the
height of our status bar
to actually set our starting point
within our view so that our view
is not overlapped by the status bar
so does anyone have any additional
questions
not at this time i don't at least
dave any questions
okay hearing none
so today we covered the core components
of view safe view and scroll view and we
also looked at some of the different
styling effects or styling ways you can
actually modify the styles of components
i'd like to thank you for your time
if you'd like to discuss any of these
topics further you can reach us at email
info developer.com
you can reach us on the web at
developernerd.com contact us
we have our youtube channel
the link for that is here and we're also
on vimeo our goal is making every
developer better have a great day
you
Transcript Segments
0.46

[Music]

28.64

does anyone have any questions on the

30.64

views

31.679

uh or scroll view areas

37.76

just real quick just to

40.239

reiterate now you you've used this to

42

cross um numerous platforms and it it

45.84

functions the same across like for

47.68

example uh

49.12

like android versus uh ios stuff

52.239

yeah so

53.6

so here's the thing since i can't get

55.199

android to work locally let me copy this

60.96

edge

63.44

let me go back over here

66.08

so if i paste this code in here

75.84

tap play

80.4

make sure this works

86

oh

91.119

bear with me

96.4

going off script for a moment

107.68

okay

108.72

oh um again forget

122.079

this is kind of cool it um this is also

124.88

how you can debug your application so

127.04

when you try to run it it will tell you

129.119

when you're missing imports

133.52

there we go

134.72

all right so here's ios

139.84

hey take a second here

196.48

so

211.84

you

250

there we go

251.2

all right so yeah good point so the safe

254.959

area view

256.239

only works for ios does not work on

259.68

android if you notice it's

261.519

covered by the status bar here

266.08

it kind of jumped ahead on me a little

267.52

bit but i'll go ahead and i'll address

268.8

this here that's okay

270.479

uh

271.52

that was just it's it's one of those

273.04

that

273.84

it is it's it's interesting how powerful

276.16

uh react native is when you look at

278.56

you know the variants in the devices so

280.88

all right cool i didn't mean that didn't

282.24

mean to steal your thunder but since you

283.52

opened it up for questions so

285.44

i'll go quiet and let you return thanks

287.199

oh no no that's fine um and because of

289.68

time i think i'm going to go ahead and

292

uh

293.12

cover that because

295.12

we're actually

297.6

i'm not on 11 um 30 already

300.24

so i may not cover all the components

302

today

303.12

all right so

305.28

what we're going to do now is so in

307.36

order to

309.44

create a custom style or handle the

312.08

status bar here for android what we're

315.44

going to do is we're going to create a

317.28

style

319.36

down here so this is this type of style

322.4

here is an inline style so that's where

324.16

you're actually putting the style at the

325.919

component

327.12

uh useful for testing not useful for

329.84

overall maintenance if you want to reuse

331.6

this style for other buttons views

334.8

and so on so what you can do is you can

337.039

create a

337.89

[Music]

342.4

you can actually create a javascript

344.639

object for styles now i'll get in to

347.759

more about the overall styles in a

349.68

moment but uh or possibly next time

352.72

given time constraints here but what i'm

354.88

going to do here though is i'm going to

356.319

show you how you can actually uh

359.919

add a custom style that will handle this

362.639

for android so in our container here

367.919

we will uh need to import

371.12

a few things one i need to import

374.4

a module called platform

378.24

and i need let's see

384.479

status

388.24

bar

389.36

so status bar will return you and all

392.4

the information about the status bar

394.319

that is

395.919

on your device and platform allows you

398.8

to get the platform information for the

401.039

device that is running so then here

403.919

under container we will add

406.479

uh padding for the top of our

410.56

application

413.039

we will use the platform object

416.319

or the platform module

419.039

we will use the os property

423.12

and three equals for comparison

427.44

and we're going to check for android

433.599

and here what's interesting uh how rant

437.28

native does this

439.36

what they do is uh they allow you to do

442.72

in line uh conditions so you do

446.24

essentially an inline if so if this

449.28

condition

450.4

is true the question mark here will

452.72

return

453.759

uh if it's true it will return the first

456.319

value

457.44

which is going to be our status bar

460.88

dot

462.08

current height

464.72

otherwise we'll return zero

472.8

all right so let me go over that again

474.4

so here i've created a

476.84

style for padding top

479.52

checking the platform

481.68

operating system is equal to

484.4

android now if you notice if i hover

486.4

over os here you this will also be

488.4

visible in visual code as well but the

490.879

different properties you can look for is

493.12

ios android windows mac or web

499.759

now

500.8

status bar dot current height will give

503.039

you the

504.56

current height of the status bar on the

507.44

device

508.72

and if it's uh not found it will return

512.24

or if we're not on android it will

513.919

return zero

516.32

now to apply this style we'll come up

518.64

here to our safe view

522.159

and we will add

525.2

dial

528.56

equals

533.36

now because we're going to be calling a

535.36

javascript object we do not need to

538.88

do double curly braces instead we need

542.16

to call our stylesheet or our styles

544.64

object here

548

dot container

552.399

and as you can see our status or view

556.32

is now handled cleanly

558.959

uh on android

560.64

now if i take this exact same code here

567.76

and let me put this individual

572.16

code

575.2

you'll see it also does not impact

578.88

ios ios is using the safe area view

583.2

and android is using our custom style

585.839

here

587.36

to get the status bar header and to

590.72

shift it down

594.959

does that answer your question rob

599.6

yes yes

602.32

cool

610.56

but since we're

612.88

kind of tight on time let me just go

614.88

over some additional style sheet

616.48

information

617.6

and

618.64

next class i will pick up with the

620.32

components and we'll go through the rest

621.76

of them

623.2

unfortunately we lost time because of

624.8

the uh zoom

626.88

yeah issue we had

629.04

no biggie all right so

631.68

i've introduced the inline style here

634.16

i've talked about that

635.6

and

637.44

you can also define and pass a

640

javascript object

641.839

here

643.36

for our styles

646.079

but what are style sheets you know what

647.92

is this actual style sheet well with

650.16

react native you style your application

652.72

using javascript so the core components

655.44

accept a prop a property name style

661.76

this little style here so all

664.48

every component in react native has a

666.8

style attribute

671.519

and the style names and values usually

674.64

match

675.76

how css worked on the web

678.399

however

679.519

these names are not the same as css they

682.88

are similar

684.48

so rather than background dash color we

687.76

use

688.64

background color no dash no hyphen

692.16

so the style prop can be a plain old

695.519

java object now that's what we usually

698.88

use for example

700.839

code you can also pass an array of

703.44

styles

704.72

where the last style in the array has

707.519

the pers

708.64

basically the order present so the last

710.48

style will

712.8

inherit all the previous styles

716.16

also as the components grow in

718.16

complexity it is often cleaner to use

720.639

style sheets here stylesheet.create to

723.6

create

724.72

several different styles in one place

726.959

making it easier to

729.12

maintain and configure your applications

732.88

now again these are not css they are

735.12

javascript properties

737.12

we can do it in line

739.279

like here using the style background

741.519

color

742.56

type

744.399

or we can do it with styles create we

747.76

could have a container

752.88

and say

758.48

body

761.6

say this one to be our background color

777.2

so here if we wanted to

790.99

[Music]

799.68

and

801.6

you

802.639

mentioned

813.2

so what we can do is we can do

815.279

styles.container

818.32

we can add a comma and then do stuff

822.48

dial

824.959

dot

825.839

body

830.8

that works

832.639

now you can also

834.959

put them inside of an array

838.32

that works as well

841.44

the documentation recommends doing it

843.44

this way using the array bracket

846.72

the hard bracket

848.959

but it also works without so i don't

851.36

know if it's just uh

856.959

if it pertains to maybe one

859.44

device or another

861.04

so the recommended approach used to add

864.16

the uh square bracket

866.48

around your array

870.16

now you can also even include these

872.72

inside

874

of

875.36

an actual style here

877.36

what we'll do here is

879.12

take this

888.56

now

889.36

this is going to be cool so here's a

891.519

shortcut for visual code

894.56

on it there we go

896.32

so if you

901.199

uh

903.839

hold

906.24

band and b

919.04

oh

926.639

there we go all right so if you select

929.12

a tag here

930.72

so say we want to change

932.72

this view tag to

935.12

say scroll view

936.72

if you hold

937.92

on windows and do control d or on mac

940.56

you do command d after highlighting it

943.04

it will allow you to update

945.36

both the beginning and the ending tag

948.88

so you could type once and it updates

951.279

both tags

952.8

unfortunately it doesn't quite work for

954.399

styles the way i hoped it would but what

957.279

we can do here is we can do styles

966.399

body

968.959

styles dot

971.6

few dimensions

1014.56

all right so what i did here is i

1016.399

combined

1018.399

my styles

1022.8

so you can actually combine inline

1024.72

styles with style objects as well

1032.48

so

1034.72

given time that's pretty much

1037.199

all we're going to be able to get to

1038.48

today so we looked at

1042

the different scrolling view areas we

1044.959

looked at safe area view we looked at

1047.199

scroll view

1048.559

and we looked at view

1050.16

we also looked at some of the different

1051.679

style options you have where you can use

1054.32

inline styles to set your background

1056

color the dimensions the height the

1058.24

width we also looked at using the

1062.559

platform

1064.24

and the status bar modules to get the

1066.88

height of our status bar

1069.039

to actually set our starting point

1071.52

within our view so that our view

1074.16

is not overlapped by the status bar

1079.6

so does anyone have any additional

1081.76

questions

1087.52

not at this time i don't at least

1092.88

dave any questions

1101.6

okay hearing none

1104.4

so today we covered the core components

1108.08

of view safe view and scroll view and we

1111.52

also looked at some of the different

1114

styling effects or styling ways you can

1116.88

actually modify the styles of components

1122

i'd like to thank you for your time

1124.24

if you'd like to discuss any of these

1125.76

topics further you can reach us at email

1129.12

info developer.com

1131.36

you can reach us on the web at

1132.76

developernerd.com contact us

1135.52

we have our youtube channel

1137.76

the link for that is here and we're also

1139.919

on vimeo our goal is making every

1142.4

developer better have a great day

1162

you