SlideShare une entreprise Scribd logo
1  sur  60
Télécharger pour lire hors ligne
Kobkrit Viriyayudhakorn, Ph.D.
CEO of iApp Technology Limited.
kobkrit@gmail.com
http://www.kobkrit.com
All source code
• https://github.com/kobkrit/react-native-class-2017
BMI Calculator App
Making BMI Calculator App
1. Draw UI on Paper
2. Initial project using react-
native
1. $|> react-native
init bmi
3. Making UI
4. Making Styles
5. Adding User Input Handling
6. Compute and Output
Draft on Paper
Making UI
1. Create container that fill
whole screen
2. Set the flexDirection of
container to ‘column’ and its

justifyContent: ‘center’
3. Start Adding Elements
1. Text
2. TextInput
3. TouchableOpacity
Draft on Paper
Using view to group each items.
Keyboard Types (Cross-Platform)
<TextInput keyboardType=‘default’>
default
numeric email-address
phone-pad
iOS (9.3)
Keyboard Types (Cross-Platform)
<TextInput keyboardType=‘default’>
default
numeric email-address
phone-padAndroid (6.0)
More Keyboard Types (iOS only)
<TextInput keyboardType=‘default’>
ascii-capable
numbers-punctuation number-pad
url
More Keyboard Types (iOS only)
<TextInput keyboardType=‘default’>
name-phone-pad
twitter web-search
decimal-pad
More TextInput Attribute
<TextInput
keyboardType=‘email-address’
autoCaptialize=‘none’
autoCorrect={false}
maxLength={30}
multiline={false}
placeholder=‘Please insert e-mail’
returnKeyType=‘next’
/>
https://facebook.github.io/react-native/docs/textinput.html
Cmd-K to Open/Hide Keyboard
Password TextInput
<TextInput
keyboardType=‘default’
secureTextEntry={true}
…

/>
iOS -> Cmd-K to Open/Hide Keyboard
Add User Input Feedback
Enable JS Debugger
Cmd - D
(iOS)


Menu Button

(Android)
State
• State is a JavaScript Object that we use to track
and response to users’ inputs.
• Each React component has its own instance of
state.
• Most important thing about state:
• Any change in state will cause all components
or any children components inside of it to be re-
rendered.
State’s Rule of Thumb
• When using state in component, always set the
initialize state to the reasonable values.
• Always use
this.setState(changedObjects)instead of
this.state.changedObject = someValue
• If not using this.setState(), React something
will not acknowledge the changes. Components
will not be re-rendered.
• Some strange behavior will happen in the app.
Initialize State
• We first defined 3 variables in state at the class’s constructor
• weight (String) = ‘0’ - It is a string because we use it with TextInput.
• height (String) = ‘0’ - It is a string because we use it with TextInput.
• and calculated bmi (Number) = 0
Showing/Setting State in
TextInput
• value attribute - setting the text according to the state.weight’s 

value
• onChangeText attribute - invoked when user making change the

TextInput, apply the new input value into the state.
See State in Action
• To see state working in action, Print the state value in render()
• Run the application.
• Typing some number into Weight (KG) and then Typing some
number into Height (CM) and see the difference.
At start, Weight (KG) = 0, 

according to the weight

state’s value.
Console in React Native Debugger

will print the state’s content, only when

the text in Weight(KG) is changed, because

