react-native-app-shortcuts
react-native-app-shortcuts copied to clipboard
Fix "Max number of dynamics shortcuts exceed" error & add a few features
- We we try to set more than 1 app shortcut, the app returns a red screen with the error : "Max number of dynamics shortcuts exceed".
This should not be the case anymore because we now make sure to not exceed the shortcutManager.getMaxShortcutCountPerActivity 👍
-
ShortcutInfo.Buildersupports asetRankmethod, which could be pretty handy in some use cases. This PR adds the support of anorderproperty inside theRNAppShortcuts.addShortcut()method. Thus, we are able to set the shortcuts order dynamically for instance, and do something like this:
import React from 'react'
import RNAppShortcuts from 'react-native-app-shortcuts'
...
export class Example extends React.Component {
state = {
appShortcuts: [
{
id: '/app/search',
shortLabel: 'Search',
longLabel: 'Search somthing',
iconFolderName: 'drawable',
iconName: 'search',
order: 2, // Could also be based on some custom logic
},
{
id: '/app/article/new',
shortLabel: 'New',
longLabel: 'New article',
iconFolderName: 'drawable',
iconName: 'pen',
order: 0,
},
{
id: '/app/notifications',
shortLabel: 'Notifs',
longLabel: 'Notifications',
iconFolderName: 'drawable',
iconName: 'clock',
order: 1,
},
]
}
// Will generate shortcuts: 'Search' -> 'Notifications' -> 'New Article' (from top to bottom)
_createDynamicAppShortcuts = () =>
this.state.data.map(shortcut => AppShortcuts.addShortcut(shortcut))
render() {
this._createDynamicAppShortcuts()
return (
...
)
}
}
- From now on,
react-native-app-shortcutsis also able to redirect the user to theMainActivitywhen the back button is pressed right after using a shortcut. The previous behaviour was leaving the app.