📺 Develpreneur YouTube Episode

Video + transcript

React Native Fundamentals Part 6

2021-10-12 •Youtube

Detailed Notes

In our third video on React Native: The Beginners Guide to React-Native Fundamental Concepts Part 3, continues our discussion of fundamental components. Previously, we covered mobile design, layout, and text components. Now we are going to cover some new components, such as buttons, images, and background images.

Just in case you missed the last video you can find it here or you need a refresher you can find the first video Started Using React Native For Your Mobile Applications here.

React-Native Fundamental Concepts Part 3 focuses on: Image Image Background Button

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

Image An Image React component is useful when you want to display different types of images, including network images, static resources, temporary local images, and images from local disk, such as the camera roll. However, if you are dealing with network and data images, you will need to manually specify the dimensions of your image. Otherwise, they may not render correctly in the application. ImageBackground Another common feature is ImageBackground. Of course if you are familiar with developing web applications then this one will remind you of a similar web element, background-image. Just like its web counter part, you can use the ImageBackground component to display an image to the background layer of your mobile app. It also has the same props as Image, and you can add whatever children to it you would like to layer on top of it. Unfortunately, you might not want to use ImageBackground in all cases, as the implementation is basic. For instance all you can really do is customize some width and height style attributes. If you need a more complex background image I would recommend using the Image component. Button Most of us are accustom to what a button is, ever heard the saying "Push the Button". In the case of mobile development the basic button component is what we use for displaying buttons and it should render nicely on any platform. It also, Supports a minimal level of customization. So, if this button doesn't look right for your app, you can build your own button using TouchableOpacity or TouchableWithoutFeedback. TouchableOpacity TouchableOpacity is a wrapper for making views respond properly to touches. On press down, the opacity of the wrapping view is decreased, dimming it. Opacity is controlled by wrapping the children in an Animated.View, which is added to the view hierarchy. Be aware that this can affect layout. React-Native Fundamental Concepts Part 3

Additional Resources React is an open-source, front end, JavaScript library for building user interfaces or UI components. In addition, Facebook and a community of individual developers and companies help maintain it. React can be useful as a base in the development of single-page or mobile applications. Node.js is an open-source, cross-platform, back-end JavaScript runtime environment that runs on Chrome V8 engine and executes JavaScript code outside a web browser. Visual Studio Code is a free source-code editor made by Microsoft for Windows, Linux and macOS. In addition it includes support for debugging, syntax highlighting, intelligent code completion, snippets, code refactoring, and embedded Git. Android software development is the process by which applications are created for devices running the Android operating system. Xcode is Apple's integrated development environment for macOS and is used to develop software for macOS, iOS, iPadOS, watchOS, and tvOS.

This series comes from our mentoring/mastermind classes.  These classes are virtual meetings that focus on how to improve our technical skills and build our businesses.  After all the goals of each member vary.  However, this diversity makes for great discussions and a ton of educational value every time we meet.  We hope you enjoy viewing this series as much as we enjoy creating it.  As always, this may not be all new to you, but we hope it helps you be a better developer.

Other Classes, You Might Consider: Integrating testing into your development flow Become a Better Developer Build A Product Catalog

Launching an Internet Business