the state make the component re-render.
Continue on Height
TextInput
Let’s compute the BMI
Method Binding
• Refresh the app now, input some
number, and push compute button.
You will see the red screen.
• It is because compute() method
is not the standard method in the
component class (We added it by
our own).
• The scope of compute() method
is not yet visible to the class’s state.
Method Binding
• You can bind the scope, by using bind()
statement.
• The best place to bind the method is at the class
constructor.
Showing the output
Full Source Code# 1
Full Source Code #2
Full Source Code #3
Exercise 1
• Showing the obesity level under the BMI number.
• BMI > 32 = Obese
• 25 < BMI < 32 = Over Weight
• 18.5 < BMI < 25 = Normal Weight
• BMI < 18.5 = Under Weight
Making Stopwatch App!
1. Draw UI on Paper
2. Initial project using react-
native
1. $|> react-native
init stopwatch
3. Making UI
4. Adding Style
5. Adding Logic
Initialize State
Showing the timeElapse
Handle Start Button Pressed
Minutes-Second-
Milliseconds Time Format
• Press Start Button
• TimeElapsed in milliseconds is displayed.
• We need to format TimeElapsed to
00:00.00 format, We have a library for that.
• Go to terminal at the working directory
• >|$ npm install minutes-
seconds-milliseconds --save
Minutes-Second-
Milliseconds Time Format
UI Separation
• We need to make the Stop button first. (Only start is
showing now)
• It is a good idea to seperate the start/stop button UI from
the main render method, since the main render method is
very long (hard to read, and hard to maintenance)
Add startButton, stopButton style
startStopButton method
Using startStopButton method
Don’t forget the method binding
Making Timer Stop
Working Start/Stop Timer App
Making Lap Function Works!
• Every time when user press the lap button, record
the current timeElapsed into this.state.lap
and reset the startTime
• Make the lower half of the app’s screen showing
the list of timeElapsed in this.state.lap array.
Implement handleLapPress
Lap Button UI Separation
render method
Display the Lap Array
See the difference
With the UI separation
Without
Full Source Code# 1
Full Source Code# 2
Full Source Code# 3
Full Source Code# 4
Home Work
• How to reset the laps?
• It is leaved as the homework for you.
• See the iOS 9’s stopwatch app for idea.

Contenu connexe

Tendances (6)

database management system lab files
database management system lab filesdatabase management system lab files
database management system lab files
 
MUnit run and wait scope
MUnit run and wait scopeMUnit run and wait scope
MUnit run and wait scope
 
youtube
youtubeyoutube
youtube
 
object oriented methodologies
object oriented methodologiesobject oriented methodologies
object oriented methodologies
 
Diagrama de Classe
Diagrama de ClasseDiagrama de Classe
Diagrama de Classe
 
Slide 5 Class Diagram
Slide 5 Class DiagramSlide 5 Class Diagram
Slide 5 Class Diagram
 

Similaire à [React Native Tutorial] Lecture 5: Input and State

Cis 407 i lab 1 of 7
Cis 407 i lab 1 of 7Cis 407 i lab 1 of 7
Cis 407 i lab 1 of 7
helpido9
 
Gui builder
Gui builderGui builder
Gui builder
learnt
 
Cis407 a ilab 1 web application development devry university
Cis407 a ilab 1 web application development devry universityCis407 a ilab 1 web application development devry university
Cis407 a ilab 1 web application development devry university
lhkslkdh89009
 
#42 green lantern framework
#42   green lantern framework#42   green lantern framework
#42 green lantern framework
Srilu Balla
 
Vbtutorial
VbtutorialVbtutorial
Vbtutorial
dhi her
 
1. User InterfaceCreate a simple text-based user interface wher.pdf
1. User InterfaceCreate a simple text-based user interface wher.pdf1. User InterfaceCreate a simple text-based user interface wher.pdf
1. User InterfaceCreate a simple text-based user interface wher.pdf
Conceptcreations1
 
Week 2PRG 218 Variables and Input and Output OperationsYou w.docx
Week 2PRG 218   Variables and Input and Output OperationsYou w.docxWeek 2PRG 218   Variables and Input and Output OperationsYou w.docx
Week 2PRG 218 Variables and Input and Output OperationsYou w.docx
melbruce90096
 

Similaire à [React Native Tutorial] Lecture 5: Input and State (20)

Introduction to VB.Net.pptx
Introduction to VB.Net.pptxIntroduction to VB.Net.pptx
Introduction to VB.Net.pptx
 
ASP DOT NET
ASP DOT NETASP DOT NET
ASP DOT NET
 
9b4c1 vb(pd) (2)
9b4c1 vb(pd) (2)9b4c1 vb(pd) (2)
9b4c1 vb(pd) (2)
 
9b4c1 vb(pd)
9b4c1 vb(pd)9b4c1 vb(pd)
9b4c1 vb(pd)
 
Cis 407 i lab 1 of 7
Cis 407 i lab 1 of 7Cis 407 i lab 1 of 7
Cis 407 i lab 1 of 7
 
Software engineering modeling lab lectures
Software engineering modeling lab lecturesSoftware engineering modeling lab lectures
Software engineering modeling lab lectures
 
Gui builder
Gui builderGui builder
Gui builder
 
Cis407 a ilab 1 web application development devry university
Cis407 a ilab 1 web application development devry universityCis407 a ilab 1 web application development devry university
Cis407 a ilab 1 web application development devry university
 
#42 green lantern framework
#42   green lantern framework#42   green lantern framework
#42 green lantern framework
 
Compose Camp Day 3 PPT.pptx.pdf
Compose Camp Day 3 PPT.pptx.pdfCompose Camp Day 3 PPT.pptx.pdf
Compose Camp Day 3 PPT.pptx.pdf
 
Ppt lesson 03
Ppt lesson 03Ppt lesson 03
Ppt lesson 03
 
Lect02 Introducing Programming.ppt
Lect02 Introducing Programming.pptLect02 Introducing Programming.ppt
Lect02 Introducing Programming.ppt
 
Ad basic tech_workshop
Ad basic tech_workshopAd basic tech_workshop
Ad basic tech_workshop
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Vbtutorial
VbtutorialVbtutorial
Vbtutorial
 
Web services in asp.net
Web services in asp.netWeb services in asp.net
Web services in asp.net
 
1. User InterfaceCreate a simple text-based user interface wher.pdf
1. User InterfaceCreate a simple text-based user interface wher.pdf1. User InterfaceCreate a simple text-based user interface wher.pdf
1. User InterfaceCreate a simple text-based user interface wher.pdf
 
Week 2PRG 218 Variables and Input and Output OperationsYou w.docx
Week 2PRG 218   Variables and Input and Output OperationsYou w.docxWeek 2PRG 218   Variables and Input and Output OperationsYou w.docx
Week 2PRG 218 Variables and Input and Output OperationsYou w.docx
 
Qtp check points
Qtp check pointsQtp check points
Qtp check points
 
MAD mobile application development you can learn from here , we perform all c...
MAD mobile application development you can learn from here , we perform all c...MAD mobile application development you can learn from here , we perform all c...
MAD mobile application development you can learn from here , we perform all c...
 

Plus de Kobkrit Viriyayudhakorn

Plus de Kobkrit Viriyayudhakorn (20)

Thai E-Voting System
Thai E-Voting System Thai E-Voting System
Thai E-Voting System
 
Thai National ID Card OCR
Thai National ID Card OCRThai National ID Card OCR
Thai National ID Card OCR
 
Chochae Robot - Thai voice communication extension pack for Service Robot
Chochae Robot - Thai voice communication extension pack for Service RobotChochae Robot - Thai voice communication extension pack for Service Robot
Chochae Robot - Thai voice communication extension pack for Service Robot
 
