react-native-compressor 2.0.0 → 2.0.1
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.
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
package com.reactnativecompressor;
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Promise;
|
|
4
|
+
import com.facebook.react.bridge.WritableMap;
|
|
5
|
+
import java.util.concurrent.atomic.AtomicBoolean;
|
|
6
|
+
import kotlin.Unit;
|
|
7
|
+
import kotlin.jvm.functions.Function0;
|
|
8
|
+
import kotlin.jvm.functions.Function1;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Adapts the React Native bridge {@link Promise} to a Nitro
|
|
12
|
+
* {@link com.margelo.nitro.core.Promise} so the existing domain methods — which speak the bridge
|
|
13
|
+
* {@code Promise} contract ({@code resolve}/{@code reject}) — can drive a Nitro Promise unchanged.
|
|
14
|
+
*
|
|
15
|
+
* <p>{@code convert} maps the resolved bridge value to the Nitro result type {@code T};
|
|
16
|
+
* {@code onSettle} runs once on resolve/reject (used to unregister progress callbacks).
|
|
17
|
+
*
|
|
18
|
+
* <p>This is intentionally written in Java rather than Kotlin: the bridge {@code Promise} interface
|
|
19
|
+
* declares {@code code} as non-null ({@code String}) on some React Native versions and nullable
|
|
20
|
+
* ({@code String?}) on others. Kotlin override parameter types are invariant, so a single Kotlin
|
|
21
|
+
* source can only match one of those. Java erases nullability for override matching, so one Java
|
|
22
|
+
* implementation satisfies every React Native version.
|
|
23
|
+
*/
|
|
24
|
+
public class NitroPromiseAdapter<T> implements Promise {
|
|
25
|
+
private final com.margelo.nitro.core.Promise<T> promise;
|
|
26
|
+
private final Function1<Object, T> convert;
|
|
27
|
+
private final Function0<Unit> onSettle;
|
|
28
|
+
private final AtomicBoolean settled = new AtomicBoolean(false);
|
|
29
|
+
|
|
30
|
+
public NitroPromiseAdapter(
|
|
31
|
+
com.margelo.nitro.core.Promise<T> promise,
|
|
32
|
+
Function1<Object, T> convert,
|
|
33
|
+
Function0<Unit> onSettle) {
|
|
34
|
+
this.promise = promise;
|
|
35
|
+
this.convert = convert;
|
|
36
|
+
this.onSettle = onSettle;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Override
|
|
40
|
+
public void resolve(Object value) {
|
|
41
|
+
if (!settled.compareAndSet(false, true)) return;
|
|
42
|
+
onSettle.invoke();
|
|
43
|
+
promise.resolve(convert.invoke(value));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private void rejectInternal(String message, Throwable throwable) {
|
|
47
|
+
if (!settled.compareAndSet(false, true)) return;
|
|
48
|
+
onSettle.invoke();
|
|
49
|
+
promise.reject(
|
|
50
|
+
throwable != null
|
|
51
|
+
? throwable
|
|
52
|
+
: new Throwable(message != null ? message : "react-native-compressor error"));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@Override
|
|
56
|
+
public void reject(String code, String message) {
|
|
57
|
+
rejectInternal(message != null ? message : code, null);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@Override
|
|
61
|
+
public void reject(String code, Throwable throwable) {
|
|
62
|
+
rejectInternal(code, throwable);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@Override
|
|
66
|
+
public void reject(String code, String message, Throwable throwable) {
|
|
67
|
+
rejectInternal(message != null ? message : code, throwable);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@Override
|
|
71
|
+
public void reject(Throwable throwable) {
|
|
72
|
+
rejectInternal(throwable.getMessage(), throwable);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@Override
|
|
76
|
+
public void reject(Throwable throwable, WritableMap userInfo) {
|
|
77
|
+
rejectInternal(throwable.getMessage(), throwable);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@Override
|
|
81
|
+
public void reject(String code, WritableMap userInfo) {
|
|
82
|
+
rejectInternal(code, null);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@Override
|
|
86
|
+
public void reject(String code, Throwable throwable, WritableMap userInfo) {
|
|
87
|
+
rejectInternal(code, throwable);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@Override
|
|
91
|
+
public void reject(String code, String message, WritableMap userInfo) {
|
|
92
|
+
rejectInternal(message != null ? message : code, null);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@Override
|
|
96
|
+
public void reject(String code, String message, Throwable throwable, WritableMap userInfo) {
|
|
97
|
+
rejectInternal(message != null ? message : code, throwable);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@Deprecated
|
|
101
|
+
@Override
|
|
102
|
+
public void reject(String message) {
|
|
103
|
+
rejectInternal(message, null);
|
|
104
|
+
}
|
|
105
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-compressor",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Compress Image, Video, and Audio same like Whatsapp & Auto/Manual Compression | Background Upload | Download File | Create Video Thumbnail",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
package com.reactnativecompressor
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.bridge.Promise
|
|
4
|
-
import com.facebook.react.bridge.WritableMap
|
|
5
|
-
import java.util.concurrent.atomic.AtomicBoolean
|
|
6
|
-
import com.margelo.nitro.core.Promise as NitroPromise
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Adapts the React Native bridge [Promise] to a Nitro [NitroPromise] so the existing
|
|
10
|
-
* domain methods — which speak the bridge `Promise` contract (`resolve`/`reject`) — can
|
|
11
|
-
* drive a Nitro Promise unchanged.
|
|
12
|
-
*
|
|
13
|
-
* [convert] maps the resolved bridge value to the Nitro result type [T];
|
|
14
|
-
* [onSettle] runs once on resolve/reject (used to unregister progress callbacks).
|
|
15
|
-
*/
|
|
16
|
-
class NitroPromiseAdapter<T>(
|
|
17
|
-
private val promise: NitroPromise<T>,
|
|
18
|
-
private val convert: (Any?) -> T,
|
|
19
|
-
private val onSettle: () -> Unit = {},
|
|
20
|
-
) : Promise {
|
|
21
|
-
private val settled = AtomicBoolean(false)
|
|
22
|
-
|
|
23
|
-
override fun resolve(value: Any?) {
|
|
24
|
-
if (!settled.compareAndSet(false, true)) return
|
|
25
|
-
onSettle()
|
|
26
|
-
promise.resolve(convert(value))
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
private fun rejectInternal(message: String?, throwable: Throwable?) {
|
|
30
|
-
if (!settled.compareAndSet(false, true)) return
|
|
31
|
-
onSettle()
|
|
32
|
-
promise.reject(throwable ?: Throwable(message ?: "react-native-compressor error"))
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
override fun reject(code: String?, message: String?) = rejectInternal(message ?: code, null)
|
|
36
|
-
|
|
37
|
-
override fun reject(code: String?, throwable: Throwable?) = rejectInternal(code, throwable)
|
|
38
|
-
|
|
39
|
-
override fun reject(code: String?, message: String?, throwable: Throwable?) = rejectInternal(message ?: code, throwable)
|
|
40
|
-
|
|
41
|
-
override fun reject(throwable: Throwable) = rejectInternal(throwable.message, throwable)
|
|
42
|
-
|
|
43
|
-
override fun reject(throwable: Throwable, userInfo: WritableMap) = rejectInternal(throwable.message, throwable)
|
|
44
|
-
|
|
45
|
-
override fun reject(code: String?, userInfo: WritableMap) = rejectInternal(code, null)
|
|
46
|
-
|
|
47
|
-
override fun reject(code: String?, throwable: Throwable?, userInfo: WritableMap) = rejectInternal(code, throwable)
|
|
48
|
-
|
|
49
|
-
override fun reject(code: String?, message: String?, userInfo: WritableMap) = rejectInternal(message ?: code, null)
|
|
50
|
-
|
|
51
|
-
override fun reject(code: String?, message: String?, throwable: Throwable?, userInfo: WritableMap?) = rejectInternal(message ?: code, throwable)
|
|
52
|
-
|
|
53
|
-
@Deprecated("Prefer passing a module-specific error code to JS.", ReplaceWith("reject(code, message)"))
|
|
54
|
-
override fun reject(message: String) = rejectInternal(message, null)
|
|
55
|
-
}
|