📺 Develpreneur YouTube Episode

Video + transcript

React Native Fundamentals - Part 8

2021-10-19 •Youtube

Detailed Notes

React-Native Fundamental Concepts focuses on: Images, Background Image, layout and events

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]
and for this example let's
look at a layout strategy where we can
define the width and
the locations of our buttons
again we'll do a separator
and here we'll do view
and first we want our text
again we want our styles
um
and this one is going to be
example 4
layout
but
there it is
now this time instead of just adding our
buttons let's add an additional view so
that we can control where our buttons go
we'll do another view
and this one we're going to use a
new
style that we'll create in a second so
we'll do
style
bits to text
and you add future fix to text
and here we're going to do flex
direction
this time we're going to keep it on the
row
and we will justify our context
and we'll do the space
between
what this will do is it will let us
it will pad
between the
components that we add to this
go inside of review
we're going to add two buttons
two
but one is going to have text
title
it's going to be left button
in on press
now again do an alert
and this time we will display the
message left button clicked
and inside of our second button
we will
name it right button
and use healer right button click
so here's our layout
the
justify context padding space between
fills
uh
the
gap between each button so the left
button is pushed to the left and the
other button is added to the right
now if we added a third it would
simply be in the middle
and now when we click these there's your
left button
middle button
and right button
all right so that is an example of how
to use buttons
any questions on
how you use the button component
okay hearing none we'll move on to the
last component for the day
and that is going to be the touchable
opacity
add that one here
obesity
and the touchable opacity component is a
wrapper for making views respond
properly to touches
these touches can be on press down
and when you push down the opacity of
the wrap view is decreased dimming
opacity is controlled by wrapping the
children in an animated view
which is added to the view hierarchy
however be aware that this can affect
the layout
so for this example let's add
do you use static
or use state
component
oops
okay
oh
had to be on a separate line
all right so we're going to use the use
state
feature to allow us to actually store
a value
dynamically so that we can reference the
state of a constant value
from anywhere within our application
so we've added our import here
the other components we need are going
to be
our style sheet
text
view
and touchable
opacity
right
clean up
previous example
all
right so in this case we want to define
our constant within our application
but here we will define it within
the function
so we'll do constant
create a variable called count
and we will use the method set
count
and we will use state
of zero
now
we're also going to do constant
on press
we're going to call set count
use previous count
so previous count is going to be our
value that we pass into
our set count
to use it we're going to use previous
count
this one
okay now inside of our return we need to
add a view
but to add our style
container
all right inside of our view
let's add another view
and we will create a new style for this
one
and inside of this view we're going to
display the text
count
and we're going to reference our static
variable
we need some attributes down here so
let's
add a
count
container
let's add align items
let's center it
and let's add some padding
and add 10 pixels for padding
let's also add an attribute over here
for a button
add some styling for a button
and our button
will be centered so we will also align
items
center
color
let's make it gray
and also add some padding
and add 10 pixels
so we got styles
container
and there's our account
we have our text now we need our button
so now instead of button we're going to
use our touchable opacity
now this guy has a wrapper
or
instead of title to display text you add
text
it will add our text press here
now for our touchable opacity let's add
our style
i have a button style
and let's also do our on press
and set it equal to our on press
constant
okay so we have our button now
if we press this guy
as you can see the button kind of fades
out between click and our account goes
up
and that's how you use touchable opacity
any questions on how to use this guy
nope
all right
so before i wrap up are there any
questions at all any of the components
we have covered today
i don't think we
one one question uh is this mainly
uh i mean in order to be good in this
you have to be very
very good at css
and html
uh not so much html remember these are
components so it's xml tag driven
uh and
the styling is css like so you just have
to
look at the libraries that are out there
if you go to react native
if we go out to react native if you go
to the docs
uh like components for instance
a click button here are all the
attributes and things that you can apply
to buttons
okay gotcha
and then there are other properties that
you can look up like image style
properties layout properties
i mean there are tons of these so
really
if you're using something like code or
you're using the expo the moment you get
in here and you start typing
or you can do control space and then
here all the different attributes that
you can apply
okay got it okay cool so they really
simplify because if you do control space
inside of visual code if you have the
plug-in install there's all your
styling like uh attributes that you can
add
okay
just gotta look for little blue boxes
anything below the blue boxes now you're
getting into actual
um
like this here is so these are
components
styling these are text stylings
these are functional stylings
it's kind of cool how
visual code works
expo isn't quite as clean like this but
again you can do like the control space
in expo and it will give you a list of
components
gotcha okay
and michael you're self-taught on this
here isn't it
yes
this is react native is very similar to
an older
tool i used to use called
titanium
alloy and it was very tag driven like
this and it really looks like react
native borrowed a lot from
their
framework
uh because i was able to take one of our
older applications that me and rob
worked on and almost
directly drop it in with a few tweaks to
make it work in react native
okay
all right to quickly review today we
talked about the
final uh component or components
of react native we looked at using the
image component to add local
image resources as well as network
uh
images into our application
when importing images or using the image
component you need to remember that
unless your image is local you have to
set the styling components for setting
the size of your image
image background is a good tag to use
when doing with splash pages when you
want to just put your image to be the
full size of the screen
and finally we looked at using the
button tag
and the touchable opacity tags
to handle wrapping of our buttons to
where we can actually interact and click
to do some type of action on our pages
i'd like to thank you for your time if
you would like to discuss any of these
topics further you can send us questions
comments and suggestions through any of
these methods you can reach us at email
at info developer.com
you can go to our developer.com site and
go to the contact us page
you can see these videos on youtube and
vimeo uh we're on vimeo at vimeo.com
developmenter and youtube we're at www
forward slash channel forward slash u c
z
o
u f n underscore l h c v v d y
p two k ks
iph underscore d
our goal is making every developer
better have a great day
you
Transcript Segments
0.46

