📺 Develpreneur YouTube Episode

Video + transcript

React Native Fundamentals Part 7

2021-10-14 •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]
now we can modify our image of course so
we can apply things like we did before
we could do things like stretch
so let's have a resizemode cover we
could do stretch
it doesn't change too much we could also
change our container
adding 50
and we can also change the flux
direction
change that
we continue to be column based
so now it covers the entire width of
page
if we did row
that looks identical
so that's an example of using
our image background
this is kind of a way you can do your
splash screen so you want to make sure
that the image you use can resize and
fit the area that you want
now we could use our local
image
sample image
and we could use our
fire
that says
icon
okay
you could set your source you could
define a constant for local
uh we just have to include the
additional pieces
all right let's pin for
our image background
all right next let's look at using
buttons
so
a button
is a basic component that should render
nicely on any platform
it supports a minimal level of
customization and if the button doesn't
look right for your application you can
build your own button using the
touchable
opacity or the touchable without
feedback
we're going to look at using button and
then we're also going to look at using
touchable opacity
the button syntax looks something like
this
button
that button is wrapped in a single tag
and it has a couple of
attributes so we have on press
we have title
we have color
and we have accessibility
accessibility
and then on press you can want to call
some function
your title is going to be your text
and your color can be
for instance the actual
default
white
you can use the name of your color or
you could use the hex value
and then the accessibility label is
going to be
your uh the text
that goes
over it to learn more
we could be learn more
right so that's the kind of look and
feel
of our button
let's start and actually create
a new example with using the button and
the alerts
and we want to use the alert
component
so in our imports we should have style
sheets we should have button we should
have alert
we should also have stylesheet text and
view
all right so in our view so instead of
using view this time
also add
we are
presenting
ios today
let's do this safe area view
and the safe area view is that tag that
allows us to
create a view
that does not overlap the header of our
device so this little notch here it will
start our view just below the knot
it will also start on the ipad or
devices without the notch just below the
top information the
date time the little battery
icon
okay so inside of here
inside of our safe area view
let's add a
placeholder styles
container
place those
right so we have our container
our container is going to be flex 1
we don't need to pad it
let's set our
let's justify our context
be centered
and let's set our margins
our horizontal margins
to be 16 pixels
okay everything's happy so far
all right instead of our safe area view
let's add another view so that we can
actually
add some containers within our container
all right inside of our view
let's add
text let's add a text
component
let's set its style
and the text we will display will be
example
one
now for our button
we need to define our title this will be
the text that gets displayed
and our title will be press me
and the function call we will use is on
press
and we're going to use an inline
function
to call the alert component
an alert is like deal like a javascript
alert in web
and here we'll do alert
alert
and this will be a simple pop-up box
and the text will display will be simple
right
because we didn't add style yet so let's
add some style for our title
and let's set the texture line
the center
and let's set its vertical margins
to be eight
style here to be styles
title
there we go so we have our view
we have our text example one
and we have a button called press me
and if we click the button
we get an alert simple button pressed
all right so let's expand on this
so now let's create another button and
this time let's adjust the color in a
way that looks standard on each platform
so on ios the color prop controls
the color of the text
on android the color adjusts the
background color of the button
so on ios if you adjust the color it
will adjust the text color and on
android it will be the actual button
color itself
now this time though
i'm going to keep this button here but
i'm going to show you how to create a
divider between your views
both create a separate
constant
and we're going to call this one
separator
so in this sense we're going to create a
custom view
that we're going to then embed into our
screen here
we have an inline function
and then inside of our function here
we will do view
style
equal
styles
and we need to create a separator style
and then we need to close our view
now we'll come down here and we will add
a style
now let's
add a separator
attribute
style
and in here we'll set the vertical
margin
to 8.
we'll set our border color or border
bottom color
to kind of an off-white
and we will use the border bottom width
and here
we're going to use these styles
the spell t component
and we're going to use one of its
predefined attributes called hairline
width
right so we have our constant here which
is just a
view component so we created a custom
view component
and now to use this
this is one of those cool things where
now
all we have to do is
call
or create our component
separator
and there's our horizontal line
so now let's add our second
example but
let's do another view
and inside of here we're going to do
another text box
another text component
we use the style
use our title style again
and this time our text will be example
two
okay so far so good
now let's add our button
more buttons
are inline so we want to add our
attributes here so we'll add our title
and we'll add our on press
and we'll use alert
and button color or button with
adjusted
color
our title will be press me
and let's
modify the color of the button
color
equals
and here again we can use the
x code
or we can just use
one of the predefined values so here we
have a red button
and when we click it
we get the alert button with adjusted
color pressed
now what if you want to create another
button
but it is disabled until some action
triggers it to be enabled
so to create a
new
button
create a new separator
create another view
and text
and we're going to use our style
and this text will be example three
again we're going to do another button
this time we have our title
we have our on press
let's go ahead and add an alert
now here's something that's interesting
so i went ahead and saved this
now we see example three but we do not
see our button displayed at this point
because we did not set a title
essentially you have a button that is
hidden
now
you can click it you can't see it but
it's
hidden so we can set the title of this
one
press me
okay there it is
and so far we can still press it it says
cannot press this one
that's because we have not added the
last attribute which is disabled
and if we
save
it gets grayed out
this is one of those neat little
features you can add where you can add
some on-screen validation as you're
entering in a form
that until all the required fields are
populated this button can essentially be
disabled once everything is filled out
passes validation then this button
becomes enabled
okay let's do one more example
[Music]
you
Transcript Segments
0.46

