npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-notification-channels

v0.3.0

Published

A package for react-native consisting of native android helper functions to create Notification channels.

Downloads

753

Readme

React Native Notification Channels (Android 8+)

A package for react-native consisting of native android helper functions to create Notification channels.

iOS | Android ------------- | ------------- ❌ | ✅

Screenshot_1669532032 Screenshot_1669532041

Installation

npm install react-native-notification-channels

Usage

import NotificationChannels, { 
  CHANNEL_IMPORTANCE 
} from "react-native-notification-channels";

// ...

async function configChannels() {

  let channelExists = await NotificationChannels.channelExists('my_new_channel')
  if (channelExists) {
    NotificationChannels.deleteChannel('my_new_channel')
    console.log('my_new_channel was deleted')
  }
  
  const list = await NotificationChannels.listChannels()
  console.log('channel list:', list)

  const groupCreated = await NotificationChannels.createChannelGroup(
    'my_new_group', 'Personal Only'
  )
  console.log('groupCreated', groupCreated)
  
  const channelCreated = await NotificationChannels.createChannel({
    channelId: 'my_new_channel',
    channelName: 'Important Notifications',
    channelDescription: 'A notification channel which will receive all the important notifications from this app',
    importance: CHANNEL_IMPORTANCE.IMPORTANCE_HIGH,
    groupId: 'my_new_group' // optional
  })
  console.log(channelCreated ? "Channel created" : "Failed to create channel")
}

useEffect(() => {
  configChannels()
}, []);

// ...

Methods

createChannel()

Creates a new channel if a channel with the given channelId does not exist. Pass an object of following properties:

| property | description | example | ------------- | ------------- | ------------- | | channelId | a unique identifier for channel | 'my_new_channel' | | channelName | a name to display in app notification settings | 'Reminders' | | channelDescription | a description to display in app notification settings | 'This channel will receive blah blah blah...' | | importance | to set importance level of channel notifications | see below for details | | groupId | a unique id for a group (that was already created using createChannelGroup method), if you want to associate the group with the channel | 'my_new_group' |

listChannels()

Returns a list of channels available.


async function configChannels() {
  const list = await NotificationChannels.listChannels()
  console.log(list)
}

channelBlocked(channelId)

Returns a boolean true if a channel with provided id is blocked, otherwise false

channelExists(channelId)

Returns a boolean true if a channel with provided id already exists, otherwise false

deleteChannel(channelId)

Deletes a channel with given id, if exists, and returns a boolean

createChannelGroup(groupId, groupName)

Creates groups for all your channels to be sorted within, with given name, and returns a boolean

Channel Importance

| importance | sound | vibrate | status bar | drawer | heads up | | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- | | IMPORTANCE_DEFAULT | ✅ | ❌ | ✅ | ✅ | ❌ | | IMPORTANCE_HIGH | ✅ | ✅ | ✅ | ✅ | ✅ | | IMPORTANCE_LOW | ❌ | ❌ | ✅ | ✅ | ❌ | | IMPORTANCE_MIN | ❌ | ❌ | ❌ | ✅ | ❌ |

Read more here: https://developer.android.com/training/notify-user/channels

Motivation

The @react-native-firebase/messaging library provided a way to create channels in their older versions but they dropped it and refer to another library called Notifee which is paid and have great many features for notifications.

Also, there is another library react-native-push-notification which does provide these features but if you use rn-firebase, then this library is a bit heavy to add if you just need something to handle channel management on android.

And of course channel management is a crucial task because the default channel created by rn-firebase, has a weird name "Miscellaneous" and also it has "sound" disabled by default so unless the user enables sound and vibration by going to notification settings, it just doesn't work if you need them to make a sound.

Of course, you can add some metadata about the channel in the manifest and change the channel config, but still, if you need to handle multiple channels, this is a good lightweight package for you.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT