• This repository has been archived on 15/Apr/2023
  • Stars
    star
    1,056
  • Rank 43,682 (Top 0.9 %)
  • Language
    Java
  • License
    MIT License
  • Created about 9 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A react-native interface for Touch 3D home screen quick actions

React Native Quick Actions

Support for the new 3D Touch home screen quick actions for your React Native apps!

This project currently supports iOS 9+ and Android 7

Installing

$ yarn add react-native-quick-actions
$ react-native link react-native-quick-actions

Additional steps on iOS

Add the following lines to your AppDelegate.m file:

#import "RNQuickActionManager.h"

// @implementation AppDelegate

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

// @end

Manual Linking on Android

Add the following to app/build.gradle within the dependencies { ... } section

implementation project(':react-native-quick-actions')

Add import com.reactNativeQuickActions.AppShortcutsPackage; to your MainApplication.java

Also add new AppShortcutsPackage() within the

public List<ReactPackage> createAdditionalReactPackages() {
  return Arrays.<ReactPackage>asList(
    ...
  );
}

section of MainApplication.java

Usage

Adding static quick actions - iOS only

Add these entries into to your Info.plist file and replace the generic stuff (Action Title, .action, etc):

<key>UIApplicationShortcutItems</key>
<array>
  <dict>
    <key>UIApplicationShortcutItemIconType</key>
    <string>UIApplicationShortcutIconTypeLocation</string>
    <key>UIApplicationShortcutItemTitle</key>
    <string>Action Title</string>
    <key>UIApplicationShortcutItemType</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER).action</string>
  </dict>
</array>

A full list of available icons can be found here:

https://developer.apple.com/design/human-interface-guidelines/ios/icons-and-images/system-icons/#quick-action-icons

Adding dynamic quick actions

In order to add / remove dynamic actions during application lifecycle, you need to import react-native-quick-actions and call either setShortcutItems to set actions or clearShortcutItems to clear.

import QuickActions from "react-native-quick-actions";

QuickActions.setShortcutItems([
  {
    type: "Orders", // Required
    title: "See your orders", // Optional, if empty, `type` will be used instead
    subtitle: "See orders you've made",
    icon: "Compose", // Icons instructions below
    userInfo: {
      url: "app://orders" // Provide any custom data like deep linking URL
    }
  }
]);

NOTE Currently android only supports a url key in userInfo. No other keys are supported. See #93 for more information.

To clear actions:

QuickActions.clearShortcutItems();

Icons

iOS

On iOS you can use the default icons provided by Apple, they're listed here: https://developer.apple.com/design/human-interface-guidelines/ios/icons-and-images/system-icons/#quick-action-icons

You can also use custom icons creating new Image set inside Image.xcassets on XCode. You'll need to define the 1x, 2x and 3x sizes.

Android

On Android you'll need to create an image file (use PNG) inside android/app/src/main/res/drawable.

Name the image with underscores, don't use hyphens.

Listening for quick actions

First, you'll need to make sure DeviceEventEmitter is added to the list of requires for React Native.

import { DeviceEventEmitter } from "react-native";

Use DeviceEventEmitter to listen for quickActionShortcut messages.

DeviceEventEmitter.addListener("quickActionShortcut", data => {
  console.log(data.title);
  console.log(data.type);
  console.log(data.userInfo);
});

To get any actions sent when the app is cold-launched using the following code:

import QuickActions from "react-native-quick-actions";

function doSomethingWithTheAction(data) {
  console.log(data.title);
  console.log(data.type);
  console.log(data.userInfo);
}

QuickActions.popInitialAction()
  .then(doSomethingWithTheAction)
  .catch(console.error);

Please note that on Android if android:launchMode is set to default value standard in AndroidManifest.xml, the app will be re-created each time when app is being brought back from background and it won't receive quickActionShortcut event from DeviceEventEmitter, instead popInitialAction will be receiving the app shortcut event.

Check if 3D Touch is supported

The following function will alert you if the user's device supports 3D Touch. Please note this project currently only supports iOS 9+ which means this code will not work on iOS devices running versions < 9.0.

import QuickActions from "react-native-quick-actions";

QuickActions.isSupported((error, supported) => {
  if (!supported) {
    console.log("Device does not support 3D Touch or 3D Touch is disabled.");
  }
});

License

Copyright (c) 2015 Jordan Byron (http://github.com/jordanbyron/)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

react-native-event-source

A react-native interface for EventSource: Server-Sent Events for iOS and Android
JavaScript
142
star
2

prawn-labels

Prawn/Labels: A simple helper to generate labels for Prawn PDFs
Ruby
91
star
3

thecookbook

Free, open source recipe tracking application
Ruby
25
star
4

house_control

React Native port of my sinatra based alarm_keypad project
JavaScript
23
star
5

mission_of_mercy

Software for Mission of Mercy Clinics
Ruby
20
star
6

capistrano_confirm_branch

Requires confirmation before switching deployed branches using capistrano
Ruby
6
star
7

reactize-selectize

React wrapper for Selectize.js
JavaScript
6
star
8

spot_the_baddy

Bohconf Madness!
Ruby
4
star
9

lists

Create and share lists with friends and family
Ruby
3
star
10

comcast_vm

Ruby API for Comcast's Digital Voice Site
Ruby
1
star
11

gradapp

My first rails app - Graduate Applicant Tracking
Ruby
1
star
12

minecrafter

A simple Sinatra app to stop and start my minecraft server on AWS
CSS
1
star
13

alarm_decoder

Ruby
1
star
14

neo

Hacked script to play Red Dirty Ruby Conf's matrix game
Ruby
1
star
15

steamer

Simple ruby class that checks the status of a steam community user
Ruby
1
star
16

momentum-invoicer

Invoice generator for madriska momentum
Ruby
1
star
17

nhsmb

Website for the Naugatuck Highschool Marching Band
Ruby
1
star
18

snow_watchr

Scrapes a CT news station's snow closings webpage for specific terms and prints them to the console and sends them to your phone via prowl.
Ruby
1
star
19

react-native-quick-actions-demo

Demo app for react-native-quick-actions
Objective-C
1
star
20

prabums

Work order submission & tracking for Bob
Ruby
1
star
21

jordanbyron.com

New site design
JavaScript
1
star
22

wedding

CSS
1
star
23

FARTLEKer

Sinatra app that sends prowl messages to your phone for FARTLEK training runs
Ruby
1
star
24

dotfiles

Vim Script
1
star
25

scsu_info_finder

iPhone Information Finder Prototype for SCSU's CSC 334
Ruby
1
star
26

irc_watchr

IRC bot that sends a prowl message when a message is sent
Ruby
1
star
27

Tea-Timer

A simple tea timer for Mac OS X to remind you when your tea is done. Because no one likes cold tea.
Ruby
1
star
28

vistr

Ruby API for Blackboard Vista
Ruby
1
star