[Music]

26.48

now we can modify our image of course so

29.76

we can apply things like we did before

31.599

we could do things like stretch

34.32

so let's have a resizemode cover we

36.399

could do stretch

39.92

it doesn't change too much we could also

42.64

change our container

45.92

adding 50

49.28

and we can also change the flux

51.36

direction

54.48

change that

57.52

we continue to be column based

63.92

so now it covers the entire width of

66.32

page

67.92

if we did row

72.799

that looks identical

85.119

so that's an example of using

88.4

our image background

90.64

this is kind of a way you can do your

92.479

splash screen so you want to make sure

94.64

that the image you use can resize and

98.079

fit the area that you want

100.4

now we could use our local

104.88

image

110.96

sample image

113.6

and we could use our

118.64

fire

139.76

that says

144.319

icon

150.72

okay

168.08

you could set your source you could

169.599

define a constant for local

171.84

uh we just have to include the

173.92

additional pieces

176.4

all right let's pin for

178.879

our image background

184

all right next let's look at using

185.92

buttons

187.599

so

188.72

a button

189.92

is a basic component that should render

192.72

nicely on any platform

194.8

it supports a minimal level of

196.48

customization and if the button doesn't

199.04

look right for your application you can

202.159

build your own button using the

204.64

touchable

206.159

opacity or the touchable without

208.48

feedback

209.599

we're going to look at using button and

211.599

then we're also going to look at using

213.36

touchable opacity

215.68

the button syntax looks something like

217.68

this

219.92

button

223.76

that button is wrapped in a single tag

228.159

and it has a couple of

232.48

attributes so we have on press

234.879

we have title

237.76

we have color

241.519

and we have accessibility

247.92

accessibility

261.919

and then on press you can want to call

263.919

some function

276.08

your title is going to be your text

278.8

and your color can be

280.639

for instance the actual

283.52

default

284.56

white

286

you can use the name of your color or

287.759

you could use the hex value

295.68

and then the accessibility label is

297.84

going to be

299.36

your uh the text

301.919

that goes

303.44

over it to learn more

305.44

we could be learn more

311.199

right so that's the kind of look and

313.12

feel

314.08

of our button

315.84

let's start and actually create

318.8

a new example with using the button and

322.24

the alerts

324.96

and we want to use the alert

327.36

component

331.199

so in our imports we should have style

333.44

sheets we should have button we should

335.12

have alert

338.32

we should also have stylesheet text and

341.28

view

344

all right so in our view so instead of

346.32

using view this time

349.199

also add

352.32

we are

353.759

presenting

356.639

ios today

358.24

let's do this safe area view

363.12

and the safe area view is that tag that

366.08

allows us to

370.24

create a view

371.68

that does not overlap the header of our

374.8

device so this little notch here it will

377.759

start our view just below the knot

380.479

it will also start on the ipad or

382.639

devices without the notch just below the

386.479

top information the

388.8

date time the little battery

391.44

icon

395.12

okay so inside of here

397.919

inside of our safe area view

401.28

let's add a

403.52

placeholder styles

407.039

container

419.52

place those

420.88

right so we have our container

423.52

our container is going to be flex 1

426.24

we don't need to pad it

431.759

let's set our

434.56

let's justify our context

437.919

be centered

442.56

and let's set our margins

446.16

our horizontal margins

448.08

to be 16 pixels

451.84

okay everything's happy so far

457.199

all right instead of our safe area view

458.88

let's add another view so that we can

460.96

actually

463.36

add some containers within our container

468.08

all right inside of our view

469.919

let's add

471.68

text let's add a text

474.24

component

476

let's set its style

482

and the text we will display will be

484.639

example

486

one

489.36

now for our button

496.319

we need to define our title this will be

498.96

the text that gets displayed

501.44

and our title will be press me

507.759

and the function call we will use is on

510.319

press

516.32