ศักยภาพของ AI สู่โอกาสใหม่แห่งการแข่งขันและความสำเร็จ (Thai AI updates in yea...
ศักยภาพของ AI สู่โอกาสใหม่แห่งการแข่งขันและความสำเร็จ (Thai AI updates in yea...ศักยภาพของ AI สู่โอกาสใหม่แห่งการแข่งขันและความสำเร็จ (Thai AI updates in yea...
ศักยภาพของ AI สู่โอกาสใหม่แห่งการแข่งขันและความสำเร็จ (Thai AI updates in yea...
 
Thai Text processing by Transfer Learning using Transformer (Bert)
Thai Text processing by Transfer Learning using Transformer (Bert)Thai Text processing by Transfer Learning using Transformer (Bert)
Thai Text processing by Transfer Learning using Transformer (Bert)
 
How Emoticon Affects Chatbot Users
How Emoticon Affects Chatbot UsersHow Emoticon Affects Chatbot Users
How Emoticon Affects Chatbot Users
 
หัวใจของปัญญาประดิษฐ์ (Gradient Descent ทำงานอย่างไร)
หัวใจของปัญญาประดิษฐ์ (Gradient Descent ทำงานอย่างไร)หัวใจของปัญญาประดิษฐ์ (Gradient Descent ทำงานอย่างไร)
หัวใจของปัญญาประดิษฐ์ (Gradient Descent ทำงานอย่างไร)
 
Check Raka Chatbot Pitching Presentation
Check Raka Chatbot Pitching PresentationCheck Raka Chatbot Pitching Presentation
Check Raka Chatbot Pitching Presentation
 
[Lecture 3] AI and Deep Learning: Logistic Regression (Coding)
[Lecture 3] AI and Deep Learning: Logistic Regression (Coding)[Lecture 3] AI and Deep Learning: Logistic Regression (Coding)
[Lecture 3] AI and Deep Learning: Logistic Regression (Coding)
 
[Lecture 4] AI and Deep Learning: Neural Network (Theory)
[Lecture 4] AI and Deep Learning: Neural Network (Theory)[Lecture 4] AI and Deep Learning: Neural Network (Theory)
[Lecture 4] AI and Deep Learning: Neural Network (Theory)
 
[Lecture 2] AI and Deep Learning: Logistic Regression (Theory)
[Lecture 2] AI and Deep Learning: Logistic Regression (Theory)[Lecture 2] AI and Deep Learning: Logistic Regression (Theory)
[Lecture 2] AI and Deep Learning: Logistic Regression (Theory)
 
ITS488 Lecture 6: Music and Sound Effect & GVR Try out.
ITS488 Lecture 6: Music and Sound Effect & GVR Try out.ITS488 Lecture 6: Music and Sound Effect & GVR Try out.
ITS488 Lecture 6: Music and Sound Effect & GVR Try out.
 
Lecture 12: React-Native Firebase Authentication
Lecture 12: React-Native Firebase AuthenticationLecture 12: React-Native Firebase Authentication
Lecture 12: React-Native Firebase Authentication
 
Unity Google VR Cardboard Deployment on iOS and Android
Unity Google VR Cardboard Deployment on iOS and AndroidUnity Google VR Cardboard Deployment on iOS and Android
Unity Google VR Cardboard Deployment on iOS and Android
 
ITS488 Lecture 4: Google VR Cardboard Game Development: Basket Ball Game #2
ITS488 Lecture 4: Google VR Cardboard Game Development: Basket Ball Game #2ITS488 Lecture 4: Google VR Cardboard Game Development: Basket Ball Game #2
ITS488 Lecture 4: Google VR Cardboard Game Development: Basket Ball Game #2
 
Lecture 4: ITS488 Digital Content Creation with Unity - Game and VR Programming
Lecture 4: ITS488 Digital Content Creation with Unity - Game and VR Programming Lecture 4: ITS488 Digital Content Creation with Unity - Game and VR Programming
Lecture 4: ITS488 Digital Content Creation with Unity - Game and VR Programming
 
Lecture 2: C# Programming for VR application in Unity
Lecture 2: C# Programming for VR application in UnityLecture 2: C# Programming for VR application in Unity
Lecture 2: C# Programming for VR application in Unity
 
Lecture 1 Introduction to VR Programming
Lecture 1 Introduction to VR ProgrammingLecture 1 Introduction to VR Programming
Lecture 1 Introduction to VR Programming
 
Thai Word Embedding with Tensorflow
Thai Word Embedding with Tensorflow Thai Word Embedding with Tensorflow
Thai Word Embedding with Tensorflow
 
Lecture 3 - ES6 Script Advanced for React-Native
Lecture 3 - ES6 Script Advanced for React-NativeLecture 3 - ES6 Script Advanced for React-Native
Lecture 3 - ES6 Script Advanced for React-Native
 

Dernier

Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 

Dernier (20)

%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 

[React Native Tutorial] Lecture 5: Input and State