SlideShare une entreprise Scribd logo
1  sur  63
Télécharger pour lire hors ligne
Kobkrit Viriyayudhakorn, Ph.D.
kobkrit@gmail.com
http://www.kobkrit.com
Making Chat Room App
Important Links
• Source Codes 

https://github.com/kobkrit/learn-react-native
• Course Materials

http://www.kobkrit.com/category/programming/react-
native/
• Score Announcement

http://bit.ly/its484quizscore
• Facebook Group

https://web.facebook.com/groups/ReactNativeThai/

React Native’s Component
Lifecycle
constructor(props)
render() -> React Element
That we have known so far…
It is not completed. Here is the completed one…
Advanced React Native Component

Mounting Lifecycle
constructor(props)
componentWillMount()
render() -> React Element
componentDidMount()
React Native Component

Mounting Lifecycle
• constructor(object props)
• The component class is instantiated.
• The parameters to the constructor are the element's
initial props, as specified by the parent element.
• You can optionally specify an initial state for the
element by assigning an object to this.state.
• At this point, no native UI has been rendered yet for
this element.
React Native Component

Mounting Lifecycle
• componentWillMount()
• This method is invoked only once, before rendering
occurs for the first time.
• At this point, there is still no native UI rendered for this
element.
• render() -> React Element
• The render method must return a React Element to
render (or null, to render nothing).
React Native Component

Mounting Lifecycle
• componentDidMount()
• This method is invoked only once, after rendering
occurs for the first time.
• At this point, the native UI for this element has finished
rendering, and may be accessed through this.refs for
direct manipulation.
• If you need to make async API calls or execute
delayed code with setTimeout, that should generally
be done in this method.


Updating Lifecycle
componentWillReceiveProps(nextProps)
shouldComponentUpdate(nextProps,
nextState)
render() -> React Element
componentDidUpdate(prevProp, prevState)
componentWillUpdate(nextProps,
nextState)
React Native Component

Updating Lifecycle
• componentWillReceiveProps(object nextProps)
• The parent of this component has passed a new set of
props.
• This component will re-render.
• You may optionally call this.setState() to update this
component's internal state before the render method
is called.
React Native Component

Updating Lifecycle
• shouldComponentUpdate(object nextProps, object
nextState) -> boolean
• Based on the next set of props and state, a
component may decide to re-render or not to re-
render.
• The base class's implementation of this method
always returns true (the component should re-render).
• For optimization, override this method and check if
either props or state have been modified, e.g. run an
equality test of each key/value in these objects.
• Returning false will prevent the render method from
being called.
React Native Component

Updating Lifecycle
• componentWillUpdate(object nextProps, object
nextState)
• This method is invoked, after the decision has been
made to re-render.
• You may not call this.setState() here, since an update
is already in progress.
• render() -> React Element
• This method is called, assuming
shouldComponentUpdate returned true.
• The render method must return a React Element to
render (or null, to render nothing).
React Native Component

Updating Lifecycle
• componentDidUpdate(object prevProps, object
prevState)
• This method is invoked after re-rendering occurs. At
this point, the native UI for this component has been
updated to reflect the React Element returned from
the render() method.
Mounting (Opening the App)
l12_firebase/bmi.js
Changing Height to 5
l12_firebase/bmi.js
Changing Weight to 5
l12_firebase/bmi.js
Why???
Because…
l12_firebase/bmi.js
• Firebase is a mobile platform that helps you quickly
develop high-quality apps, grow your user base,
and earn more money.
• The tools and infrastructure you need to build
better apps and grow successful businesses
• Firebase is made up of complementary features
that you can mix-and-match to fit your needs.
• It was acquired by Google since 2014.
Key Features
• Authentication (User Sign-In, User Registration, Login
by Google, Login by Facebook)
• Realtime Database (Store and sync app data in
realtime)
• Cloud Messaging (Send Notification to User’s Mobile)
• Crash Reporting (Sending crash report to us)
• Analytics (Knowing how much people using our app
right now)
Firebase span over 2 weeks
• Lecture 12
• Real-Time Database Part I
• Lecture 13
• Real-Time Database Part II
• Authentication
• Cloud Messaging / Notification
Getting Start With Firebase
1. Create Firebase Project in the Firebase console.

https://console.firebase.google.com/ (We need a
Google account for this).
2. Retrieve apiKey, authDomain, databaseURL, and
storageBucket from Firebase console.
3. Create a new react-native project.
4. Install Firebase from npm.
5. Add it into a react-native project.
Create a Project @ Firebase
• Enter https://console.firebase.google.com/
• Login with your Google account
• Press “Create New Project” button

1. Adding Project Name (Any name is fine)
2. Select Country to Thailand
3. Press Create Project button
• Click at “Add Firebase to your web app” 

(The pink one)
• Press Copy button to copy the apiKey, authDomain,
databaseURL, storageBucket, and messagingSenderId
and paste into the code.
Create New Project and
Install Firebase
• We will install Firebase version 3.6.0
• Open Terminal and change to a working directory
• $|> react-native init l12_firebase
• $|> cd l12_firebase
• $|> npm install firebase --save
• $|> atom index.ios.js
1.js
Realtime Database
• Store and sync data with our NoSQL cloud
database. Data is synced across all clients in
realtime, and remains available when your app
goes offline.
Key Differences with Realm
• Realm allows you implement your own database
server. Firebase can’t. You need to use Google
Cloud server (which is not free if it is a high traffic).
• Realms DB is the reactive programming concept
(Lazy loading). Firebase’s Realtime DB isn’t.
• Realms DB needs to specify database schema,
while Firebase isn’t. Firebase will save what ever it
got.
Realtime Database Structure
• All Firebase Realtime Database data is stored as
JSON objects, e.g.,
Basic Writing Operation
• Get a database reference
• Writing something
Save the {text: ‘Hello Text!’} as key ‘notes/1’ 

into Firebase database
1.js
1.js
What happen?
• As the default, user who can write the realtime
database must be authenticated.
• Since our user is not yet authenticated, so the
permission error is occurred.
• For development, We can change this behavior by
re-configure the Database permission.
Realtime Database
Permission Rules
1
2
https://console.firebase.google.com/
Sample Realtime DB Rules
• Default (Require Authentication)









• Public / Development (Open to everyone)
Sample Realtime DB Rules
• Private User Database (Which means only owners
can access their information in database)









Sample Realtime DB Rules
• Private (No one can access the database, except
admin can access via Firebase console)
Change Realtime DB
permission to Public
• Change the rule to Public permission
• Press “Publish” button
Reload the App again
• At Simulator, Cmd + R or
R,R for reload
• Now there is no warning
sign.
• Realtime database save
successfully.
Viewing Saved database
• We can view the saved information in Firebase’s
Realtime database at Firebase console.
• https://console.firebase.google.com/project/{your-
project-name}/database/data
Chat Room App
• Simple one chat room.
• Showing number of online users.
• Showing conversations publicly.
• Send the chat message.
• Setting the username
2.js
Making Chat Room App UI
2.js
User online / offline
• Conditions
• Online, when the app is active on the screen.
• Offline, when the app is inactive or in
background on the screen.
• We need helps from a React Native’s library called
“AppState”
AppState
• Can tell us whether the app is in foreground (active) on
the screen, or in background (inactive).
• active - The app is running in the foreground
• background - The app is running in the background.
The user is either in another app or on the home screen
• inactive - This is a state that occurs when transitioning
between foreground & background, and during periods
of inactivity such as entering the Multitasking view or in
the event of an incoming call
Obtaining State
• Accessing AppState.currentState (it was kept up-
to-date by React Native)
• E.g., If app in the foreground (active) state.
• AppState.currentState == “active”
• If app in the background state.
• AppState.currentState == “background”
Listening for State changes
2.js
Key Logics for Online User
Counting
• Enter the app
• Read the current onlineUser from Firebase
• Add by 1
• Push it back to the Firebase.
• Leave the app.
• Read the current onlineUser from Firebase
• Remove by 1
• Push it back to the Firebase.
Want do some operation in
background?
• When user leave the app, the app become into the
background state.
• All JavaScript code is halted and unloaded from the
memory.
• All timers (setTimeout) are unable to execute,
because their don’t found the codes to run in the
memory.
• We need an external library for running operation in
background.
react-native-background-
timer
• Installation
• $|> npm install react-native-background-timer -- save
• $|> react-native link
• Usage
Handling # of Online User
2.js
2.js
On vs Once
• firebaseRef.on(‘value’, callback)
• Listening for data change forever.
• When the data has changed, the call back is called.
• firebaseRef.once(‘value’, callback)
• Listening for data change only one time. Once it is
changed, it called only one time and become
inactive.
Opening the App
Leaving the App
Enter the App Again..
Modifying DB value in 

Firebase console
Realtime DB Transaction
• Problem occurs!
• When two users open the app at the same time,
when will be happen?
• Both users read the amount of user as the same
value, both users update the database by
increasing by 1. Instead of adding by 2.
• Number of online user and real online user is
mismatched.
Realtime DB Transaction
3.js
Realtime DB Transaction
3.js
Realtime DB Transaction
• All transaction requests will be queued at the Firebase
server and will be processed one-by-one.
• Transaction guarantees that no other operations can
write into database during the reading and writing
operations in a transaction block.
• This behavior, we called it atomic write operations.
• Problems of mismatch number of online users when
two or more users enter the app at the same time,
solved!
Q/A

Contenu connexe

Tendances

React js use contexts and useContext hook
React js use contexts and useContext hookReact js use contexts and useContext hook
React js use contexts and useContext hookPiyush Jamwal
 
Intro To React Native
Intro To React NativeIntro To React Native
Intro To React NativeFITC
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooksMaulik Shah
 
Reactjs workshop (1)
Reactjs workshop (1)Reactjs workshop (1)
Reactjs workshop (1)Ahmed rebai
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass SlidesNir Kaufman
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_jsMicroPyramid .
 
An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJSAll Things Open
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJSKnoldus Inc.
 
React js programming concept
React js programming conceptReact js programming concept
React js programming conceptTariqul islam
 
Introduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace ITIntroduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace ITnamespaceit
 
Redux Toolkit - Quick Intro - 2022
Redux Toolkit - Quick Intro - 2022Redux Toolkit - Quick Intro - 2022
Redux Toolkit - Quick Intro - 2022Fabio Biondi
 
Basics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdfBasics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdfKnoldus Inc.
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React NativeSambhu Lakshmanan
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners Varun Raj
 
How native is React Native? | React Native vs Native App Development
How native is React Native? | React Native vs Native App DevelopmentHow native is React Native? | React Native vs Native App Development
How native is React Native? | React Native vs Native App DevelopmentDevathon
 

Tendances (20)

React js use contexts and useContext hook
React js use contexts and useContext hookReact js use contexts and useContext hook
React js use contexts and useContext hook
 
ReactJS
ReactJSReactJS
ReactJS
 
Intro To React Native
Intro To React NativeIntro To React Native
Intro To React Native
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooks
 
Introduction to react js
Introduction to react jsIntroduction to react js
Introduction to react js
 
Reactjs workshop (1)
Reactjs workshop (1)Reactjs workshop (1)
Reactjs workshop (1)
 
WEB DEVELOPMENT USING REACT JS
 WEB DEVELOPMENT USING REACT JS WEB DEVELOPMENT USING REACT JS
WEB DEVELOPMENT USING REACT JS
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass Slides
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_js
 
An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJS
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 
Its time to React.js
Its time to React.jsIts time to React.js
Its time to React.js
 
Introduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace ITIntroduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace IT
 
Redux Toolkit - Quick Intro - 2022
Redux Toolkit - Quick Intro - 2022Redux Toolkit - Quick Intro - 2022
Redux Toolkit - Quick Intro - 2022
 
Workshop 21: React Router
Workshop 21: React RouterWorkshop 21: React Router
Workshop 21: React Router
 
Basics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdfBasics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdf
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
 
How native is React Native? | React Native vs Native App Development
How native is React Native? | React Native vs Native App DevelopmentHow native is React Native? | React Native vs Native App Development
How native is React Native? | React Native vs Native App Development
 

Similaire à React Native Firebase

