React Native Springboard Shortcuts
React Native Springboard Shortcuts provides an easy way to create shortcuts to an application when developing in react native.
The shortcuts can deeplink to a specific screen(s) inside your app.
This library take advantage of the native side with a simple API for the JavaScript side. At the moment the library support only shortcuts for Android devices, in the future we may add support for IOS as well.
Requirements
- Android SDK version >=
25
Getting started
$ npm install --save react-native-springboard-shortcuts
Manual installation
Android
- Open up
android/app/src/main/java/[...]/MainApplication.java
- Add
import com.alon.ReactNativeSpringboardShortcuts.RNSpringboardShortcutsPackage;
to the imports at the top of the file - Add
new RNSpringboardShortcutsPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-springboard-shortcuts' project(':react-native-springboard-shortcuts').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-springboard-shortcuts/lib/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:implementation project(":react-native-springboard-shortcuts")
Example
import RNSpringboardShortcuts from 'react-native-springboard-shortcuts';
RNSpringboardShortcuts.isShortcutServiceAvailable((isAvailable: boolean) => {
if (isAvailable) {
const shortcut = {
id: 'shortcut.id.example',
shortLabel: 'Shortcut title',
longLabel: 'Shortcut description',
imageUrl: 'https://someImage.jpg',
intentUri: `myApp://myCoolAppScreen`
};
RNSpringboardShortcuts.exists(shortcut.id).then(() => {
// Exists
RNSpringboardShortcuts.updateShortcut(shortcut);
}).catch((_err: Error) => {
// Not exists
RNSpringboardShortcuts.addShortcut(shortcut);
});
}
});
API
isShortcutServiceAvailable
RNSpringboardShortcuts.isShortcutServiceAvailable((isAvailable: boolean) => {
});
exists
RNSpringboardShortcuts.exists(shortcut.id).then(() => {
// Exists
}).catch((_err: Error) => {
// Not exists
});
addShortcut
RNSpringboardShortcuts.addShortcut(shortcut);
updateShortcut
RNSpringboardShortcuts.updateShortcut(shortcut);
removeShortcut
RNSpringboardShortcuts.removeShortcut(shortcut.id);
removeAllShortcuts
RNSpringboardShortcuts.removeAllShortcuts();
handleShortcut
This function will only work if you did NOT provide an intentUri
to the shortcut.
To use this method for handling shortcuts, copy it to componentDidMount
function of a component/screen which load at the start of your app.
RNSpringboardShortcuts.handleShortcut((shortcutId: string) => {
});
So what are you waiting for, now that you know how to use it, start implementing React Native Springboard Shortcuts in your project today!