Skip to content

A bridge between JS thread and native widget, initially created for sharing data and communication with ios 14 widget

License

Notifications You must be signed in to change notification settings

valleyelectronics/react-native-widget-bridge

 
 

Repository files navigation

react-native-widget-bridge

A bridge between JS thread and native widget, initially created for sharing data and communication with ios 14 widget

Currently, it's support ios 14 Android will be supported soon

Installation

npm install react-native-widget-bridge

Usage

import WidgetBridge from "react-native-widget-bridge";

const result = await WidgetBridge.multiply(3, 7);

// Always ensure that suite was ready to read/write before interact with it
const success: Bool = await WidgetBridge.ensureUserDefaultsSuit(
  "group.my.exampe.com"
);

// If suite has been ready, write to UserDefaults suite
const success: Bool = await WidgetBridge.setDict("MyDictA", {
  a: 1,
  b: 2,
  foo: "bar",
});
const dict: object = await WidgetBridge.getDict("MyDictA");
const success: Bool = await WidgetBridge.removeObject("MyDictA");

const success: Bool = await WidgetBridge.setString(
  "MyStringB",
  "This is a test string"
);
const str: String = await WidgetBridge.getString("MyStringB");
const success: Bool = await WidgetBridge.removeObject("MyStringB");

// Reload widget timeline after your's UserDefaults data was changed
const myWidgetKind = "my_widget";
WidgetBridge.reloadWidget(myWidgetKind);

// You can also reload all widgets
WidgetBridge.reloadAllWidgets();

You can get the myWidgetKind by looking into your widget entry file:

@main
struct my_widget: Widget {
   let kind: String = "my_widget"
   ...
}

Contributing

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

License

MIT

About

A bridge between JS thread and native widget, initially created for sharing data and communication with ios 14 widget

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 24.3%
  • Java 24.3%
  • Swift 18.7%
  • Ruby 16.1%
  • TypeScript 5.5%
  • JavaScript 5.5%
  • Other 5.6%