and we're going to use an inline

518.56

function

521.599

to call the alert component

525.44

an alert is like deal like a javascript

527.839

alert in web

529.68

and here we'll do alert

532

alert

533.6

and this will be a simple pop-up box

536.8

and the text will display will be simple

541.279

right

549.519

because we didn't add style yet so let's

553.12

add some style for our title

558.399

and let's set the texture line

561.12

the center

566.959

and let's set its vertical margins

571.92

to be eight

576.64

style here to be styles

580.08

title

589.12

there we go so we have our view

591.92

we have our text example one

594.64

and we have a button called press me

597.76

and if we click the button

599.519

we get an alert simple button pressed

609.2

all right so let's expand on this

611.36

so now let's create another button and

614

this time let's adjust the color in a

616.399

way that looks standard on each platform

619.12

so on ios the color prop controls

623.2

the color of the text

625.2

on android the color adjusts the

627.6

background color of the button

630.399

so on ios if you adjust the color it

632.72

will adjust the text color and on

635.12

android it will be the actual button

637.279

color itself

641.2

now this time though

643.279

i'm going to keep this button here but

645.76

i'm going to show you how to create a

648.24

divider between your views

650.72

both create a separate

654.72

constant

660

and we're going to call this one

661.76

separator

664

so in this sense we're going to create a

667.04

custom view

670.079

that we're going to then embed into our

673.36

screen here

674.72

we have an inline function

682.64

and then inside of our function here

686.32

we will do view

689.04

style

690.399

equal

696.56

styles

699.68

and we need to create a separator style

706

and then we need to close our view

710.079

now we'll come down here and we will add

712.24

a style

716.48

now let's

717.44

add a separator

720.079

attribute

721.6

style

723.68

and in here we'll set the vertical

725.6

margin

727.6

to 8.

730.72

we'll set our border color or border

733.2

bottom color

738.88

to kind of an off-white

743.76

and we will use the border bottom width

757.36

and here

758.72

we're going to use these styles

761.76

the spell t component

764.32

and we're going to use one of its

765.519

predefined attributes called hairline

768.88

width

775.2

right so we have our constant here which

777.279

is just a

778.88

view component so we created a custom

781.2

view component

783.519

and now to use this

785.6

this is one of those cool things where

787.839

now

788.72

all we have to do is

790.56

call

791.519

or create our component

794.16

separator

796.16

and there's our horizontal line

802.8

so now let's add our second

804.8

example but

806.32

let's do another view

809.92

and inside of here we're going to do

812.079

another text box

815.12

another text component

818.24

we use the style

827.44

use our title style again

830.959

and this time our text will be example

833.92

two

838.959

okay so far so good

841.68

now let's add our button

846.56

more buttons

848.56

are inline so we want to add our

851.04

attributes here so we'll add our title

856.399

and we'll add our on press

867.36

and we'll use alert

876.56

and button color or button with

880.16

adjusted

881.68

color

889.6

our title will be press me

894

and let's

895.6

modify the color of the button

899.12

color

901.839

equals

903.36

and here again we can use the

906

x code

907.199

or we can just use

909.839

one of the predefined values so here we

912.72

have a red button

914.959

and when we click it

916.399

we get the alert button with adjusted

918.72

color pressed

925.6

now what if you want to create another

927.92

button

928.88

but it is disabled until some action

932.8

triggers it to be enabled

934.959

so to create a

936.959

new

938.32

button

939.199

create a new separator

946.079

create another view

956.079

and text

968.48

and we're going to use our style

981.199

and this text will be example three

990

again we're going to do another button

996.399

this time we have our title

1000.56

we have our on press

1009.279

let's go ahead and add an alert

1029.52

now here's something that's interesting

1031.12

so i went ahead and saved this

1033.36

now we see example three but we do not

1036.16

see our button displayed at this point

1038.079

because we did not set a title

1040.959

essentially you have a button that is

1042.88

hidden

1047.12

now

1047.919

you can click it you can't see it but

1049.84

it's

1050.84

hidden so we can set the title of this

1053.52

one

1055.6

press me

1059.039

okay there it is

1060.72

and so far we can still press it it says

1063.2

cannot press this one

1065.039

that's because we have not added the

1066.96

last attribute which is disabled

1070.4

and if we

1071.52

save

1072.559

it gets grayed out

1074.32

this is one of those neat little

1075.84

features you can add where you can add

1077.52

some on-screen validation as you're

1080.08

entering in a form

1081.84

that until all the required fields are

1084.88

populated this button can essentially be

1087.36

disabled once everything is filled out

1089.76

passes validation then this button

1092

becomes enabled

1098

okay let's do one more example

1101.53

[Music]

1117.039

you