File tree Expand file tree Collapse file tree
android/src/main/java/com/retyui/widgetpicker Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,14 +25,31 @@ class WidgetPickerModuleImpl(private val reactContext: ReactApplicationContext)
2525 @RequiresApi(Build .VERSION_CODES .O )
2626 fun requestPinAppWidget (widgetClassKey : String , promise : Promise ) {
2727 try {
28+ if (isRequestPinAppWidgetSupported().not ()) {
29+ promise.resolve(Arguments .createMap().apply {
30+ putString(" message" , " not supported" )
31+ })
32+ return
33+ }
34+
2835 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) {
3249 promise.resolve(Arguments .createMap().apply {
3350 putString(" message" , " success" )
3451 })
35- }else {
52+ } else {
3653 promise.resolve(Arguments .createMap().apply {
3754 // launcher doesn't support this feature
3855 // or widget not found
Original file line number Diff line number Diff line change 11{
22 "name" : " react-native-widget-picker" ,
3- "version" : " 1.0.2 " ,
3+ "version" : " 1.0.3 " ,
44 "license" : " MIT" ,
55 "main" : " dist/cjs" ,
66 "module" : " dist/mjs" ,
You can’t perform that action at this time.
0 commit comments