🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

react-native-widget-updater

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-widget-updater

Get information about native widgets and trigger updates from React Native.

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

react-native-widget-updater

Update native home screen and lock screen widgets from JS.

Imagine you want to display an updated entry in your native widget. This package provides the ability to trigger updates.

react-native-widget-updater

Installation

yarn add react-native-widget-updater

or

npm install react-native-widget-updater

Usage

For all the function calls, a widget class name or kind is required. On iOS this will be the kind variable defined in the Widget struct, essentially the name of the widget:

struct WidgetUpdaterExampleWidget: Widget {
  let kind: String = "WidgetUpdaterExampleWidget"

On Android it's the class name which extends the AppWidgetProvider class:

class ExampleAppWidget : AppWidgetProvider()

This needs to prefixed with a dot and becomes .ExampleAppWidget.

Updating widgets

To update a widget from within react, call the updateAppWidgets function and pass the class names of your widgets.

import { updateAppWidgets } from 'react-native-widget-updater';

// Pass the classes of the app widget
const widgetClasses = ['.ExampleAppWidget'];
await updateAppWidges(widgetClasses);

Gathering in use widgets

To gather all in-use widgets from within react, call the getAppWidgetIds function and pass the class names of your widgets.

import { getAppWidgetIds } from 'react-native-widget-updater';

// Pass the classes of the app widget
const widgetClasses = ['.ExampleAppWidget'];
const result = await getAppWidgetIds(widgetClasses);

This will return a map of widget classes and the corresponding OS ids assigned, e.g. the .ExampleAppWidget currently has two instances on the home screen with the ids 18 and 19.

{
    ".ExampleAppWidget": [18, 19]
}

Contributing

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

License

MIT

Keywords

react-native

FAQs

Package last updated on 26 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts