Saturday, September 25, 2021

Top Local Databases For React Native Mobile App Development

 React Native has become one of the primary choices to develop cross-platform applications. It is also a cost-efficient solution to develop a mobile app quickly. The demand for React Native app development has grown substantially in the past few years. Developers are asked to develop high-performance offline first apps that are easily scalable.

It has made the mobile app developers think about the platform and tech stack to build a React Native app efficiently. React Native database (DB) is the backbone of application, hence, it should be selected with proper due diligence.

What to Know Before Selecting React Native Database?

The Complexity of the Data

Key-value storage is the default option for multiple client-side scripting languages and server-sides. Majorly both keys and values have to be kept in a serial in strings either through a library or by a React Native developer. However, serialization can cause serious issues and halts affecting the app performance, especially when it is working in the limited resource environment of a smartphone with a complex data set.

Hence, a database is selected to help you store data with greater complexity in comparison to the key-value pairs like objects and full documents.

Number of Lines of Code

If over 20 lines of code are required to write a CRUD operation, then you should not be looking for an advanced database. Advanced databases for React Native app development will make the coding complicated and will also affect the performance of DB significantly. It can also increase the cost of React Native development. On top of that, processing multiple code lines will only slow down the app.

Hence, avoid using advanced databases that may dwindle the app experience and slow down the release speed.

Synching of the Offline Data

You should go with a simple database for apps with lower complexity and no multiple-user collaboration. It would work better along with simple synchronized functionality. These apps can be synced easily with a server in the presence of an internet connection.

However, if collaboration is one of the primary features of your application then you need to go with a complex database to facilitate seamless syncing. Apps like Trello, leverage complex databases to ensure all the documents are in sync on all the devices.

Handling Data Conflicts and Concurrency

Possibility of a data conflict is directly proportional to the number of collaboration features your app has. It is advisable to go with a database that shares the conflict handling policies on the repository pages or website. Read database documents thoroughly to understand how databases handle syncing and conflicts. Also, check out the trade-offs that are done and how it can affect your application.

Memory Management

Your app can crash due to inadequate memory management. Compaction is one of the most used processes of memory management. It deletes the data or documents that are no longer in use. This process ensures that there is always some free memory available at any point in time.

These 5 factors will give you a fair idea on which local React Native database to select for your mobile application.

Top Local Databases for React Native App Development

1. Realm

Realm was built to develop offline and real-time apps that work on both smartphones and wearables. It is equally beneficial for React Native mobile applications for Android and iOS. It is built on top of SQLite or on ORM. Hence, it comes with its own database engine and never relies on key value stores.

Realm is one of the most preferred databases to develop high-performance apps or handle large chunks of data. With React Native app development, Realm is best for large mobile apps.

Benefits of Realm:

  • Realm Sync runs in the background to record service requests and user interactions locally
  • Redux offline can help you implement offline-first architecture easily
  • Leverages multiple encryption standards for different mobile platforms

2. Firebase

Firebase works with real-time NoSQL DB to develop React Native apps. It is selected primarily for its data synchronization and offline data change capabilities. It is capable of handling M and C of the MVC required for React Native apps.

Benefits of Firebase:

  • Firebase ensures real-time syncing of data for all clients at the same point in time. It is an important feature for apps that abruptly go offline due to disruption in the internet connectivity
  • It comes with a cross-platform API that requires minimal setup. Also, no application server is needed to access data as you access it directly by a smartphone
  • You can develop applications with offline persistence capabilities. It would include marking the presence of user offline or online and storing timestamp whenever the user goes offline

3. SQLite

SQLite was developed to provide local storage for mobile apps. Lite means that it is a lightweight library that needs minimal setup efforts. You can also integrate it within the mobile app to access the database directly.

Benefits of SQLite

  • Being an ACID-compliant database, it implements all SQL standards with a few omissions. It has file-based library architecture and comes equipped with tools capable of handling all data types efficiently
  • You can use a react-native-SQLite-storage plugin to manage data within the mobile app for offline persistence

4. PouchDB

PouchDB is a Javascript database. The open-source DB stores the data in JSON format. It allows developers to leverage the advantages of React Native easily through reading, developing, querying, updating, and deleting queries via a single JavaScript API. It is compatible with CouchDB, MongoDB, MySQL, and PostgreSQL.

Benefits of PouchDB:

  • There is no need to run queries over the network as PouchDB remains inside a browser. It helps in faster execution of queries
  • Sync data with a supported server to run apps both online and offline

5. Async Storage 

It is a local storage system that enables developers to persist data between application reboots while storing the data locally. Async Storage is in-built with React Native to help you use it for any additional deployment.

Benefits of Async Storage:

  • It is an excellent solution to save the data required by the app even after the app or device is closed by the user

6. Watermelon DB

It is built on SQLite and offers the potential to scale thousands of recordings without affecting the speed of the mobile app. Watermelon DB is optimized perfectly to develop complex apps on React Native with real-world performance.

Benefits of Watermelon DB:

  • It offers an offline first system
  • You can develop cross-platform mobile apps on SQLite foundation
  • Offers stating typing with flow

7. Vasern 

Vasern is an open-source and lightweight database for React Native app development. You can use the Vasern API for local data storage, cloud storage, and syncing across application’s clients. Its structure and design are inspired by multiple open source databases.

Benefits of Vasern DB:

  • Offer end-to-end syncing of database
  • Focuses on performances and consistency
  • Faster operations

8. BerkeleyDB 

BerkeleyDB offers a faster performing backend to enable React Native developers to handle data in several ways efficiently. Its API is compatible with multiple languages including Android and iOS.

It is capable of handling data in multiple ways including how SQLite does or through Value/Key pair data as byte arrays and also support several data items for one key.

Benefits of Berkeley DB:

  • Support concurrent access for several users
  • Offers industrial-strength transaction support
  • Easy to use

Tuesday, March 13, 2018

React native Animations

              Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface

            React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.


import React from 'react';
import { Animated, Text, View } from 'react-native';

class FadeInView extends React.Component {
  state = {
    fadeAnim: new Animated.Value(0),  // Initial value for opacity: 0
  }

  componentDidMount() {
    Animated.timing(                  // Animate over time
      this.state.fadeAnim,            // The animated value to drive
      {
        toValue: 1,                   // Animate to opacity: 1 (opaque)
        duration: 10000,              // Make it take a while
      }
    ).start();                        // Starts the animation
  }

  render() {
    let { fadeAnim } = this.state;

    return (
      <Animated.View                 // Special animatable View
        style={{
          ...this.props.style,
          opacity: fadeAnim,         // Bind opacity to animated value
        }}
      >
        {this.props.children}
      </Animated.View>
    );
  }
}

// You can then use your `FadeInView` in place of a `View` in your components:
export default class App extends React.Component {
  render() {
    return (
      <View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
        <FadeInView style={{width: 250, height: 50, backgroundColor: 'powderblue'}}>
          <Text style={{fontSize: 28, textAlign: 'center', margin: 10}}>Fading in</Text>
        </FadeInView>
      </View>
    )
  }

}



Tuesday, March 6, 2018

JavaScript tutorials


JavaScript Tutorial for beginners and professionals is a solution of client side dynamic pages.
JavaScript is an object-based scripting language that is lightweight and cross-platform.
JavaScript is not compiled but translated. The JavaScript Translator (embedded in browser) is responsible to translate the JavaScript code.

Where JavaScript is used
JavaScript is used to create interactive websites. It is mainly used for:
  • Client-side validation
  • Dynamic drop-down menus
  • Displaying data and time
  • Displaying popup windows and dialog boxes (like alert dialog box, confirm dialog box and prompt dialog box)
  • Displaying clocks etc.

JavaScript Example

<html>
<body>
<h2>Welcome to JavaScript</h2>
<script>
document.write("Hello JavaScript by JavaScript");
</script>
</body>
</html>



Javascript example is easy to code. JavaScript provides 3 places to put the JavaScript code: within body tag, within head tag and external JavaScript file.

3 Places to put JavaScript code

  1. Between the body tag of html
  2. Between the head tag of html
  3. In .js file (external javaScript)
  1. Between the body tag of html
<html>  
<body>  
<script type="text/javascript">  
 alert("Hello Javatpoint");  
</script>  
</body>  
</html>  

     2.Between the head tag of html



<html>  
<head>  
<script type="text/javascript">  
function msg(){  
 alert("Hello Javatpoint");  
}  
</script>  
</head>  
<body>  
<p>Welcome to Javascript</p>  
<form>  
<input type="button" value="click" onclick="msg()"/>  
</form>  
</body>  
</html>  


Types of JavaScript Comments

There are two types of comments in JavaScript.
  1. Single-line Comment
  2. Multi-line Comment

JavaScript Variable

JavaScript variable is simply a name of storage location. There are two types of variables in JavaScript : local variable and global variable.

There are some rules while declaring a JavaScript variable (also known as identifiers).
  1. Name must start with a letter (a to z or A to Z), underscore( _ ), or dollar( $ ) sign.
  2. After first letter we can use digits (0 to 9), for example value1.
  3. JavaScript variables are case sensitive, for example x and X are different variables.

JavaScript local variable

A JavaScript local variable is declared inside block or function. It is accessible within the function or block only

JavaScript global variable

JavaScript global variable is accessible from any function. A variable i.e. declared outside the function or declared with window object is known as global variable

Javascript Data Types

JavaScript provides different data types to hold different types of values. There are two types of data types in JavaScript.
  1. Primitive data type
  2. Non-primitive (reference) data type
JavaScript is a dynamic type language, means you don't need to specify type of the variable because it is dynamically used by JavaScript engine. You need to use var here to specify the data type. It can hold any type of values such as numbers, strings etc

  1. var a=40;//holding number  
  2. var b="Rahul";//holding string  

1). Primitive Data type 

There are five types of primitive data types in JavaScript. They are as follows:
1) String, represents sequence of characters e.g. "hello"
2) Number, represents numeric values e.g. 100
3) Boolean, represents boolean value either false or true

