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.
npm install @rn-org/react-native-shortcuts ![React Native]() ![Android]() ![iOS]() !RN 0.81.4
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, enhancing user experience by providing fast access to common tasks.
Fully compatible with TypeScript & Turbomodules.
Required React Native Version >=0.72.0
| Android | iOS |
|--------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------|
| |
|
| Platform | Support |
|----------|---------|
| iOS | ✅ |
| Android | ✅ |
| Web | ❌ |
| Windows | ❌ |
| macOS | ❌ |
``sh`
npm install @rn-org/react-native-shortcuts
or
`sh`
yarn add @rn-org/react-native-shortcuts
Add the following code to your
AppDelegate.m`objective-c
#import "RNShortcuts.h"
``objective-c
- (void)application:(UIApplication )application performActionForShortcutItem:(UIApplicationShortcutItem )shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
[RNShortcuts handleShortcutItem:shortcutItem];
completionHandler(YES);
}
`
#### If you are using SwiftAdd the following line to your App's
Bridging-Header.h> [!IMPORTANT]
> A Bridging Header is required in iOS development when you want to use Objective-C code in a Swift project.
> Add your bridging header to Objective-C Bridging Header under Swift Compiler-General (Target -> Build Settings -> Swift Compiler-General -> Objective-C Bridging Header)

`objective-c
#import "RNShortcuts.h"
`Add the following code to your
AppDelegate.swift
`swift
override func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
RNShortcuts.handle(shortcutItem)
completionHandler(true)
}
`$3
No setup needed
Summary
$3
| 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. |
Usage
Import
`javascript
import Shortcuts from '@rn-org/react-native-shortcuts';
`$3
`javascript
const response = await Shortcuts.isShortcutSupported() // true or false
`| Platform | Supported Version |
|----------|----------------------|
| iOS | >=9.0 |
| Android | >=7.1 (API Level 25) |
$3
`javascript
const response = await Shortcuts.addShortcut({
id: "a426a46b-7389-431c-9ea8-8b370e0c65fc",
title: "Open App",
symbolName: "house.fill",
iconName: "app_shortcut"
})
`Response:
`json
{
"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. |
| symbolName | iOS | No | The SF Symbol for the Home Screen shortcut. Symbol name must correspond to an existing SF Symbol. Refer iOS resource addition. |
| 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. |$3
`javascript
const response = await Shortcuts.updateShortcut({
id: "a426a46b-7389-431c-9ea8-8b370e0c65fc",
title: "Open App",
symbolName: "house.fill",
iconName: "app_shortcut"
})
`Response:
`json
{
"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. |
| symbolName | iOS | No | The SF Symbol for the Home Screen shortcut. Symbol name must correspond to an existing SF Symbol. Refer iOS resource addition. |
| 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. |$3
`javascript
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. |$3
`javascript
const response = await Shortcuts.removeAllShortcuts() // true or false
`$3
`javascript
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. |$3
`javascript
const response = await Shortcuts.getShortcutById("a426a46b-7389-431c-9ea8-8b370e0c65fc") // true or false
`Response:
`json
{
"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. |$3
If the initial app launch was triggered by a shortcut, it will give the id of that shortcut,
otherwise it will give null.
`javascript
const id = await Shortcuts.getInitialShortcutId();or
const callback = (id) => {
console.log('Shortcut Id:', id);
};
Shortcuts.getInitialShortcutId().then(callback)
`$3
If the app is in background and the app is launchced by a shortcut, it will give the id of that
shortcut.
`javascript
const listenerSubscription = React.useRef(null);React.useEffect(() => {
const callback = (id: string) => {
console.log('Shortcut Id:', id);
if (id) {
Alert.alert('Shortcut Detected',
App opened with shortcut id: ${id});
}
}; listenerSubscription.current = Shortcuts.addOnShortcutUsedListener(callback);
return () => {
listenerSubscription.current?.remove();
listenerSubscription.current = null;
}
}, [])
`How To Run Example App ?
To run example app, follow the below steps
1. Clone the repository
2. Do
yarn install
3. For androidyarn example android
5. For iOS cd ios and do bundle exec pod install` and run the iOS app from XCode