React.js - The Dawn of Virtual DOM
React.js - The Dawn of Virtual DOMReact.js - The Dawn of Virtual DOM
React.js - The Dawn of Virtual DOMJimit Shah
 
React and Flux life cycle with JSX, React Router and Jest Unit Testing
React and  Flux life cycle with JSX, React Router and Jest Unit TestingReact and  Flux life cycle with JSX, React Router and Jest Unit Testing
React and Flux life cycle with JSX, React Router and Jest Unit TestingEswara Kumar Palakollu
 
React Native Firebase Realtime Database + Authentication
React Native Firebase Realtime Database + AuthenticationReact Native Firebase Realtime Database + Authentication
React Native Firebase Realtime Database + AuthenticationKobkrit Viriyayudhakorn
 
O365 Developer Bootcamp NJ 2018 - Material
O365 Developer Bootcamp NJ 2018 - MaterialO365 Developer Bootcamp NJ 2018 - Material
O365 Developer Bootcamp NJ 2018 - MaterialThomas Daly
 
Optimizing your use of react life cycles by shedrack akintayo
Optimizing your use of react life cycles by shedrack akintayoOptimizing your use of react life cycles by shedrack akintayo
Optimizing your use of react life cycles by shedrack akintayoShedrack Akintayo
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with SeleniumDave Haeffner
 
Managing state in modern React web applications
Managing state in modern React web applicationsManaging state in modern React web applications
Managing state in modern React web applicationsJon Preece
 
Introduction to react native with redux
Introduction to react native with reduxIntroduction to react native with redux
Introduction to react native with reduxMike Melusky
 
React state management with Redux and MobX
React state management with Redux and MobXReact state management with Redux and MobX
React state management with Redux and MobXDarko Kukovec
 
Understanding Facebook's React.js
Understanding Facebook's React.jsUnderstanding Facebook's React.js
Understanding Facebook's React.jsFederico Torre
 
Spfx with react redux
Spfx with react reduxSpfx with react redux
Spfx with react reduxRajesh Kumar
 
SFDC Deployments
SFDC DeploymentsSFDC Deployments
SFDC DeploymentsSujit Kumar
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsJeff Durta
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react jsStephieJohn
 
Marty, You're Just Not Thinking Fourth Dimensionally
Marty, You're Just Not Thinking Fourth DimensionallyMarty, You're Just Not Thinking Fourth Dimensionally
Marty, You're Just Not Thinking Fourth DimensionallyTeamstudio
 

Similaire à React Native Firebase (20)

React.js - The Dawn of Virtual DOM
React.js - The Dawn of Virtual DOMReact.js - The Dawn of Virtual DOM
React.js - The Dawn of Virtual DOM
 
React and Flux life cycle with JSX, React Router and Jest Unit Testing
React and  Flux life cycle with JSX, React Router and Jest Unit TestingReact and  Flux life cycle with JSX, React Router and Jest Unit Testing
React and Flux life cycle with JSX, React Router and Jest Unit Testing
 
React Native Firebase Realtime Database + Authentication
React Native Firebase Realtime Database + AuthenticationReact Native Firebase Realtime Database + Authentication
React Native Firebase Realtime Database + Authentication
 
O365 Developer Bootcamp NJ 2018 - Material
O365 Developer Bootcamp NJ 2018 - MaterialO365 Developer Bootcamp NJ 2018 - Material
O365 Developer Bootcamp NJ 2018 - Material
 
Optimizing your use of react life cycles by shedrack akintayo
Optimizing your use of react life cycles by shedrack akintayoOptimizing your use of react life cycles by shedrack akintayo
Optimizing your use of react life cycles by shedrack akintayo
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with Selenium
 
Reactjs
Reactjs Reactjs
Reactjs
 
Managing state in modern React web applications
Managing state in modern React web applicationsManaging state in modern React web applications
Managing state in modern React web applications
 
ReactJS
ReactJSReactJS
ReactJS
 
Introduction to react native with redux
Introduction to react native with reduxIntroduction to react native with redux
Introduction to react native with redux
 
React state management with Redux and MobX
React state management with Redux and MobXReact state management with Redux and MobX
React state management with Redux and MobX
 
React a11y-csun
React a11y-csunReact a11y-csun
React a11y-csun
 
