Skip to content

Create, update and handle intents from Android notifications with progress bar in React Native.

Notifications You must be signed in to change notification settings

xwlabs99/react-native-download-notification

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-download-notification

Create, update and handle intents from Android notifications with progress bar in React Native.

Instalation

npm install rodriguezmartin/react-native-download-notification --save

Usage

// First import it
import  DownloadNotification  from  'react-native-download-notification';

// Create the function which will be called when the notification is tapped
intentHandler(intent){
  // intent is a String, depending on the notification state could be:
  //   'cancel' if download is on going
  //   'open' if it is set to completed
  //   'dismiss' if the user dismisses it
  if(intent === 'cancel'){
    // a reference of the notification tapped is binded
    this.setStateCancelled();
  }
}

// Create a notification
const notification = await DownloadNotification.create(
  'Document.pdf', // The notification title
  this.intentHandler // The intentHandler function created above
);

// Update the progress
notification.updateProgress(progress); // int from 0 to 100

// Set the finished state
notification.setStateCompleted();
notification.setStateCancelled();
notification.setStateFailed();

Customization

// You can globally customize the icon and labels of the notifications.
componentDidMount(){
  DownloadNotification.setup({
    icon: 'ic_launcher', // Default is the 'get_app' material icon.
    downloadingLabel: 'Downloading...', // Default is 'Downloading' 
    completedLabel: 'The download is complete', // Default is 'Download Completed'
    failedLabel: 'The download has failed', // Default is 'Download Failed'
    cancelledLabel: 'The download has been cancelled' // Default is 'Download Cancelled'
  });
}

About

Create, update and handle intents from Android notifications with progress bar in React Native.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 84.1%
  • JavaScript 15.9%