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
- 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)
+ }
}
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
}
});
MIT