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-actions-shortcuts

v1.0.1

Published

iOS Home screen Quick Actions & Android App Shortcuts for react-native

Downloads

7,122

Readme

react-native-actions-shortcuts

iOS Home screen Quick Actions & Android App Shortcuts for react-native

Installation

npm install react-native-actions-shortcuts

Setup

iOS

If you are using cocoapods - you may need to run pod install (from ios directory).

On iOS, Quick Actions are handled by the application:performActionForShortcutItem:completionHandler method of your app's UIApplicationDelegate (i.e. AppDelegate.m), so, you will therefore need to add the following code in your project's AppDelegate.m) file.

- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
    [RNShortcuts performActionForShortcutItem:shortcutItem completionHandler:completionHandler];
}

Android

Android doesn't require any additional setup.

Usage

Example project

See the Example project for a working demo.

Documentation

Imports

// ...
import { NativeEventEmitter } from "react-native";
import Shortcuts from "react-native-actions-shortcuts";

// if using typescript, can also use the 'ShortcutItem' type
import Shortcuts, { ShortcutItem } from "react-native-actions-shortcuts";

// ...

Initial shortcut / action

Get the initial shortcut that the app was launched with. On iOS this will be returned just once, subsequent calls will return null.

const shortcutItem = await Shortcuts.getInitialShortcut();

Listen for shortcut / action invocations

Listen to shortcut / action invocations while app is running.

On iOS the listener is also called for the initial invocation, unless it was already received via Shortcuts.getInitialShortcut().

const ShortcutsEmitter = new NativeEventEmitter(Shortcuts);

// 1. define the listener
function handleShortcut(item) {
    const {type, data} = item;
    // your handling logic
};

// 2. add the listener in a `useEffect` hook or `componentDidMount`
ShortcutsEmitter.addListener("onShortcutItemPressed", handleShortcut);

// 3. remove the listener in a `useEffect` hook or `componentWillUnmount`
ShortcutsEmitter.removeListener("onShortcutItemPressed", handleShortcut);

Set shortcuts

To set shortcuts (will replace existing dynamic actions / shortcuts)

const shortcutItem = {
    type: "my.awesome.action",
    title: "Do awesome things",
    shortTitle: "Do it",
    subtitle: "iOS only",
    iconName: "ic_awesome",
    data: {
        "foo": "bar",
    },
};

Shortcuts.setShortcuts([shortcutItem]);

// you can also `await` to get the current dynamic shortcuts / actions
const shortcutItems = await Shortcuts.setShortcuts([shortcutItem]);

Clear shortcuts

Clears all dynamic shortcuts.

Shortcuts.clearShortcuts();

Get shortcuts

Get the current shortcuts. Some information may be lost, such as iconName, data, etc.

const shortcutItems = await Shortcuts.getShortcuts();

Icons

To display icons with your shortcuts / actions you will need to add them to your project. Once added use the name of your iOS asset or Android drawable as the value for iconName above.

iOS - Asset catalog

Add new assets to your Asset catalog by importing either png (scalar) or pdf (vector) files.

Refer Custom Icons : Home Screen Quick Action Icon Size to learn about the dimensions and design specifications.

Android - drawable

Add drawable resources to you Android project. In Android studio, choose:

  • for vector icons (SVG / PDF): File > New > Vector Asset

  • for scalar icons (PNG): File > New > Image Asset

Refer App Shortcuts: Icon design guidelines to learn about the dimensions and design specifications.

Contributing

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

License

MIT

Attribution

Icons made by Gregor Cresnar from www.flaticon.com