@rn-bridge/react-native-shortcuts
v0.3.0
Published
React native library for android shortcuts and iOS quick actions which allow users to quickly access specific app functionalities directly from the home screen or app icon.
Downloads
28
Maintainers
Readme
@rn-bridge/react-native-shortcuts
Android Shortcuts and iOS Quick Actions are features that allow users to quickly access specific app functionalities directly from the home screen or app icon, enhancing user experience by providing fast access to common tasks.
Fully compatible with TypeScript.
Example
| Android | iOS | |---|---| | | |
Supported platforms
| Platform | Support | |---|---| | iOS | ✅ | | Android | ✅ | | Web | ❌ | | Windows | ❌ | | macOS | ❌ |
Installation
npm install @rn-bridge/react-native-shortcuts
or
yarn add @rn-bridge/react-native-shortcuts
Setup
iOS
Add the following code to your AppDelegate.m
#import "RNShortcuts.h"
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
[RNShortcuts handleShortcutItem:shortcutItem];
completionHandler(YES);
}
Android
No setup needed
Summary
Methods
| Name | Description |
| --- | --- |
| addShortcut
| Adds the shortcut(android), quick action(ios) for the given details. |
| updateShortcut
| Updates the shortcut or quick action details. |
| removeShortcut
| Removes the specific shortcut. For android in case if the user changes your app shortcut to pinned shortcut, app shortcut will be removed but pinned shortcut will be still visible but in disabled state. This shortcut is no longer valid and is not clickable. |
| removeAllShortcuts
| Removes all the shortcuts. For android in case if the user changes your app shortcuts to pinned shortcuts, app shortcuts will be removed but pinned shortcuts will be still visible but in disabled state. These shortcuts are no longer valid and are not clickable. |
| getShortcutById
| Returns the shortcut details such as id, title, longLabel, subtitle. |
| isShortcutExists
| Returns whether the shortcut is registered with given id. |
| isShortcutSupported
| Returns whether your device supports shortcuts(android), quick actions(ios). |
| getInitialShortcutId
| If the initial app launch was triggered by a shortcut, it will give the id of that shortcut, otherwise it will give null. |
| addOnShortcutUsedListener
| If the app is in background and the app is launchced by a shortcut, it will give the id of that shortcut. |
| removeOnShortcutUsedListener
| Removes the listener. You app no longer receives events. |
Usage
Import
import Shortcuts from '@rn-bridge/react-native-shortcuts';
isShortcutSupported
const response = await Shortcuts.isShortcutSupported() // true or false
| Platform | Supported Version | |---|---| | iOS | >=9.0 | | Android | >=7.1 (API Level 25) |
addShortcut
const response = await Shortcuts.addShortcut({
id: "a426a46b-7389-431c-9ea8-8b370e0c65fc",
title: "Open App",
iconName: "app_shortcut"
})
Response:
{
"id": "a426a46b-7389-431c-9ea8-8b370e0c65fc",
"title": "Open App"
}
Supported options:
| Key | Platform | Required | Description |
| --- | --- | --- | --- |
| id
| Both | Yes | A required, app-specific string that you employ to identify the shortcut. |
| title
| Both | Yes | The required, user-visible title for the Home Screen shortcut. |
| longLabel
| Android | No | An extended phrase that describes the shortcut's purpose. If there's enough space, the launcher displays this value instead of title. When possible, limit this long description to 25 characters. |
| subtitle
| iOS | No | The user-visible subtitle for the Home Screen dynamic quick action. |
| iconName
| Both | No | The icon for the Home Screen shortcut. Icon name should be the name of your iOS asset or Android drawable. Refer iOS Android resource addition. |
updateShortcut
const response = await Shortcuts.updateShortcut({
id: "a426a46b-7389-431c-9ea8-8b370e0c65fc",
title: "Open App",
iconName: "app_shortcut"
})
Response:
{
"id": "a426a46b-7389-431c-9ea8-8b370e0c65fc",
"title": "Open App"
}
Supported options:
| Key | Platform | Required | Description |
| --- | --- | --- | --- |
| id
| Both | Yes | The shortcut id which you want to update. |
| title
| Both | Yes | The required, user-visible title for the Home Screen shortcut. |
| longLabel
| Android | No | An extended phrase that describes the shortcut's purpose. If there's enough space, the launcher displays this value instead of title. When possible, limit this long description to 25 characters. |
| subtitle
| iOS | No | The user-visible subtitle for the Home Screen dynamic quick action. |
| iconName
| Both | No | The icon for the Home Screen shortcut. Icon name should be the name of your iOS asset or Android drawable. Refer iOS Android resource addition. |
removeShortcut
const response = await Shortcuts.removeShortcut("a426a46b-7389-431c-9ea8-8b370e0c65fc") // true or false
Supported options:
| Key | Platform | Required | Description |
| --- | --- | --- | --- |
| id
| Both | Yes | The shortcut id which you want to remove. |
removeAllShortcuts
const response = await Shortcuts.removeAllShortcuts() // true or false
isShortcutExists
const response = await Shortcuts.isShortcutExists("a426a46b-7389-431c-9ea8-8b370e0c65fc") // true or false
Supported options:
| Key | Platform | Required | Description |
| --- | --- | --- | --- |
| id
| Both | Yes | The shortcut id which you want to check. |
getShortcutById
const response = await Shortcuts.getShortcutById("a426a46b-7389-431c-9ea8-8b370e0c65fc") // true or false
Response:
{
"id": "a426a46b-7389-431c-9ea8-8b370e0c65fc",
"title": "Open App",
"longLable": "...",
"subtitle": "..."
}
Supported options:
| Key | Platform | Required | Description |
| --- | --- | --- | --- |
| id
| Both | Yes | The shortcut id which you want to get. |
getInitialShortcutId
If the initial app launch was triggered by a shortcut, it will give the id of that shortcut, otherwise it will give null.
const callback = (id) => {
console.log('Shortcut Id:', id);
};
const id = await Shortcuts.getInitialShortcutId();
addOnShortcutUsedListener
If the app is in background and the app is launchced by a shortcut, it will give the id of that shortcut.
const callback = (id) => {
console.log('Shortcut Id:', id);
};
Shortcuts.addOnShortcutUsedListener(callback);
removeOnShortcutUsedListener
Shortcuts.removeOnShortcutUsedListener();
How To Run Example App ?
To run example app, follow the below steps
- Clone the repository
- Do
yarn install
- Next navigate to example folder i.e
cd example
- Do
yarn install
- Next navigate to ios folder i.e
cd ios
and dopod install
, thencd ..
- For android run
yarn android
- For ios run
yarn ios