Skip to content

Commit

Permalink
Fix: Added support for changing the icon more than once on android (#42)
Browse files Browse the repository at this point in the history
* Added support for changing the icon more than once on android

* Updated based on PR feedback
  • Loading branch information
MaxMSolutions authored Sep 30, 2021
1 parent efb2594 commit 8281fb3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.facebook.react.bridge.ReactMethod
import com.facebook.react.bridge.Promise

class ChangeIconModule(reactContext: ReactApplicationContext, private val packageName: String) : ReactContextBaseJavaModule(reactContext), Application.ActivityLifecycleCallbacks {
private var classToKill: String = ""
private var classesToKill: MutableList<String> = mutableListOf<String>()
private var iconChanged: Boolean = false;
private var componentClass: String = ""
override fun getName(): String {
Expand All @@ -38,7 +38,7 @@ class ChangeIconModule(reactContext: ReactApplicationContext, private val packag
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP
)
classToKill = componentClass;
classesToKill.add(componentClass)
componentClass = activeClass
activity.application.registerActivityLifecycleCallbacks(this)
iconChanged = true;
Expand All @@ -50,11 +50,14 @@ class ChangeIconModule(reactContext: ReactApplicationContext, private val packag
if (activity == null) {
return
}
activity.packageManager.setComponentEnabledSetting(
ComponentName(packageName, classToKill),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP
)
classesToKill.forEach {
activity.packageManager.setComponentEnabledSetting(
ComponentName(packageName, it),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP
)
}
classesToKill.clear()
iconChanged = false;
}
}
Expand Down
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-change-icon",
"version": "3.1.1",
"version": "3.1.2",
"description": "Change application icon programmatically in React-Native.",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down Expand Up @@ -120,7 +120,10 @@
]
}
},
"eslintIgnore": ["node_modules/", "lib/"],
"eslintIgnore": [
"node_modules/",
"lib/"
],
"prettier": {
"quoteProps": "consistent",
"singleQuote": true,
Expand All @@ -131,6 +134,10 @@
"@react-native-community/bob": {
"source": "src",
"output": "lib",
"targets": ["commonjs", "module", "typescript"]
"targets": [
"commonjs",
"module",
"typescript"
]
}
}

0 comments on commit 8281fb3

Please sign in to comment.