Skip to content

retyui/react-native-widget-picker

Repository files navigation

react-native-widget-picker

react-native-widget-picker on npm react-native-widget-picker downloads react-native-widget-picker install size CI status

Let users pin a widget. On devices running Android 8.0 (API level 26) and higher, launchers that let pin widgets onto their home screen

screen-20230811-235340.mp4

Getting started

  • Android only
  • support React Native's New & Old Architecture
yarn add react-native-widget-picker
# or
npm install react-native-widget-picker

Edit android/app/src/main/java/com/.../MainActivity.java and add:

+import com.retyui.widgetpicker.WidgetPickerModuleImpl;

public class MainActivity extends ReactActivity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
+    WidgetPickerModuleImpl.registerWidgetClass("MyAppWidget", MyAppWidget.class);
    // you can register multiple widgets ^^^ 
  }

Kotlin MainActivity.kt example:

+import com.retyui.widgetpicker.WidgetPickerModuleImpl.Companion.registerWidgetClass

class MainActivity : ReactActivity() {
+  override fun onCreate(savedInstanceState: Bundle?) {
+    super.onCreate(savedInstanceState)
+    registerWidgetClass("MyAppWidget", MyAppWidget::class.java)
+  }
}

Usage

import {WidgetPicker} from 'react-native-widget-picker';

WidgetPicker.isRequestPinAppWidgetSupported() // true or false

// "MyAppWidget" - name from MainActivity.java or .kt
WidgetPicker.requestPinAppWidget("MyAppWidget").then((value) => {
    
    if (value.message === "success") {
        // success
    }
});

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published