esoftplay 0.0.129-s → 0.0.129-u
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/modules/lib/image.tsx +13 -9
- package/package.json +1 -1
- package/state.ts +4 -4
package/modules/lib/image.tsx
CHANGED
|
@@ -242,20 +242,24 @@ class m extends LibComponent<LibImageProps, LibImageState> {
|
|
|
242
242
|
var wantedMaxSize = maxDimension || 1280
|
|
243
243
|
var rawheight = result.height
|
|
244
244
|
var rawwidth = result.width
|
|
245
|
-
|
|
246
|
-
if (rawheight
|
|
247
|
-
|
|
248
|
-
var
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
245
|
+
let doResize = false
|
|
246
|
+
if (wantedMaxSize < Math.max(rawheight, rawwidth)) {
|
|
247
|
+
doResize = true
|
|
248
|
+
var ratio = rawwidth / rawheight
|
|
249
|
+
if (rawheight > rawwidth) {
|
|
250
|
+
var wantedwidth = wantedMaxSize * ratio;
|
|
251
|
+
var wantedheight = wantedMaxSize;
|
|
252
|
+
} else {
|
|
253
|
+
var wantedwidth = wantedMaxSize;
|
|
254
|
+
var wantedheight = wantedMaxSize / ratio;
|
|
255
|
+
}
|
|
252
256
|
}
|
|
253
257
|
|
|
254
258
|
setTimeout(async () => {
|
|
255
259
|
const manipImage = await ImageManipulator.manipulateAsync(
|
|
256
260
|
result.uri,
|
|
257
|
-
[{ resize: { width: wantedwidth, height: wantedheight } }],
|
|
258
|
-
{ format: SaveFormat.JPEG }
|
|
261
|
+
doResize ? [{ resize: { width: wantedwidth, height: wantedheight } }] : [],
|
|
262
|
+
{ format: SaveFormat.JPEG, compress: 1.0 }
|
|
259
263
|
);
|
|
260
264
|
new LibCurl().upload('image_upload', "image", String(manipImage.uri), 'image/jpeg',
|
|
261
265
|
(res: any, msg: string) => {
|
package/package.json
CHANGED
package/state.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
2
|
|
|
3
|
-
type useSafeStateReturn<T> = [T | undefined, (value: T | undefined) => void, () => T];
|
|
3
|
+
type useSafeStateReturn<T> = [T | undefined, (value: T | undefined) => void, () => T | undefined];
|
|
4
4
|
|
|
5
5
|
export default function useSafeState<T = any>(defaultValue?: T): useSafeStateReturn<T> {
|
|
6
6
|
const isMountedRef = useRef<boolean>(true);
|
|
7
7
|
const valueRef = useRef(defaultValue)
|
|
8
|
-
const [
|
|
8
|
+
const [, rerender] = useState({})
|
|
9
9
|
|
|
10
10
|
const updateState = useCallback((value: T | undefined) => {
|
|
11
11
|
if (isMountedRef.current) {
|
|
12
12
|
valueRef.current = value;
|
|
13
|
-
|
|
13
|
+
rerender({})
|
|
14
14
|
}
|
|
15
15
|
}, []);
|
|
16
16
|
|
|
@@ -25,5 +25,5 @@ export default function useSafeState<T = any>(defaultValue?: T): useSafeStateRet
|
|
|
25
25
|
};
|
|
26
26
|
}, []);
|
|
27
27
|
|
|
28
|
-
return [
|
|
28
|
+
return [valueRef.current, updateState, getter];
|
|
29
29
|
}
|