Code Monkey home page Code Monkey logo

react-native-shortcut-badge's Introduction

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 leolin310148/ShortcutBadger#46

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

Usage

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

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

Properties

Property Type Description
launcher string or null Name of the current launcher "home", or null if the launcher could not be detected.
supported boolean Does 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.

react-native-shortcut-badge's People

Contributors

amarcruz avatar makedirectory avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.