Skip to content

Fix "Max number of dynamics shortcuts exceed" error & add a few features #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

CharlesMangwa
Copy link

@CharlesMangwa CharlesMangwa commented Sep 9, 2017

  1. 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".

Screenshot of the Max number of dynamics shortcuts exceed error on Android

This should not be the case anymore because we now make sure to not exceed the shortcutManager.getMaxShortcutCountPerActivity 👍

  1. ShortcutInfo.Builder supports a setRank method, which could be pretty handy in some use cases. This PR adds the support of an order property inside the RNAppShortcuts.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 (
        ...
      )
    }
  }
  1. From now on, react-native-app-shortcuts is also able to redirect the user to the MainActivity when the back button is pressed right after using a shortcut. The previous behaviour was leaving the app.

1. We we try to set more than 1 app shortcut, the app returns a red screen [Max number of dynamics shortcuts exceed](https://goo.gl/LdmqTm). This should not be the case anymore 👍

2. ShortcutInfo.Builder supports a `setRank` method, which could be pretty handy in some use cases. This PR adds the support of an `order` property inside the `RNAppShortcuts.addShortcut()` method. Thus, we are able to set the shortcuts order dynamically for instance, and do something like this:

```js
  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,
        },
        {
          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: 'New Article' -> 'Notifications' -> 'Search' (from top to bottom)
    _createDynamicAppShortcuts = () =>
      this.state.data.map(shortcut => AppShortcuts.addShortcut(shortcut))

    render() {
      this._createDynamicAppShortcuts()
      return (
        ...
      )
    }
  }
```
@CharlesMangwa CharlesMangwa changed the title Fix "Max number of dynamics shortcuts exceed" error & add order feature Fix "Max number of dynamics shortcuts exceed" error & add a few features Sep 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant