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.
Android | iOS |
---|---|
Platform | Support |
---|---|
iOS | âś… |
Android | âś… |
Web | ❌ |
Windows | ❌ |
macOS | ❌ |
npm install @rn-bridge/react-native-shortcuts
or
yarn add @rn-bridge/react-native-shortcuts
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);
}
No setup needed
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. |
Import
import Shortcuts from '@rn-bridge/react-native-shortcuts';
const response = await Shortcuts.isShortcutSupported() // true or false
Platform | Supported Version |
---|---|
iOS | >=9.0 |
Android | >=7.1 (API Level 25) |
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. |
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. |
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. |
const response = await Shortcuts.removeAllShortcuts() // true or false
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. |
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. |
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();
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);
Shortcuts.removeOnShortcutUsedListener();
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