Understanding Facebook's React.js
Understanding Facebook's React.jsUnderstanding Facebook's React.js
Understanding Facebook's React.js
 
Spfx with react redux
Spfx with react reduxSpfx with react redux
Spfx with react redux
 
SFDC Deployments
SFDC DeploymentsSFDC Deployments
SFDC Deployments
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
 
Redux Tech Talk
Redux Tech TalkRedux Tech Talk
Redux Tech Talk
 
Marty, You're Just Not Thinking Fourth Dimensionally
Marty, You're Just Not Thinking Fourth DimensionallyMarty, You're Just Not Thinking Fourth Dimensionally
Marty, You're Just Not Thinking Fourth Dimensionally
 

Plus de Kobkrit Viriyayudhakorn

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 RobotKobkrit Viriyayudhakorn
 
ศักยภาพของ AI สู่โอกาสใหม่แห่งการแข่งขันและความสำเร็จ (Thai AI updates in yea...
ศักยภาพของ AI สู่โอกาสใหม่แห่งการแข่งขันและความสำเร็จ (Thai AI updates in yea...ศักยภาพของ AI สู่โอกาสใหม่แห่งการแข่งขันและความสำเร็จ (Thai AI updates in yea...
ศักยภาพของ AI สู่โอกาสใหม่แห่งการแข่งขันและความสำเร็จ (Thai AI updates in yea...Kobkrit Viriyayudhakorn
 
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)Kobkrit Viriyayudhakorn
 
หัวใจของปัญญาประดิษฐ์ (Gradient Descent ทำงานอย่างไร)
หัวใจของปัญญาประดิษฐ์ (Gradient Descent ทำงานอย่างไร)หัวใจของปัญญาประดิษฐ์ (Gradient Descent ทำงานอย่างไร)
หัวใจของปัญญาประดิษฐ์ (Gradient Descent ทำงานอย่างไร)Kobkrit Viriyayudhakorn
 
Check Raka Chatbot Pitching Presentation
Check Raka Chatbot Pitching PresentationCheck Raka Chatbot Pitching Presentation
Check Raka Chatbot Pitching PresentationKobkrit Viriyayudhakorn
 
[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)Kobkrit Viriyayudhakorn
 
[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)Kobkrit Viriyayudhakorn
 
[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)Kobkrit Viriyayudhakorn
 
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.Kobkrit Viriyayudhakorn
 
Lecture 12: React-Native Firebase Authentication
Lecture 12: React-Native Firebase AuthenticationLecture 12: React-Native Firebase Authentication
Lecture 12: React-Native Firebase AuthenticationKobkrit Viriyayudhakorn
 
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 AndroidKobkrit Viriyayudhakorn
 
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 #2Kobkrit Viriyayudhakorn
 
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 Kobkrit Viriyayudhakorn
 
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 UnityKobkrit Viriyayudhakorn
 
Lecture 1 Introduction to VR Programming
Lecture 1 Introduction to VR ProgrammingLecture 1 Introduction to VR Programming
Lecture 1 Introduction to VR ProgrammingKobkrit Viriyayudhakorn
 
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-NativeKobkrit 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

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 

Dernier (20)

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 

React Native Firebase

  • 2. Important Links • Source Codes 
 https://github.com/kobkrit/learn-react-native • Course Materials
 http://www.kobkrit.com/category/programming/react- native/ • Score Announcement
 http://bit.ly/its484quizscore • Facebook Group
 https://web.facebook.com/groups/ReactNativeThai/

  • 3. React Native’s Component Lifecycle constructor(props) render() -> React Element That we have known so far… It is not completed. Here is the completed one…
  • 4. Advanced React Native Component
 Mounting Lifecycle constructor(props) componentWillMount() render() -> React Element componentDidMount()
  • 5. React Native Component
 Mounting Lifecycle • constructor(object props) • The component class is instantiated. • The parameters to the constructor are the element's initial props, as specified by the parent element. • You can optionally specify an initial state for the element by assigning an object to this.state. • At this point, no native UI has been rendered yet for this element.
  • 6. React Native Component
 Mounting Lifecycle • componentWillMount() • This method is invoked only once, before rendering occurs for the first time. • At this point, there is still no native UI rendered for this element. • render() -> React Element • The render method must return a React Element to render (or null, to render nothing).
  • 7. React Native Component
 Mounting Lifecycle • componentDidMount() • This method is invoked only once, after rendering occurs for the first time. • At this point, the native UI for this element has finished rendering, and may be accessed through this.refs for direct manipulation. • If you need to make async API calls or execute delayed code with setTimeout, that should generally be done in this method.
  • 8. 
 Updating Lifecycle componentWillReceiveProps(nextProps) shouldComponentUpdate(nextProps, nextState) render() -> React Element componentDidUpdate(prevProp, prevState) componentWillUpdate(nextProps, nextState)
  • 9. React Native Component
 Updating Lifecycle • componentWillReceiveProps(object nextProps) • The parent of this component has passed a new set of props. • This component will re-render. • You may optionally call this.setState() to update this component's internal state before the render method is called.
  • 10. React Native Component
 Updating Lifecycle • shouldComponentUpdate(object nextProps, object nextState) -> boolean • Based on the next set of props and state, a component may decide to re-render or not to re- render. • The base class's implementation of this method always returns true (the component should re-render). • For optimization, override this method and check if either props or state have been modified, e.g. run an equality test of each key/value in these objects. • Returning false will prevent the render method from being called.
  • 11. React Native Component
 Updating Lifecycle • componentWillUpdate(object nextProps, object nextState) • This method is invoked, after the decision has been made to re-render. • You may not call this.setState() here, since an update is already in progress. • render() -> React Element • This method is called, assuming shouldComponentUpdate returned true. • The render method must return a React Element to render (or null, to render nothing).
  • 12. React Native Component
 Updating Lifecycle • componentDidUpdate(object prevProps, object prevState) • This method is invoked after re-rendering occurs. At this point, the native UI for this component has been updated to reflect the React Element returned from the render() method.
  • 13. Mounting (Opening the App) l12_firebase/bmi.js
  • 14. Changing Height to 5 l12_firebase/bmi.js
  • 15. Changing Weight to 5 l12_firebase/bmi.js
  • 17. • Firebase is a mobile platform that helps you quickly develop high-quality apps, grow your user base, and earn more money. • The tools and infrastructure you need to build better apps and grow successful businesses • Firebase is made up of complementary features that you can mix-and-match to fit your needs. • It was acquired by Google since 2014.
  • 18.
  • 19. Key Features • Authentication (User Sign-In, User Registration, Login by Google, Login by Facebook) • Realtime Database (Store and sync app data in realtime) • Cloud Messaging (Send Notification to User’s Mobile) • Crash Reporting (Sending crash report to us) • Analytics (Knowing how much people using our app right now)
  • 20. Firebase span over 2 weeks • Lecture 12 • Real-Time Database Part I • Lecture 13 • Real-Time Database Part II • Authentication • Cloud Messaging / Notification
  • 21. Getting Start With Firebase 1. Create Firebase Project in the Firebase console.
 https://console.firebase.google.com/ (We need a Google account for this). 2. Retrieve apiKey, authDomain, databaseURL, and storageBucket from Firebase console. 3. Create a new react-native project. 4. Install Firebase from npm. 5. Add it into a react-native project.
  • 22. Create a Project @ Firebase • Enter https://console.firebase.google.com/ • Login with your Google account • Press “Create New Project” button

  • 23. 1. Adding Project Name (Any name is fine) 2. Select Country to Thailand 3. Press Create Project button
  • 24. • Click at “Add Firebase to your web app” 
 (The pink one)
  • 25. • Press Copy button to copy the apiKey, authDomain, databaseURL, storageBucket, and messagingSenderId and paste into the code.
  • 26. Create New Project and Install Firebase • We will install Firebase version 3.6.0 • Open Terminal and change to a working directory • $|> react-native init l12_firebase • $|> cd l12_firebase • $|> npm install firebase --save • $|> atom index.ios.js
  • 27. 1.js
  • 28. Realtime Database • Store and sync data with our NoSQL cloud database. Data is synced across all clients in realtime, and remains available when your app goes offline.
  • 29. Key Differences with Realm • Realm allows you implement your own database server. Firebase can’t. You need to use Google Cloud server (which is not free if it is a high traffic). • Realms DB is the reactive programming concept (Lazy loading). Firebase’s Realtime DB isn’t. • Realms DB needs to specify database schema, while Firebase isn’t. Firebase will save what ever it got.
  • 30. Realtime Database Structure • All Firebase Realtime Database data is stored as JSON objects, e.g.,
  • 31. Basic Writing Operation • Get a database reference • Writing something Save the {text: ‘Hello Text!’} as key ‘notes/1’ 
 into Firebase database
  • 32. 1.js
  • 33. 1.js
  • 34. What happen? • As the default, user who can write the realtime database must be authenticated. • Since our user is not yet authenticated, so the permission error is occurred. • For development, We can change this behavior by re-configure the Database permission.
  • 36. Sample Realtime DB Rules • Default (Require Authentication)
 
 
 
 
 • Public / Development (Open to everyone)
  • 37. Sample Realtime DB Rules • Private User Database (Which means only owners can access their information in database)
 
 
 
 

  • 38. Sample Realtime DB Rules • Private (No one can access the database, except admin can access via Firebase console)
  • 39. Change Realtime DB permission to Public • Change the rule to Public permission • Press “Publish” button
  • 40. Reload the App again • At Simulator, Cmd + R or R,R for reload • Now there is no warning sign. • Realtime database save successfully.
  • 41. Viewing Saved database • We can view the saved information in Firebase’s Realtime database at Firebase console. • https://console.firebase.google.com/project/{your- project-name}/database/data
  • 42.
  • 43. Chat Room App • Simple one chat room. • Showing number of online users. • Showing conversations publicly. • Send the chat message. • Setting the username 2.js
  • 44. Making Chat Room App UI 2.js
  • 45. User online / offline • Conditions • Online, when the app is active on the screen. • Offline, when the app is inactive or in background on the screen. • We need helps from a React Native’s library called “AppState”
  • 46. AppState • Can tell us whether the app is in foreground (active) on the screen, or in background (inactive). • active - The app is running in the foreground • background - The app is running in the background. The user is either in another app or on the home screen • inactive - This is a state that occurs when transitioning between foreground & background, and during periods of inactivity such as entering the Multitasking view or in the event of an incoming call
  • 47. Obtaining State • Accessing AppState.currentState (it was kept up- to-date by React Native) • E.g., If app in the foreground (active) state. • AppState.currentState == “active” • If app in the background state. • AppState.currentState == “background”
  • 48. Listening for State changes 2.js
  • 49. Key Logics for Online User Counting • Enter the app • Read the current onlineUser from Firebase • Add by 1 • Push it back to the Firebase. • Leave the app. • Read the current onlineUser from Firebase • Remove by 1 • Push it back to the Firebase.
  • 50. Want do some operation in background? • When user leave the app, the app become into the background state. • All JavaScript code is halted and unloaded from the memory. • All timers (setTimeout) are unable to execute, because their don’t found the codes to run in the memory. • We need an external library for running operation in background.
  • 51. react-native-background- timer • Installation • $|> npm install react-native-background-timer -- save • $|> react-native link • Usage
  • 52. Handling # of Online User 2.js
  • 53. 2.js
  • 54. On vs Once • firebaseRef.on(‘value’, callback) • Listening for data change forever. • When the data has changed, the call back is called. • firebaseRef.once(‘value’, callback) • Listening for data change only one time. Once it is changed, it called only one time and become inactive.
  • 57. Enter the App Again..
  • 58. Modifying DB value in 
 Firebase console
  • 59. Realtime DB Transaction • Problem occurs! • When two users open the app at the same time, when will be happen? • Both users read the amount of user as the same value, both users update the database by increasing by 1. Instead of adding by 2. • Number of online user and real online user is mismatched.
  • 62. Realtime DB Transaction • All transaction requests will be queued at the Firebase server and will be processed one-by-one. • Transaction guarantees that no other operations can write into database during the reading and writing operations in a transaction block. • This behavior, we called it atomic write operations. • Problems of mismatch number of online users when two or more users enter the app at the same time, solved!
  • 63. Q/A