Transcript Text
[Music]
all right so today we are going to wrap
up our discussion on react native uh
talking about the fundamental concepts
in react native
now before we get into today's lesson
again i'd like to recap what react
native is
it is an open source mobile application
framework created by facebook and is
used to develop applications for android
android tv ios mac os and others as well
it can also be used for web development
windows and uwp by enabling developers
to use react frameworks along with the
native platform capabilities
so the concepts we're going to talk
about today
are going to be the image and the button
component
now let's give you a quick comparison
between react android ios and web
in react native we're going to use the
image tag
on android you would use the image view
on ios you would use the ui image view
web we use the image tag img
and that these tags are essentially used
to display different types of images on
the screen on our app
on our web pages
if we want to use button
for react native
it's pretty much a button on all of the
different frameworks except for ios ios
requires you to use the ui button
which again the button is used to
display a clickable button
let's get started with our hands-on demo
so like before this is going to be a
fairly interactive um
presentation we're going to spend a lot
of our time
just
typing through examples and looking and
seeing how these components interact and
work
right now my android
emulator is currently broken still on
ios because i have the new arm
m1
macbooks and there's still a slight bug
in my development environment for
android
so for now we're just going to use an
ipad and an iphone 12
emulator to see how
deploying our applications or as we
code our applications we can see
real-time updates on different devices
so the first element we're going to talk
about today is the image
and in react
it is a
essentially the image tag
img
capital image
is a react component for displaying
different types of images including
network images static references
temporary local images and images from
the local disk such as the camera rule
now in this example i'm going to show
you how to fetch and display an image
from your local storage as well as from
one from your network
so
let's start with
our view
everything that was here was
pre-generated by
expo
so we start with our view and then we
need to add some images
to our view so we will start with the
image
option
image requires a source
we need to tell it where to find the
image
and inside of our source
if we're looking for an image locally
we use require
and to look for an image that is on your
device or on your machine while you're
testing
you come over here and you find your
path so we have our assets folder here
and inside of assets we have some static
images
so to access that we start with the root
path dot
assets
and let's do have
icon
now it failed because it did not import
our image so we need to make sure that
we import our image tag
and there's our image
now let's
add some styles
uh actually before we add styles let's
go get an image off the network
so let's go out to the web
browser
to use
microsoft edge
and let's go to developer.com
and let's take our banner image up here
so we will copy our link to our image
right there
so as you can see in html the image tag
uses the srt or source attribute to look
up the image on the web and we're just
essentially doing something similar in
react native so here we will do image
source
equals
again
on this time we don't need to use uh
require this time we're actually going
to use
the ui
uri attribute
and the uri attribute just takes a
texturing of your
image
okay
save that
nothing is displayed
so here is a slight tip if you're
pulling images locally
you don't need to set any attributes for
displaying the image it's going to take
the actual properties of the image
if you import the image from the web uh
from a web resource you have to actually
define the source to find this
so we're going to do this a couple
different ways so let's
copy this again
just create a second one
and let's create some styles and apply
to each of these three images
so again i want to note that for network
and data images you need to manually
specify the dimensions of your image
and to do that we just come down to our
style sheets section here
and we're going to add some additional
style attributes
but first let's create one for alt image
and this we're just going to set the
default
of our image
to be width of 50 pixels
and a height
of 50.
okay
set this guy up to be 50
we applied the style so if i take the
image and i come up here to our first
one
and we do style
equals
image
oops style document
there we go
now let's add a
second attribute for our
first developer
image that we're going to import
and this we're going to call small image
oops
image we're going to do 66 and 58
and then small image is actually going
to be
50 50.
all right
now let's create a another one for large
image
and this one we're going to set the
width to be full screen so 100
and we'll set the height to be 200
and we'll also create one additional
style property called pretty image
this one is going to use the resize
mode
of scratch
all right so we applied image to our
first image
we used small image
a little bit smaller we did large image
that bigger
okay so let's go back to just image
like that
the what's one
yeah adding here so that it's not at the
top
now the reason i'm adding top padding
here is because i am not using the
uh
container safe
uh view
i'm using just view
this view is compatible with all devices
whereas if we use the
ios view it
comes down from the header of our ios
app so we miss out on the notch the time
but that may break or it gets ignored
when we deal with the android devices
next let's add some
imaging to our developer our first one
so we'll copy our style here
and let's also add style to our third
one here
so this first one
we're going to do large
image
and for the moment we'll leave this guy
blank
so if we see save you see we now have
our image
looks pretty good on the ipad looks
pretty crappy on the ios device
and if you notice we still don't have
our third image because we did not
specify the style for it yet
and so the last one we want is going to
be stretchy image
and a little bit better it looks a
little distorted on the ios but at least
now we can see everything
in our image
so you can use the require
to pull the image from the local device
or you can use the attribute uri
to pull from a url
right the second one we're going to look
at today
actually before i move on does anyone
have any questions on
using images
yeah i'm good
okay
all right so the next example we're
going to look at is going to use the
image background
now this is a common feature request
from developers familiar with web in
using
images on the web now to handle this use
case you can use the image background
button
tag
component which has the same properties
as image
and whatever child you add to it will
appear on top of it as a top layer
now you might not want to use the image
background
in some cases since the implementation
is basic
so
typically you're going to use image for
most of your image displaying through
your mobile applications your web
image background is a good
uh
little uh tag to use when you're dealing
with like splash screens or loading
screens where you want to have an image
behind but have some text or something
displayed in front of it
so for this one let's take our url here
let's take our source
and actually turn this into a constant
so we'll come up here
and we'll create a constant
called the belt
image
okay
this way i don't have to copy and paste
the url all over the place
let's clean up our view so we'll get rid
of
our previous example
save that
review
so good
also going to
reset
our style sheet here
all right so inside of our view
let's
let's go ahead and add our image
background so if we do image
now we need to make sure that it's added
in our imports it is we have image
background
and just like image it has source
and because we defined
our uri here as a constant we can just
reference development image
and now we need to add some style
and close our tab
yeah happy because we don't have an
image attribute yet
let's go add one so image
and so here we're going to use flex
1
we're going to use resize mode
of cover
and we're going to
set
our justify context
to be center
oh yep
sorry image background is not a single
close tag
it is a wrapper tag so we have to
actually close
our tag
and let's add
something inside of here so we can
actually see that
let's actually add a text
and just add some simple text
now let's add some style to our text
and let's add a text
attribute to our
style
set our text color
let's go ahead and set it to white
let's paint our font size
v42
off weight
make it bold
let's align it to the center
and let's set its background color
is semi-transparent
there we go
all right so
here's our image
using background image and here's our
text inside of our hand
you
Transcript Segments
0.42

