Skip to content

Commit

Permalink
1.0.3
Browse files Browse the repository at this point in the history
Prevent app crash on old Android versions
  • Loading branch information
retyui committed Aug 13, 2023
1 parent 68ecb40 commit 87452d6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,31 @@ class WidgetPickerModuleImpl(private val reactContext: ReactApplicationContext)
@RequiresApi(Build.VERSION_CODES.O)
fun requestPinAppWidget(widgetClassKey: String, promise: Promise) {
try {
if (isRequestPinAppWidgetSupported().not()) {
promise.resolve(Arguments.createMap().apply {
putString("message", "not supported")
})
return
}

val appWidgetManager: AppWidgetManager = reactContext.getSystemService(AppWidgetManager::class.java)
val myProvider = ComponentName(reactContext, widgets[widgetClassKey]!!)
val result = appWidgetManager.requestPinAppWidget(myProvider, null, null)
if(result){

val widgetClass = widgets[widgetClassKey];

if (widgetClass == null) {
promise.resolve(Arguments.createMap().apply {
putString("message", "widget not found")
})
return
}

val provider = ComponentName(reactContext, widgetClass)
val result = appWidgetManager.requestPinAppWidget(provider, null, null)
if (result) {
promise.resolve(Arguments.createMap().apply {
putString("message", "success")
})
}else{
} else {
promise.resolve(Arguments.createMap().apply {
// launcher doesn't support this feature
// or widget not found
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-widget-picker",
"version": "1.0.2",
"version": "1.0.3",
"license": "MIT",
"main": "dist/cjs",
"module": "dist/mjs",
Expand Down

0 comments on commit 87452d6

Please sign in to comment.