expo-background-remover 0.3.0 → 1.0.2
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.2'
|
|
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.2"
|
|
41
41
|
}
|
|
42
42
|
lintOptions {
|
|
43
43
|
abortOnError false
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
2
|
-
<application>
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
2
|
+
xmlns:tools="http://schemas.android.com/tools"> <application>
|
|
3
3
|
<meta-data
|
|
4
4
|
android:name="com.google.mlkit.vision.DEPENDENCIES"
|
|
5
|
-
|
|
5
|
+
/* 2. Combine both values: barcode_ui (from expo-camera) and subject_segment (from this) */
|
|
6
|
+
android:value="barcode_ui,subject_segment"
|
|
7
|
+
/* 3. Tell the merger to use this specific value and ignore others */
|
|
8
|
+
tools:replace="android:value" />
|
|
6
9
|
</application>
|
|
7
|
-
</manifest>
|
|
10
|
+
</manifest>
|
|
@@ -3,8 +3,10 @@ package expo.modules.backgroundremover
|
|
|
3
3
|
import expo.modules.kotlin.modules.Module
|
|
4
4
|
import expo.modules.kotlin.modules.ModuleDefinition
|
|
5
5
|
import java.net.URL
|
|
6
|
-
import
|
|
7
|
-
import kotlinx.coroutines.
|
|
6
|
+
import kotlinx.coroutines.CoroutineScope
|
|
7
|
+
import kotlinx.coroutines.Dispatchers
|
|
8
|
+
import kotlinx.coroutines.launch
|
|
9
|
+
import expo.modules.kotlin.Promise
|
|
8
10
|
|
|
9
11
|
|
|
10
12
|
class ExpoBackgroundRemoverModule : Module() {
|
|
@@ -34,26 +36,25 @@ class ExpoBackgroundRemoverModule : Module() {
|
|
|
34
36
|
|
|
35
37
|
|
|
36
38
|
|
|
37
|
-
AsyncFunction("removeBackgroundAsync") { imageUri: String, promise:
|
|
39
|
+
AsyncFunction("removeBackgroundAsync") { imageUri: String, promise: Promise ->
|
|
38
40
|
val context = appContext.reactContext ?: return@AsyncFunction promise.reject(
|
|
39
41
|
"NO_CONTEXT", "React Context is null", null
|
|
40
42
|
)
|
|
41
43
|
|
|
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 {
|
|
44
47
|
val processor = BackgroundRemoverProcessor(context)
|
|
45
48
|
try {
|
|
46
49
|
val result = processor.processImage(imageUri)
|
|
47
50
|
promise.resolve(result)
|
|
48
51
|
} catch (e: Exception) {
|
|
49
|
-
// Rejects the JS promise with the error message
|
|
50
52
|
promise.reject("ERR_BG_REMOVER", e.message, e)
|
|
51
53
|
} finally {
|
|
52
54
|
processor.close()
|
|
53
55
|
}
|
|
54
56
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
}
|
|
57
58
|
|
|
58
59
|
// Defines a JavaScript function that always returns a Promise and whose native code
|
|
59
60
|
// is by default dispatched on the different thread than the JavaScript runtime runs on.
|