Expo Big Battle (27)--expo SDK API Util (Expo comes with the tool class), Tacksnapshotasync,svg,sqlite

Source: Internet
Author: User
Tags base64 event listener log log sql injection sqlite






Brief: This series of articles will be a comprehensive introduction to the Expo, I contact the Expo since June 2017, the study of the Expo intermittent, all the way to nearly 10 months, nonsense not to say, next you see the content, speak all to the official website



I guess go all machine turn + personal modification supplement +demo test form, to the expo to do a big blood! Welcome to join the Expo Interest Learning Exchange Group: 597732981



"Before I wrote some columns about Expo and RN entry configuration for East I west, you can click here to view: from zero learning RN development"



Related articles:



Expo Big Battle (a)--what is the expo, how to install Expo Clinet and xde,xde how to use



Expo Big Battle (ii)--expo life cycle, Expo Community exchanges, Expo learning necessary resources, the development of the use of the expo concerns some issues



Expo Big Battle (iii)--to the development of react native project developers have targeted the introduction of the limitations of Expo,expo, the development of project selection points of attention, etc.



Expo Big Battle (Iv.)--Rapid use of Expo to build a key term in a App,expo



Expo Big Battle (v) configuration information for App.json files in--expo



Expo Big Battle (vi)--EXPO Development mode, Expo in the EXP Command line tool, Expo How to view the debug mode in the log Log,expo



Expo Big Battle (vii)--expo How to use Genymotion simulator



Expo Big Battle (eight)--expo in the Publish and Expo link, to link this piece of things not detailed see, we can come to communicate with me



More >>



Written in chapter 23 after the words, before the translation, no matter how, good and bad, after all, is the end of the expo, but also the basic theory of the things in-depth understanding again, the following Expo big Battle series will mainly introduce the Expo SDK API.


Util


A tool class provided in the Expo, not suitable for useful practical functions elsewhere (helpful utility functions that don ' t fit anywhere else), including some localization/internationalization methods (including some localization/i18n methods.).



Expo.Util.getCurrentDeviceCountryAsync ()
Returns the current device country code.



Expo.Util.getCurrentLocaleAsync ()
Returns the current device locale as a string.



Expo.Util.getCurrentTimeZoneAsync ()
Returns the current device time zone name.



Expo.Util.reload ()
Reload the current experience (reloads the experience). This will get and load the latest available JS for the device's Expo environment support. This is useful for triggering the update experience if you have released a new version.


Subscribe to application updates (subscribing to app update) Expo.Util.addNewVersionListenerExperimental(listener)


Android only. Callback is invoked when a new version of your application is successfully downloaded in the background.



Parameters
Listener-callback function that is called when a new version of the application is successfully downloaded in the background.



Return
A Eventsubscription object that you can call remove () when you want to unsubscribe from the listener.


Correlation type (related types)


Eventsubscription



Return from Addnewversionlistenerexperimental.


    • Remove () (function)-cancels the subscription of the Listener for future updates.


Event



The object that is passed into each event listener when the new version is available.


    • Manifest (object)-The manifest object for the new version of the application.




Takesnapshotasync


Given the view, Takesnapshotasync will basically intercept the view and return an image for you. This is useful for users such as signature boards, where users draw some content and then want to save the image from it.


Expo.takeSnapshotAsync(view, options)


Snapshot given view (snapshots the given view).


Parameters
    • View (number | reactelement)-A snapshot view of ref or Reacttag (also known as a node handle).
Options ( Object) —


Option graph (A Map of options:):


    • Format (string)-"PNG" | "JPG" | "JPEG" | " WEBM "
    • Quality (number) Quality (qty)-Numbers between 0 and 1, of which 0 is the worst quality, and 1 is the best.
    • Result (string)-the type of the resulting image. -' file '-Returns a file URI. -' base64 '-Base64 encoded image. -' Data-uri '-Base64 encoded image with Data-uri prefix.
    • Height (number)-the height of the result, in pixels.
    • Width (number)-the width of the result, in pixels.
Return


An image of the format specified in the option parameter. (as can be seen from this title, it is actually)





Svg Expo.Svg()


A set of drawing primitives, such as Circle,rect,path,clippath and polygon. It supports most SVG elements and attributes. The implementation is provided by REACT-NATIVE-SVG and documents are provided in the repository.


import React, { Component } from ‘react‘;
import { View, StyleSheet } from ‘react-native‘;
import { Constants, Svg } from ‘expo‘;

export default class App extends Component {
  render() { return ( <View style={styles.container}>
        <Svg height={100} width={100}>
          <Svg.Circle
            cx={50}
            cy={50}
            r={45}
            strokeWidth={2.5}
            stroke="#e74c3c" fill="#f1c40f" />
          <Svg.Rect
            x={15}
            y={15}
            width={70}
            height={70}
            strokeWidth={2}
            stroke="#9b59b6" fill="#3498db" />
        </Svg>
      </View> );
  }
} const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: ‘center‘,
    justifyContent: ‘center‘,
    paddingTop: Constants.statusBarHeight,
    backgroundColor: ‘#ecf0f1‘,
  },
});


