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

@iroomit/react-native-in-app-notification

v1.0.1

Published

A simple dropdown notification view for React Native that imitates a push notification for while the app is open. Can be called anywhere throughout your React Native application.

Downloads

8

Readme

React Native In-App Notification (@iroomit/react-native-in-app-notification)

License: MIT Version

This library provides a simple interface for showing push notification-like messages throughout your React Native app on iOS and Android while it is in the foreground. Fully written in JS (TypeScript), no external libraries needed.

✅ No additional libraries/imports (Pure JS)

✅ Implemented in TypeScript/Full TypeScript Support

Used in production for the in-app messaging portion of iROOMit Roommates & Rooms for Rent Finder iOS & Android app.

Features

✅ Animates in/out from top of screen

✅ Custom title and message preview

✅ Optional image preview

✅ Drag up to close

✅ onPress functionality for each notification

✅ Customizable styles

Installation

Install the package by running:

npm install @iroomit/react-native-in-app-notification

or

yarn add @iroomit/react-native-in-app-notification

Usage

Getting Started

You must wrap the root of your app in your App.js or App.tsx file with <InAppNotificationProvider />:

...

import { InAppNotificationProvider } from '@iroomit/react-native-in-app-notification';

const App = () => {

    return (
        <InAppNotificationProvider>
            <View>
                ...
            </View>
        </InAppNotificationProvider>
    )
}

...

Use in Functional Components

To display a notification from any functional component within your application, you can use the useInAppNotification() hook to get access to the showNotification(...) and dismissAll() methods:

...

import { useInAppNotification } from '@iroomit/react-native-in-app-notification';

const MyButton = () => {
    const { showNotification } = useInAppNotification();

    return (
        <TouchableOpacity onPress={() => {

            showNotification("My Title", "My notification text can go here", "https://mydomain.com/myimage.png", {
                onPress: () => console.log('Notification pressed!')
            });
            
        }}>
            ...
        </TouchableOpacity>
    )
}

...

Use in Class Components

You can wrap your class component definition with the withInAppNotification(...) higher-order component function to access the inAppNotification prop that provides showNotification(...) and dismissAll() methods:

...
import React from 'react';
import { withInAppNotification } from '@iroomit/react-native-in-app-notification';

export default withInAppNotification(class MyButton extends React.Component {
    constructor(props) {
        super(props);
    }

    render() {

        return (
            <TouchableOpacity onPress={() => {

                this.props.inAppNotification.showNotification("My Title", "My notification text can go here", "https://mydomain.com/myimage.png", {
                    onPress: () => console.log('Notification pressed!')
                });
                
            }}>
                ...
            </TouchableOpacity>
        )
    }
});
...

API Reference

InAppNotificationProvider: Component

Props

  • titleTextStyle (optional): A style prop that defines the text style for the notification title.
  • messageTextStyle (optional): A style prop that defines the text style for the notification message.
  • thumbnailStyle (optional): A style prop that defines the style for the notification thumbnail image.

showNotification(title: string, message: string, imgUrl?: string, options?: InAppNotificationOptions): Function

This function adds a notification to the queue to be shown. By default, one notification is shown every 3 seconds. If there are no more notifications in the queue, the last/only notification in the queue is shown for up to 9 seconds.

  • title and message are required.
  • If imgUrl is not provided, the image preview on the left of the notification is hidden.

InAppNotificationOptions

An optional object to further customize each individual notification. For now, just used to assign a callback for the onPress action.

  • onPress (optional): Function

If onPress is not defined, then the notification shown will not be pressable.

dismissAll(): Function

This function immediately dismisses any visible notifications and clears the queue of any remaining notifications that were to be shown.

Collaboration

While this package is production-ready, we are open to collaboration on new features and bug fixes. We also intend on supporting various kinds of notification styles in the near future.

If you would like to contribute, please open a new issue on GitHub or contact iROOMit.