Code Monkey home page Code Monkey logo

capacitor-quick-actions's Introduction

Capacitor Quick Actions

Plugin for using Quick Actions in your Capacitor Apps.
Now it supports only on iOS/iPadOS 13+.

Install

npm install capacitor-quick-actions
npx cap sync

Preparation

Modify your AppDelegate.swift:

  1. Add import CapacitorQuickActions to the top of the file.
  2. Add application function to the bottom of the file:
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
        let handled = QuickActions.handleQuickAction(shortcutItem)
        completionHandler(handled)
}

Example of the AppDelegate.swift file available here.

Usage

// Import the plugin
import { QuickActions } from 'capacitor-quick-actions';

// Add buttons to the home screen
const addButtonsToHomeScreen = async () => {
    await QuickActions.addQuickActions({
        actions: [
            { id: "button1", title: 'Action1', iconName: 'house', description: 'Description1' },
            { id: "button2", title: 'Action2', iconName: '2' } // Description is optional
        ]
    });
}

// Remove buttons from the home screen
const clearButtonsFromHomeScreen = async () => {
    await QuickActions.clearQuickActions();
}

// Add Listener for the selected action
QuickActions.addListener('quickActionSelected', (data) => {
    console.log('Quick Action selected:', data.type); // returns id of the selected action
});

Icons

To use icons in your quick actions provide the name of the icon from this app.

API

addQuickActions(...)

addQuickActions(options: { actions: QuickAction[]; }) => Promise<void>
Param Type
options { actions: QuickAction[]; }

clearQuickActions()

clearQuickActions() => Promise<void>

addListener('quickActionSelected', ...)

addListener(eventName: 'quickActionSelected', listenerFunc: (data: { type: string; }) => void) => PluginListenerHandle
Param Type
eventName 'quickActionSelected'
listenerFunc (data: { type: string; }) => void

Returns: PluginListenerHandle


Interfaces

QuickAction

Prop Type
id string
title string
iconName string
description string

PluginListenerHandle

Prop Type
remove () => Promise<void>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.