This code runs the effect:









This chapter at the end of the Sqlite,expo is a good integration of SQLite, what is SQLite? is a mobile phone built-in database, a good use of sqlite, you can create a great app


Sqlite


The module provides a database that can be queried by a similar Websql API. The database persists between the restart of the application.



Here's a simple demo. I myself also have a project on the use of SQLite.


Expo.SQLite.openDatabase(name, version, description, size)


Open a database, create it, if it does not exist, and return a database object.


Parameters


Name (string)-the name of the database file to open.



The version, description, and size parameters are ignored but accepted by the function to be compatible with the WEBSQL specification (but is accepted by the function for compatibility with the WEBSQL specification.).


Return


Returns a database object, as described below.


Database Objects (DatabaseObjects


The database object returns Expo.SQLite.openDatabase ()by calling. Such an object represents a connection to a database on the device. They support a method:



Db.transaction (callback, error, success)



Executes a database transaction.


Parameters
    • Callback)-a function that represents the transaction to be executed. Use a transaction (see below) as the unique parameter on which you can add SQL statements to execute.
    • Error (function))-Call it if you have errors in handling this transaction. Take a single parameter that describes the error.
    • Success (function)-called when a transaction finishes executing on the database.
Object of Things (TransactionObjects


The transaction object is passed as a parameter to the callback parameter of the Db.transaction () method on the database (see above). It allows queued SQL statements to be executed in the database transaction. It supports one method:



Tx.executesql (SQLStatement, arguments, success, error)



Queues the SQL statement to execute in the transaction. strongly recommended for authors to use? The placeholder feature of this method avoids SQL injection attacks and does not immediately build SQL statements. ( note here )


Parameters
    • SQLStatement (String)-the string that contains the database query to execute, expressed as SQL. The string might contain? placeholder, which lists the values to replace in the parameter parameter.
    • Arguments (array) parameters (arrays)-to replace?? An array of values (numbers or strings)? placeholder in the SQL statement.
    • Success (function) Success-called when the query completes successfully during transaction processing. Takes two parameters: the transaction itself and a ResultSet object (see below) and the results of the query.
    • Error (function)-Called when an error occurs while executing this particular query in a transaction. Takes two parameters: the transaction itself and the Error object.
ResultSet Object


The ResultSet object is returned by the second parameter of the successful callback of the transaction's Tx.executesql () method (see above). They have the following forms:


 
{
  insertId,
  rowsAffected,
  rows: {
    length,
    item(),
    _array,
  },
}
    • Insertid (number)-The row ID of the row inserted by the SQL statement that inserted the database.
    • Rowsaffected-The number of rows that the SQL statement changed.
    • Rows.length-the number of rows returned by the query.
    • Rows.item (function)-Rows.item (index) returns the row with the given index. If there is no such row, NULL is returned.
    • Rows.array (Number_)-The actual row array returned by the query. You can use it directly instead of getting rows through Rows.item ().


The next one to continue the introduction, this article mainly introduces: Expo SDK API Util (the Expo comes with the tool Class), Tacksnapshotasync,svg,sqlite , you are welcome to pay attention to my public number, this article is approved by everyone, my measure is the public The number of fans grew. Welcome to reprint, but must keep my blog link!









Expo Big Battle (27)--expo SDK API Util (Expo comes with the tool class), Tacksnapshotasync,svg,sqlite


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.