0.1.6 • Published 4 years ago

@hiredchina/react-native-shortcut-badge v0.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

react-native-shortcut-badge

Badge for the shortcut icon in your React Native App (Android & iOS).

iOS have native support for badges and this library uses the React Native PushNotificationIOS module.

In Android, this is a wrapper for the amazing ShortcutBadger library.

ShortcutBadger is included in many notification libraries for React Native, rn-shortcut-badge offers an API and updates that do not depend on any of these libraries, although it can present the same drawbacks (before Android 8 there is no native support for badges, in Android 8 and later the badge is defined by the notifications).

NOTE: This is Work In Progress, not fully tested.

Setup

$ yarn add react-native-shortcut-badge
$ react-native link react-native-shortcut-badge

If you are using Proguard, add this to your android/app/proguard-rules.pro

See https://github.com/leolin310148/ShortcutBadger/issues/46

-keep class me.leolin.shortcutbadger.impl.** { <init>(...); }

Usage

import ShortcutBadge from 'react-native-shortcut-badge';

ShortcutBadge.getCount((count) => {
    ShortcutBadge.setCount(count + 1);
});

Properties

PropertyTypeDescription
launcherstring or nullName of the current launcher "home", or null if the launcher could not be detected.
supportedbooleanDoes ShortcutBadge have support for the current launcher/device?

NOTE: The counter remains in the storage of the device even if the launcher is not supported.

Methods

  • setCount(count: number) => Promise<boolean>

    Set the counter and update the badge.

    Returns true if the operation succeeds.

  • getCount() => Promise<number>

    Returns the badge counter.

  • requestPermission(): Promise<boolean>

    Request permission for Badge, mainly for iOS.

    Return true if permission is granted.

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0-beta.2

4 years ago