[Music]

27.119

all right so today we are going to wrap

29.92

up our discussion on react native uh

33.12

talking about the fundamental concepts

35.76

in react native

37.28

now before we get into today's lesson

39.92

again i'd like to recap what react

41.68

native is

43.04

it is an open source mobile application

45.44

framework created by facebook and is

48

used to develop applications for android

50.64

android tv ios mac os and others as well

55.36

it can also be used for web development

57.68

windows and uwp by enabling developers

61.44

to use react frameworks along with the

63.52

native platform capabilities

69.76

so the concepts we're going to talk

71.2

about today

72.4

are going to be the image and the button

76.24

component

77.6

now let's give you a quick comparison

79.52

between react android ios and web

83.439

in react native we're going to use the

86.32

image tag

88.08

on android you would use the image view

91.6

on ios you would use the ui image view

95.52

web we use the image tag img

99.28

and that these tags are essentially used

101.52

to display different types of images on

103.92

the screen on our app

107.2

on our web pages

108.88

if we want to use button

110.56

for react native

112.32

it's pretty much a button on all of the

115.2

different frameworks except for ios ios

118.479

requires you to use the ui button

121.439

which again the button is used to

123.84

display a clickable button

131.44

let's get started with our hands-on demo

136.8

so like before this is going to be a

139.2

fairly interactive um

142.08

presentation we're going to spend a lot

143.68

of our time

144.879

just

146

typing through examples and looking and

148.879

seeing how these components interact and

150.879

work

167.599

right now my android

169.68

emulator is currently broken still on

172.4

ios because i have the new arm

175.84

m1

177.12

macbooks and there's still a slight bug

179.599

in my development environment for

181.2

android

182.4

so for now we're just going to use an

184.64

ipad and an iphone 12

187.519

emulator to see how

190.159

deploying our applications or as we

192.879

code our applications we can see

194.56

real-time updates on different devices

200.64

so the first element we're going to talk

202.4

about today is the image

205.28

and in react

206.959

it is a

208.959

essentially the image tag

214.64

img

217.2

capital image

218.959

is a react component for displaying

222.159

different types of images including

224.48

network images static references

227.599

temporary local images and images from

230.56

the local disk such as the camera rule

234

now in this example i'm going to show

235.84

you how to fetch and display an image

238.159

from your local storage as well as from

240.799

one from your network

242.799

so

243.519

let's start with

245.76

our view

251.04

everything that was here was

252.239

pre-generated by

254.56

expo

257.359

so we start with our view and then we

259.359

need to add some images

261.199

to our view so we will start with the

263.44

image

267.36

option

271.44

image requires a source

277.52

we need to tell it where to find the

279.36

image

285.759

and inside of our source

287.84

if we're looking for an image locally

290.8

we use require

296.56

and to look for an image that is on your

300.24

device or on your machine while you're

302.32

testing

303.52

you come over here and you find your

305.84

path so we have our assets folder here

308.8

and inside of assets we have some static

312.32

images

313.36

so to access that we start with the root

316

path dot

318.8

assets

321.759

and let's do have

324.8

icon

330.88

now it failed because it did not import

334.56

our image so we need to make sure that

336.08

we import our image tag

339.68

and there's our image

344.72

now let's

346.479

add some styles

348.08

uh actually before we add styles let's

350.16

go get an image off the network

352.96

so let's go out to the web

361.36

browser

363.199

to use

364.4

microsoft edge

371.12

and let's go to developer.com

375.12

and let's take our banner image up here

378

so we will copy our link to our image

395.44

right there

397.28

so as you can see in html the image tag

400.72

uses the srt or source attribute to look

404.639

up the image on the web and we're just

406.88

essentially doing something similar in

409.36

react native so here we will do image

414.56

source

420

equals

424.4

again

429.36

on this time we don't need to use uh

432.08

require this time we're actually going

434.4

to use

435.759

the ui

437.68

uri attribute

440.72

and the uri attribute just takes a

442.96

texturing of your

446.319

image

448.88

okay

451.599

save that

455.12

nothing is displayed

456.96

so here is a slight tip if you're

459.599

pulling images locally

462

you don't need to set any attributes for

464.8

displaying the image it's going to take

467.199

the actual properties of the image

470.319

if you import the image from the web uh

474.56

from a web resource you have to actually

476.639

define the source to find this

479.52

so we're going to do this a couple

480.8

different ways so let's

482.319

copy this again

484.879

just create a second one

489.84

and let's create some styles and apply

492.24

to each of these three images

498.639

so again i want to note that for network

501.759

and data images you need to manually

504.24

specify the dimensions of your image

506.8

and to do that we just come down to our

508.479

style sheets section here

510.4

and we're going to add some additional

512.719

style attributes

514.479

but first let's create one for alt image

518.159

and this we're just going to set the

519.519

default

520.64

of our image

522.32

to be width of 50 pixels

526.64

and a height

528.64

of 50.

534.64

okay

535.6

set this guy up to be 50

537.839

we applied the style so if i take the

540.48

image and i come up here to our first

542.959

one

543.92

and we do style

546.88

equals

551.839

image

552.8

oops style document

560.24

there we go

563.279

now let's add a

565.76

second attribute for our

568

first developer

570

image that we're going to import

571.839

and this we're going to call small image

582.32

oops

584

image we're going to do 66 and 58

588

and then small image is actually going

590.16

to be

591.04

50 50.

598.32

all right

599.279

now let's create a another one for large

602.8

image

609.92

and this one we're going to set the

611.68

width to be full screen so 100

616

and we'll set the height to be 200

620.959

and we'll also create one additional

623.92

style property called pretty image

636.56

this one is going to use the resize

639.76

mode

642.88

of scratch

648.24

all right so we applied image to our

650.399

first image

651.92

we used small image

655.279

a little bit smaller we did large image

664.72

that bigger

667.36

okay so let's go back to just image

670.56

like that

674.48

the what's one

678.959

yeah adding here so that it's not at the

681.36

top

682.959

now the reason i'm adding top padding

685.12

here is because i am not using the

688.64

uh

690

container safe

692.24

uh view

694.8

i'm using just view

696.64

this view is compatible with all devices

699.519

whereas if we use the

701.519

ios view it

704.079

comes down from the header of our ios

706.399

app so we miss out on the notch the time

709.6

but that may break or it gets ignored

712.399

when we deal with the android devices

715.68

next let's add some

717.68

imaging to our developer our first one

721.279

so we'll copy our style here

727.36

and let's also add style to our third

729.839

one here

730.8

so this first one

732.959

we're going to do large

735.76

image

742.24

and for the moment we'll leave this guy

743.92

blank

745.2

so if we see save you see we now have

747.76

our image

750.56

looks pretty good on the ipad looks

752.959

pretty crappy on the ios device

758.72

and if you notice we still don't have

760.399

our third image because we did not

762.24

specify the style for it yet

764.959

and so the last one we want is going to

766.56

be stretchy image

771.44

and a little bit better it looks a

774

little distorted on the ios but at least

776.48

now we can see everything

778.399

in our image

782.959

so you can use the require

785.2

to pull the image from the local device

789.76

or you can use the attribute uri

793.519

to pull from a url

801.68

right the second one we're going to look

803.36

at today

804.639

actually before i move on does anyone

806.24

have any questions on

807.92

using images

809.6

yeah i'm good

811.2

okay

812.24

all right so the next example we're

813.92

going to look at is going to use the

815.92

image background

817.76

now this is a common feature request

820

from developers familiar with web in

823.92

using

825.279

images on the web now to handle this use

828.079

case you can use the image background

830.959

button

838.399

tag

840.56

component which has the same properties

843.04

as image

844.639

and whatever child you add to it will

848.079

appear on top of it as a top layer

851.519

now you might not want to use the image

853.36

background

854.72

in some cases since the implementation

857.36

is basic

858.8

so

860.48

typically you're going to use image for

863.199

most of your image displaying through

865.279

your mobile applications your web

867.76

image background is a good

870.399

uh

871.199

little uh tag to use when you're dealing

873.76

with like splash screens or loading

875.68

screens where you want to have an image

877.279

behind but have some text or something

879.519

displayed in front of it

881.76

so for this one let's take our url here

886.32

let's take our source

888.24

and actually turn this into a constant

894.72

so we'll come up here

896.399

and we'll create a constant

898.639

called the belt

901.68

image

908.079

okay

909.199

this way i don't have to copy and paste

910.88

the url all over the place

915.279

let's clean up our view so we'll get rid

917.279

of

918.959

our previous example

920.88

save that

922.72

review

924.079

so good

926.48

also going to

928.399

reset

930.639

our style sheet here

933.04

all right so inside of our view

936.079

let's

937.839

let's go ahead and add our image

939.759

background so if we do image

944.8

now we need to make sure that it's added

946.8

in our imports it is we have image

949.519

background

951.199

and just like image it has source

955.04

and because we defined

957.199

our uri here as a constant we can just

960.32

reference development image

963.199

and now we need to add some style

978.079

and close our tab

981.44

yeah happy because we don't have an

983.519

image attribute yet

985.759

let's go add one so image

988.72

and so here we're going to use flex

993.6

1

994.72

we're going to use resize mode

999.44

of cover

1003.279

and we're going to

1004.639

set

1005.6

our justify context

1009.04

to be center

1013.6

oh yep

1015.36

sorry image background is not a single

1018.32

close tag

1019.68

it is a wrapper tag so we have to

1021.68

actually close

1023.519

our tag

1026.16

and let's add

1028.079

something inside of here so we can

1030

actually see that

1034.079

let's actually add a text

1038.4

and just add some simple text

1049.12

now let's add some style to our text

1071.36

and let's add a text

1073.76

attribute to our

1075.919

style

1077.2

set our text color

1079.52

let's go ahead and set it to white

1083.6

let's paint our font size

1088.08

v42

1091.679

off weight

1095.44

make it bold

1102.96

let's align it to the center

1110.08

and let's set its background color

1113.039

is semi-transparent

1125.6

there we go

1127.28

all right so

1129.2

here's our image

1131.36

using background image and here's our

1133.679

text inside of our hand

1150.88

you