[Music]

28.08

and for this example let's

31.279

look at a layout strategy where we can

34.399

define the width and

37.04

the locations of our buttons

39.6

again we'll do a separator

46

and here we'll do view

57.52

and first we want our text

64.799

again we want our styles

82

um

86.88

and this one is going to be

89.92

example 4

93.92

layout

96.64

but

100.079

there it is

103.52

now this time instead of just adding our

106.88

buttons let's add an additional view so

110.799

that we can control where our buttons go

113.92

we'll do another view

119.6

and this one we're going to use a

122

new

124.079

style that we'll create in a second so

126.88

we'll do

128.56

style

134.64

bits to text

138.879

and you add future fix to text

144.72

and here we're going to do flex

147.92

direction

150.64

this time we're going to keep it on the

152.319

row

156.8

and we will justify our context

163.04

and we'll do the space

169.599

between

171.519

what this will do is it will let us

175.04

it will pad

177.599

between the

178.879

components that we add to this

183.599

go inside of review

185.599

we're going to add two buttons

197.68

two

200.239

but one is going to have text

208.08

title

211.519

it's going to be left button

216.08

in on press

227.04

now again do an alert

233.599

and this time we will display the

235.599

message left button clicked

243.76

and inside of our second button

247.28

we will

248.959

name it right button

252.4

and use healer right button click

257.6

so here's our layout

259.28

the

261.12

justify context padding space between

264.56

fills

265.68

uh

266.639

the

268.4

gap between each button so the left

270.96

button is pushed to the left and the

273.04

other button is added to the right

275.44

now if we added a third it would

282.32

simply be in the middle

291.68

and now when we click these there's your

293.44

left button

295.44

middle button

297.12

and right button

302.32

all right so that is an example of how

304.639

to use buttons

306.479

any questions on

308.72

how you use the button component

321.6

okay hearing none we'll move on to the

323.919

last component for the day

326.4

and that is going to be the touchable

328.56

opacity

331.919

add that one here

340

obesity

342

and the touchable opacity component is a

344.96

wrapper for making views respond

347.199

properly to touches

349.759

these touches can be on press down

352.96

and when you push down the opacity of

355.84

the wrap view is decreased dimming

359.759

opacity is controlled by wrapping the

361.84

children in an animated view

364.96

which is added to the view hierarchy

367.68

however be aware that this can affect

370.08

the layout

373.28

so for this example let's add

379.44

do you use static

383.52

or use state

385.6

component

387.28

oops

389.6

okay

405.68

oh

408.96

had to be on a separate line

415.52

all right so we're going to use the use

417.52

state

418.4

feature to allow us to actually store

421.28

a value

423.36

dynamically so that we can reference the

425.44

state of a constant value

428.08

from anywhere within our application

430.479

so we've added our import here

433.759

the other components we need are going

435.68

to be

436.4

our style sheet

439.199

text

440.88

view

441.84

and touchable

446.72

opacity

451.52

right

454.88

clean up

456.4

previous example

462.08

all

462.84

right so in this case we want to define

466.08

our constant within our application

468.56

but here we will define it within

471.68

the function

472.879

so we'll do constant

478.24

create a variable called count

481.52

and we will use the method set

484.319

count

487.36

and we will use state

490.879

of zero

496.479

now

497.28

we're also going to do constant

500.8

on press

510.4

we're going to call set count

516.719

use previous count

527.68

so previous count is going to be our

531.04

value that we pass into

533.279

our set count

535.76

to use it we're going to use previous

537.6

count

543.839

this one

553.04

okay now inside of our return we need to

555.36

add a view

562.8

but to add our style

569.44

container

578.959

all right inside of our view

585.519

let's add another view

595.76

and we will create a new style for this

597.92

one

602.72

and inside of this view we're going to

604.399

display the text

607.76

count

610.72

and we're going to reference our static

613.44

variable

618.88

we need some attributes down here so

620.959

