Giter VIP home page Giter VIP logo

react-native-app-shortcuts's Introduction

react-native-app-shortcuts

Introduction

Library for creating Android App Shortcuts in React Native.

Google Official intro for App Shortcuts

If your app targets Android 7.1 (API level 25) or higher, you can define shortcuts to specific actions in your app. These shortcuts can be displayed in a supported launcher. Shortcuts let your users quickly start common or recommended tasks within your app.

Requirements

  • Android SDK version >= 25
  • React Native >= 0.40

Getting started

$ npm install react-native-app-shortcuts --save

Mostly automatic installation

$ react-native link react-native-app-shortcuts

Manual installation

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import com.rnas.RNAppShortcutsPackage; to the imports at the top of the file
  • Add new RNAppShortcutsPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-app-shortcuts'
    project(':react-native-app-shortcuts').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-app-shortcuts/android')
    
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-app-shortcuts')
    
  3. Make sure the android sdk version specify to >= 25 in android/app/build.gradle:
  android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        applicationId "com.test"
        minSdkVersion 16
        targetSdkVersion 25
    }

Usage

Import the package

import RNAppShortcuts from 'react-native-app-shortcuts';

Add and update App Shortcut

Add App Shortcut

RNAppShortcuts.addShortcut({
  id: 'id1',
  shortLabel: 'sample',
  longLabel: 'sample label',
  iconFolderName: 'drawable',
  iconName: 'icon'
})

Update App Shortcut

RNAppShortcuts.updateShortcut({
  id: 'id1',
  shortLabel: 'updated',
  longLabel: 'updated label',
  iconFolderName: 'drawable',
  iconName: 'icon'
})

Options Meaning

Name Type Description
id String Id of the shortcut.
shortLabel String Short label for the shortcut.
longLabel String Long label for the shortcut.
iconFolderName String Folder name of the shortcut's icon. For example, if the icon is in ./android/app/src/res/drawable folder of your prject, you should use 'drawable' here.
iconName String Name of the icon, without extension name.

Remove App ShortCut

Remove specify shortcut

You can remove a shortcut just by passing the id into RNAppShortcuts.removeShortcut.

RNAppShortcuts.removeShortCut('id')

Remove all shortcuts

RNAppShortcuts.removeAllShortCuts()

Check the existence of the Shortcut

Set the id of the parameter of RNAppShortcuts.exists.

RNAppShortcuts.exists('id').then(function() {
  // Exists
}).catch(function(err) {
  // Not exists
})

Handle App Shortcut

RNAppShortcuts.handleShortcut will trigger after you click the shortcut. And you will get the id of the shortcut here.

RNAppShortcuts.handleShortcut(function(id) {
  // Do anything you want. Just like navigate to specify page by the id and so on.
})

react-native-app-shortcuts's People

Contributors

ahmedfeyzi avatar ehesp avatar jkomyno avatar lokyoung avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.