File tree 2 files changed +22
-5
lines changed
android/src/main/java/com/retyui/widgetpicker
2 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -25,14 +25,31 @@ class WidgetPickerModuleImpl(private val reactContext: ReactApplicationContext)
25
25
@RequiresApi(Build .VERSION_CODES .O )
26
26
fun requestPinAppWidget (widgetClassKey : String , promise : Promise ) {
27
27
try {
28
+ if (isRequestPinAppWidgetSupported().not ()) {
29
+ promise.resolve(Arguments .createMap().apply {
30
+ putString(" message" , " not supported" )
31
+ })
32
+ return
33
+ }
34
+
28
35
val appWidgetManager: AppWidgetManager = reactContext.getSystemService(AppWidgetManager ::class .java)
29
- val myProvider = ComponentName (reactContext, widgets[widgetClassKey]!! )
30
- val result = appWidgetManager.requestPinAppWidget(myProvider, null , null )
31
- if (result){
36
+
37
+ val widgetClass = widgets[widgetClassKey];
38
+
39
+ if (widgetClass == null ) {
40
+ promise.resolve(Arguments .createMap().apply {
41
+ putString(" message" , " widget not found" )
42
+ })
43
+ return
44
+ }
45
+
46
+ val provider = ComponentName (reactContext, widgetClass)
47
+ val result = appWidgetManager.requestPinAppWidget(provider, null , null )
48
+ if (result) {
32
49
promise.resolve(Arguments .createMap().apply {
33
50
putString(" message" , " success" )
34
51
})
35
- }else {
52
+ } else {
36
53
promise.resolve(Arguments .createMap().apply {
37
54
// launcher doesn't support this feature
38
55
// or widget not found
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " react-native-widget-picker" ,
3
- "version" : " 1.0.2 " ,
3
+ "version" : " 1.0.3 " ,
4
4
"license" : " MIT" ,
5
5
"main" : " dist/cjs" ,
6
6
"module" : " dist/mjs" ,
You can’t perform that action at this time.
0 commit comments