expo-background-remover 0.2.9 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/android/build.gradle
CHANGED
|
@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
|
|
|
2
2
|
apply plugin: 'kotlin-android'
|
|
3
3
|
|
|
4
4
|
group = 'expo.modules.backgroundremover'
|
|
5
|
-
version = '0.
|
|
5
|
+
version = '1.0.0'
|
|
6
6
|
|
|
7
7
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
8
8
|
apply from: expoModulesCorePlugin
|
|
@@ -37,7 +37,7 @@ android {
|
|
|
37
37
|
namespace "expo.modules.backgroundremover"
|
|
38
38
|
defaultConfig {
|
|
39
39
|
versionCode 1
|
|
40
|
-
versionName "0.
|
|
40
|
+
versionName "1.0.0"
|
|
41
41
|
}
|
|
42
42
|
lintOptions {
|
|
43
43
|
abortOnError false
|
|
@@ -2,9 +2,11 @@ package expo.modules.backgroundremover
|
|
|
2
2
|
|
|
3
3
|
import expo.modules.kotlin.modules.Module
|
|
4
4
|
import expo.modules.kotlin.modules.ModuleDefinition
|
|
5
|
-
import java.net.URL
|
|
5
|
+
import java.net.URL
|
|
6
|
+
import kotlinx.coroutines.CoroutineScope
|
|
6
7
|
import kotlinx.coroutines.Dispatchers
|
|
7
|
-
import kotlinx.coroutines.
|
|
8
|
+
import kotlinx.coroutines.launch
|
|
9
|
+
import expo.modules.kotlin.Promise
|
|
8
10
|
|
|
9
11
|
|
|
10
12
|
class ExpoBackgroundRemoverModule : Module() {
|
|
@@ -32,21 +34,27 @@ class ExpoBackgroundRemoverModule : Module() {
|
|
|
32
34
|
|
|
33
35
|
|
|
34
36
|
|
|
35
|
-
|
|
36
|
-
val context = appContext.reactContext
|
|
37
|
-
?: throw Exception("Context not available")
|
|
37
|
+
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
AsyncFunction("removeBackgroundAsync") { imageUri: String, promise: Promise ->
|
|
40
|
+
val context = appContext.reactContext ?: return@AsyncFunction promise.reject(
|
|
41
|
+
"NO_CONTEXT", "React Context is null", null
|
|
42
|
+
)
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
// Using Dispatchers.IO ensures this runs on a background thread,
|
|
45
|
+
// which prevents the UI from freezing during image processing.
|
|
46
|
+
CoroutineScope(Dispatchers.IO).launch {
|
|
47
|
+
val processor = BackgroundRemoverProcessor(context)
|
|
48
|
+
try {
|
|
49
|
+
val result = processor.processImage(imageUri)
|
|
50
|
+
promise.resolve(result)
|
|
51
|
+
} catch (e: Exception) {
|
|
52
|
+
promise.reject("ERR_BG_REMOVER", e.message, e)
|
|
53
|
+
} finally {
|
|
54
|
+
processor.close()
|
|
44
55
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
56
|
+
}
|
|
57
|
+
}
|
|
50
58
|
|
|
51
59
|
// Defines a JavaScript function that always returns a Promise and whose native code
|
|
52
60
|
// is by default dispatched on the different thread than the JavaScript runtime runs on.
|