2) Non- Primitive 
The non-primitive data types are as follows:
1) Object,
2) Array,
3) RegExp

JavaScript Operators

JavaScript operators are symbols that are used to perform operations on operands. For example:
There are following types of operators in JavaScript.
  1. Arithmetic Operators
  2. Comparison (Relational) Operators
  3. Bitwise Operators
  4. Logical Operators
  5. Assignment Operators
  6. Special Operators

JavaScript Functions

avaScript functions are used to perform operations. We can call JavaScript function many times to reuse the code.

Advantage of JavaScript function

There are mainly two advantages of JavaScript functions.
  1. Code reusability: We can call a function several times so it save coding.
  2. Less coding: It makes our program compact. We don’t need to write many lines of code each time to perform a common task.
syntax:

  1. function functionName([arg1, arg2, ...argN]){  
  2.  //code to be executed  
  3. }  


Javascript Function :


<html>
<body>
<script>  
function msg(){  
alert("hello! this is message");  
}  
</script>  
<input type="button" onclick="msg()" value="call function"/>  
</body>
</html>

Javascript Function Argument :

<html>
<body>
<script>  
function getcube(number){  
alert(number*number*number);  
}  
</script>  
<form>  
<input type="button" value="click" onclick="getcube(4)"/>  
</form>  
</body>
</html>

Javascript Function with return value

<html>
<body>
<script>  
function getInfo(){  
return "hello javatpoint! How r u?";  
}  
</script>  
<script>  
document.write(getInfo());  
</script>  
</body>
</html>

JavaScript Objects

A javaScript object is an entity having state and behavior (properties and method). For example: car, pen, bike, chair, glass, keyboard, monitor etc.
JavaScript is an object-based language. Everything is an object in JavaScript.
JavaScript is template based not class based. Here, we don't create class to get the object. But, we direct create objects.

object by object literal:
  1. object={property1:value1,property2:value2.....propertyN:valueN}  

<html>
<body>
<script>  
emp={id:102,name:"Shyam Kumar",salary:40000}  
document.write(emp.id+" "+emp.name+" "+emp.salary);  
</script>
</body>
</html>

Creating instance Object 
var emp=new Object();

<html>
<body>
<script>  
var emp=new Object();  
emp.id=101;  
emp.name="Ravi Malik";  
emp.salary=50000;  
document.write(emp.id+" "+emp.name+" "+emp.salary);  
</script> 
</body>
</html>

Object Constructor

Here, you need to create function with arguments. Each argument value can be assigned in the current object by using this keyword.
The this keyword refers to the current object.

<html>
<body>
<script>  
function emp(id,name,salary){  
this.id=id;  
this.name=name;  
this.salary=salary;  
}  
e=new emp(103,"Vimal Jaiswal",30000);  
  
document.write(e.id+" "+e.name+" "+e.salary);  
</script>  
</body>
</html>

JavaScript Array

JavaScript array is an object that represents a collection of similar type of elements.
There are 3 ways to construct array in JavaScript
  1. By array literal
  2. By creating instance of Array directly (using new keyword)
  3. By using an Array constructor (using new keyword)
Array litral 
The syntax of creating array using array literal is given below:
  1. var arrayname=[value1,value2.....valueN];  
  2. example:
<html>
<body>
<script>  
var emp=["Sonoo","Vimal","Ratan"];  
for (i=0;i<emp.length;i++){  
document.write(emp[i] + "<br/>");  
}  
</script>  
</body>
</html>

Instance Array
The syntax of creating array directly is given below:
  1. var arrayname=new Array();  
  2. example:
<html>
<body>
<script>  
var i;  
var emp = new Array();  
emp[0] = "Arun";  
emp[1] = "Varun";  
emp[2] = "John";  
  
for (i=0;i<emp.length;i++){  
document.write(emp[i] + "<br>");  
}  
</script>  
</body>
</html>

Constructor Array

Here, you need to create instance of array by passing arguments in constructor so that we don't have to provide value explicitly.
The example of creating object by array constructor is given below.
syntax :  var emp=new Array(value1,value2,value3);  
<html>
<body>
<script>  
var emp=new Array("Jai","Vijay","Smith");  
for (i=0;i<emp.length;i++){  
document.write(emp[i] + "<br>");  
}  
</script>  
</body>
</html>

JavaScript String

The JavaScript string is an object that represents a sequence of characters.
There are 2 ways to create string in JavaScript
  1. By string literal
  2. By string object (using new keyword)
String Literal
The string literal is created using double quotes. The syntax of creating string using string literal is given below:

var stringname="string value"

String Object
The syntax of creating string object using new keyword is given below:
Here, new keyword is used to create instance of string.

var stringname=new String("string literal");

String Method
Let's see the list of JavaScript string methods with examples.

  • charAt(index)
  • concat(str)
  • indexOf(str)
  • lastIndexOf(str)
  • toLowerCase()
  • toUpperCase()
  • slice(beginIndex, endIndex)
  • trim(