Skip to content

Hirurgo/react-native-download-notification

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-download-notification

  • Create, update and handle intents from Android notifications with progress bar in React Native.
  • Update to support Oreo+ using lucienbl's fork code
  • Added stop action button and other custom perks (silent notification, title and content text updates and others)

Instalation

yarn add react-native-android-downloading-notifications

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 87.6%
  • JavaScript 12.4%