Skip to content

RobinBobin/react-native-common-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a collection of useful classes for RN projects.

  1. Installation.
  2. Package contents.
  3. Version history.

Install with:

npm i react-native-common-utils 

For RN < 0.60:

react-native link react-native-common-utils 

needs to be executed, if you want to use the native modules defined in my package.

  1. ApplicationSession
  2. EventHandlingHelper
  3. NativeEventEmitterWrapper
  4. Native modules
  5. StaticUtils

Warning: These native modules are currently implemented only for Android. I'll implement them for iOS once… I hope…

  1. ShareData
  2. GetPath

Shares arbitrary data.

import { ShareData } from "react-native-common-utils"; 
  • deleteTempFiles()

    Invoke to delete the temp files created internally by the module.

     ShareData.deleteTempFiles(); 
  • send()

    Shares data returning a Promise.

    If you specify an attachment, one of "base64", "path", "uri" must be specified, otherwise the promise will be rejected with the code "ERROR_NO_SRC_TO_COPY".

    A temp file with the content being sent is created for each attachment. If the directory where a temp file is to be created is unavailable, the promise is rejected with the code "ERROR_NO_TEMP_FILE_DST". If a temp file fails to be created, the promise is rejected with the code "ERROR_TEMP_FILE_CREATE".

    Please, bear in mind that these temp files can't be deleted automatically so consider using ShareData.deleteTempFiles().

     const options = { mime: String, // One of the mime types. Default: "*/*". to: String / [String], // "to" address(es). Default: undefined. cc: String / [String], // "cc" address(es). Default: undefined. bcc: String / [String], // "bcc" address(es). Default: undefined. subject: String, // The email subject. Default: null. text: String, // The body of the email. Default: undefined. html: String, // The body of the email. Can contain html. Default: undefined. attachments: [{ fileName: String, // The name of an attachment, as seen by a recipient of the email. Default: uuid. fileExtension: String, // The extension of an attachment, as seen by a recipient of the email. Default: "". base64: String, // Base64 encoded string with the content of an attachment. Default: undefined. path: String, // Path to a file to send as an attachment. Default: undefined. uri: String, // Uri pointing to a file to send as an attachment. Default: undefined. }], createChooser: Boolean, // Android only. Whether to use Intent.createChooser(). Default: true. chooserTitle: String // Android only. Title for the chooser. Default: null. }; ShareData.send(options); 

Gets the path/uri of the specified file.

import { GetPath } from "react-native-common-utils"; 
  • get()

    This function returns a Promise resolving to the path/uri of the specified file. "pathType" must be one of:

    Value Meaning
    "DB" The file is a db file.

    The promise is rejected with the code "Invalid path type" if pathType is invalid.

     const options = { pathType: String, // The file path type. This parameter must be specified. fileName: String, // The file name. Default: "". fileExtension: String // The file extension. Default: "". }; GetPath.get(options); 

A collection of different static utility methods extending StaticUtils from simple-common-utils.

import { StaticUtils } from "react-native-common-utils"; 
  • spinkitColor()

    Taking an RGBA value, returns a string of the form #rrggbb (as react-native-spinkit recognizes).

     StaticUtils.spinkitColor(10); // #000000 StaticUtils.spinkitColor(0xFF487210); // #ff4872 
  • getLocaleId()

    Gets the current locale id.

     StaticUtils.getLocaleId(); // GB 
Version number Changes
v8.0.0 1. Many modules removed.
2. The package depends only on simple-common-utils@^2.2.0.
v7.2.1 @react-native-community -> @react-native-async-storage for async-storage
v7.2.0 EventHandlingHelper.invokeListeners(): all the arguments are passed to inner listeners, not only data.
v7.1.1 1. AsyncStorage wasn't imported as a default object.
2. @react-native-community/async-storage is made a peer dependency.
v7.1.0 AsyncStorage imported from @react-native-community/async-storage.
v7.0.1 react-native-localization moved to peerDependencies.
v7.0.0 Backwards-incompatible changes:
1. ListViewHelper / styles.listView removed.
2. AlterStyles removed.
3. core-decorators and @autobind are no longer used.
v6.0.1 1. AlterStyles deprecated in favour of combineStyles() from react-native-common-ui-components/js/styles.js.
2. @babel/plugin-proposal-decorators is specified as a dev dependency and the postinstall script is deleted.
v6.0.0 1. The latest version of react-native-localization is specified in package.json.
2. Backwards-incompatible change in strings.js: strings.formatString() is no longer available if a sub-object name was specified. strings.all.formatString() has to be used instead.
v5.1.0 1. An iOS-only bug fixed in ApplicationSession.manage().
2. State changes can be optionally logged to the console. An argumentApplicationSession._setSessionType()
v5.0.0 Backwards-incompatible change: styles.screen is superseded by styles.screen.container.
v4.1.0 1. ApplicationSession added.
2. styles.screen added.
v4.0.0 Backwards-incompatible change: babel-plugin-transform-decorators-legacy is removed from dependencies to allow for Babel 7 usage. End user instructions are given through the postinstall event.
v3.3.1 Preferences.Data.
v3.2.1  
v3.2.0 Added the JSONPreference class to store JSON objects as strings.
v3.1.0  
v3.0.0 1. Backwards-incompatible change: when using react-native-common-ui-components, styles must be imported from react-native-common-ui-components/js/styles.
2. AlterStyles.combineEx() added.
3. Readme updated.
v2.1.1 Readme updated.
v2.1.0 1. Readme updated.
2. ListViewHelper.setEmptyItemsRenderer() is added.
v2.0.2 Invalid imports fixed.
v2.0.1 client-side-common-utils deprecated; switched to simple-common-utils.
v2.0.0 Backwards-incompatible changes:
1. UI Components moved to react-native-common-ui-components.
2. Google Drive API wrapper moved to react-native-google-drive-api-wrapper.
3. SQL query builder moved to simple-sql-query-builder.
4. ArrayStringifier, DottedStringObject and utf8 moved to client-side-common-utils.
v1.0.11 1. Readme updated.
2. react-native-extended-stylesheet and react-native-localization specified as dependencies.
v1.0.6 - v1.0.10 Readme updated.
v1.0.5 1. Readme updated.
2. Components/Button: arbitrary children supported.
v1.0.2 - v1.0.4 Readme updated.
v1.0.1 Readme added.
v1.0.0 Initial release.


Written with StackEdit.

About

Common utils for RN projects.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published