let's

622.079

add a

627.36

count

628.88

container

634.399

let's add align items

638.8

let's center it

641.839

and let's add some padding

645.279

and add 10 pixels for padding

649.68

let's also add an attribute over here

651.839

for a button

655.36

add some styling for a button

658.8

and our button

662.24

will be centered so we will also align

666.48

items

670.64

center

676.88

color

682

let's make it gray

687.2

and also add some padding

692.399

and add 10 pixels

697.68

so we got styles

701.279

container

710.24

and there's our account

714.24

we have our text now we need our button

730.079

so now instead of button we're going to

732.56

use our touchable opacity

739.839

now this guy has a wrapper

742.56

or

743.68

instead of title to display text you add

746.399

text

752.24

it will add our text press here

756.639

now for our touchable opacity let's add

760

our style

770.399

i have a button style

773.36

and let's also do our on press

778.639

and set it equal to our on press

784.72

constant

790.32

okay so we have our button now

792.72

if we press this guy

794.639

as you can see the button kind of fades

796.399

out between click and our account goes

798.639

up

806.079

and that's how you use touchable opacity

809.44

any questions on how to use this guy

814.959

nope

819.36

all right

829.199

so before i wrap up are there any

831.519

questions at all any of the components

833.519

we have covered today

840.079

i don't think we

841.279

one one question uh is this mainly

843.92

uh i mean in order to be good in this

845.92

you have to be very

848.399

very good at css

851.44

and html

853.519

uh not so much html remember these are

856.079

components so it's xml tag driven

860.079

uh and

861.519

the styling is css like so you just have

864.639

to

865.44

look at the libraries that are out there

869.36

if you go to react native

882.24

if we go out to react native if you go

884.72

to the docs

886.399

uh like components for instance

889.6

a click button here are all the

891.6

attributes and things that you can apply

894

to buttons

895.839

okay gotcha

897.6

and then there are other properties that

899.199

you can look up like image style

901.279

properties layout properties

903.92

i mean there are tons of these so

906.88

really

909.279

if you're using something like code or

911.44

you're using the expo the moment you get

914

in here and you start typing

918.16

or you can do control space and then

920.32

here all the different attributes that

922.16

you can apply

926.24

okay got it okay cool so they really

928.72

simplify because if you do control space

930.959

inside of visual code if you have the

932.639

plug-in install there's all your

934.959

styling like uh attributes that you can

937.92

add

939.279

okay

941.199

just gotta look for little blue boxes

943.44

anything below the blue boxes now you're

945.68

getting into actual

947.759

um

949.839

like this here is so these are

951.519

components

952.72

styling these are text stylings

956

these are functional stylings

959.36

it's kind of cool how

960.959

visual code works

962.639

expo isn't quite as clean like this but

966.88

again you can do like the control space

968.88

in expo and it will give you a list of

971.36

components

974.32

gotcha okay

976.24

and michael you're self-taught on this

978

here isn't it

979.199

yes

980.399

this is react native is very similar to

982.639

an older

983.759

tool i used to use called

985.68

titanium

987.44

alloy and it was very tag driven like

989.759

this and it really looks like react

992

native borrowed a lot from

994.88

their

995.68

framework

996.88

uh because i was able to take one of our

1000.079

older applications that me and rob

1001.68

worked on and almost

1003.759

directly drop it in with a few tweaks to

1006.48

make it work in react native

1011.04

okay

1016.959

all right to quickly review today we

1019.12

talked about the

1020.56

final uh component or components

1023.6

of react native we looked at using the

1026.319

image component to add local

1030.079

image resources as well as network

1033.039

uh

1033.919

images into our application

1037.12

when importing images or using the image

1039.839

component you need to remember that

1042.24

unless your image is local you have to

1045.439

set the styling components for setting

1048.24

the size of your image

1051.039

image background is a good tag to use

1054.4

when doing with splash pages when you

1056.32

want to just put your image to be the

1059.12

full size of the screen

1060.88

and finally we looked at using the

1062.559

button tag

1063.84

and the touchable opacity tags

1066.72

to handle wrapping of our buttons to

1069.6

where we can actually interact and click

1072

to do some type of action on our pages

1078.16

i'd like to thank you for your time if

1080.32

you would like to discuss any of these

1081.84

topics further you can send us questions

1084.4

comments and suggestions through any of

1086.48

these methods you can reach us at email

1089.44

at info developer.com

1091.919

you can go to our developer.com site and

1095.28

go to the contact us page

1097.36

you can see these videos on youtube and

1100.16

vimeo uh we're on vimeo at vimeo.com

1103.76

developmenter and youtube we're at www

1109.6

forward slash channel forward slash u c

1112.96

z

1113.84

o

1114.64

u f n underscore l h c v v d y

1120.24

p two k ks

1122.48

iph underscore d

1125.919

our goal is making every developer

1127.52

better have a great day

1146

you