esoftplay 0.0.242 → 0.0.244
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/bin/build.js +2 -4
- package/modules/lib/image.tsx +62 -181
- package/modules/lib/version.tsx +10 -2
- package/package.json +1 -1
- package/modules/lib/image_crop.tsx +0 -263
package/bin/build.js
CHANGED
|
@@ -330,22 +330,20 @@ export default function App() {
|
|
|
330
330
|
'expo-file-system',
|
|
331
331
|
'expo-font',
|
|
332
332
|
'expo-image',
|
|
333
|
-
'expo-image-manipulator',
|
|
334
|
-
'expo-image-picker',
|
|
335
333
|
'expo-linear-gradient',
|
|
336
334
|
'expo-media-library',
|
|
337
335
|
'expo-notifications',
|
|
338
336
|
'expo-status-bar',
|
|
339
337
|
'expo-splash-screen',
|
|
340
338
|
'expo-secure-store',
|
|
341
|
-
// 'expo-sqlite',
|
|
342
339
|
'expo-updates',
|
|
343
340
|
'immhelper',
|
|
344
341
|
'dayjs',
|
|
345
342
|
'react-fast-compare',
|
|
346
343
|
'react-native-gesture-handler',
|
|
347
344
|
'react-native-awesome-gallery',
|
|
348
|
-
|
|
345
|
+
'react-native-global-exception-handler',
|
|
346
|
+
'react-native-image-crop-picker',
|
|
349
347
|
'react-native-keyboard-controller',
|
|
350
348
|
'react-native-mmkv',
|
|
351
349
|
'react-native-pan-pinch-view',
|
package/modules/lib/image.tsx
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
|
+
//[moved] change native cropper
|
|
1
2
|
// noPage
|
|
2
3
|
import { LibComponent } from 'esoftplay/cache/lib/component/import';
|
|
3
4
|
import { LibCurl } from 'esoftplay/cache/lib/curl/import';
|
|
4
5
|
import { LibIcon } from 'esoftplay/cache/lib/icon/import';
|
|
5
|
-
import { LibNavigation } from 'esoftplay/cache/lib/navigation/import';
|
|
6
6
|
import { LibProgress } from 'esoftplay/cache/lib/progress/import';
|
|
7
7
|
import { LibStyle } from 'esoftplay/cache/lib/style/import';
|
|
8
8
|
import esp from 'esoftplay/esp';
|
|
9
9
|
import useGlobalState from 'esoftplay/global';
|
|
10
10
|
import { CameraView } from 'expo-camera';
|
|
11
|
-
import * as ImageManipulator from 'expo-image-manipulator';
|
|
12
|
-
import { SaveFormat } from 'expo-image-manipulator';
|
|
13
|
-
import * as ImagePicker from 'expo-image-picker';
|
|
14
11
|
import React from 'react';
|
|
15
|
-
import { ActivityIndicator,
|
|
12
|
+
import { ActivityIndicator, Image, TouchableOpacity, View } from 'react-native';
|
|
13
|
+
import ImagePicker from "react-native-image-crop-picker";
|
|
16
14
|
const { height, width } = LibStyle;
|
|
17
15
|
|
|
18
16
|
|
|
@@ -103,200 +101,83 @@ class m extends LibComponent<LibImageProps, LibImageState> {
|
|
|
103
101
|
}
|
|
104
102
|
|
|
105
103
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
104
|
+
private static ratio2Size(ratio: string, maxDimension: number = 1200): [width: number, height: number] {
|
|
105
|
+
if (maxDimension <= 0 || !isFinite(maxDimension)) {
|
|
106
|
+
console.error("Invalid maxDimension provided, returning [0, 0].");
|
|
107
|
+
return [0, 0];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const parts = ratio?.split(":");
|
|
111
|
+
if (parts?.length !== 2) {
|
|
112
|
+
return [maxDimension, maxDimension];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const [aspectRatioWidth, aspectRatioHeight] = parts.map(Number);
|
|
116
|
+
|
|
117
|
+
if (isNaN(aspectRatioWidth) || isNaN(aspectRatioHeight) || aspectRatioWidth <= 0 || aspectRatioHeight <= 0) {
|
|
118
|
+
return [maxDimension, maxDimension];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (aspectRatioWidth > aspectRatioHeight) {
|
|
122
|
+
const width = maxDimension;
|
|
123
|
+
const height = (aspectRatioHeight / aspectRatioWidth) * width;
|
|
124
|
+
return [width, height];
|
|
125
|
+
} else {
|
|
126
|
+
const height = maxDimension;
|
|
127
|
+
const width = (aspectRatioWidth / aspectRatioHeight) * height;
|
|
128
|
+
return [width, height];
|
|
129
|
+
}
|
|
109
130
|
}
|
|
110
131
|
|
|
111
132
|
/** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/image.md#fromCamera) untuk melihat dokumentasi*/
|
|
112
133
|
static fromCamera(options?: LibImageCameraOptions): Promise<string> {
|
|
113
134
|
return new Promise((_r) => {
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const { status } = await ImagePicker.requestMediaLibraryPermissionsAsync();
|
|
126
|
-
finalStatus = status
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
if (finalStatus != 'granted') {
|
|
130
|
-
Alert.alert(esp.lang("lib/image", "cam_title", esp.appjson().expo.name), esp.lang("lib/image", "cam_msg", esp.appjson().expo.name))
|
|
131
|
-
}
|
|
132
|
-
ImagePicker.launchCameraAsync({
|
|
133
|
-
allowsEditing: Platform.OS != 'ios' && options && options.crop ? true : false,
|
|
134
|
-
aspect: options?.crop?.ratio?.split(':').map((x) => Number(x)),
|
|
135
|
-
quality: 1,
|
|
136
|
-
presentationStyle: ImagePicker.UIImagePickerPresentationStyle.FULL_SCREEN
|
|
137
|
-
}).then(async (res: any) => {
|
|
138
|
-
if (!res)
|
|
139
|
-
res = ImagePicker?.getPendingResultAsync()
|
|
140
|
-
if (!res?.cancelled) {
|
|
141
|
-
let result: any = undefined
|
|
142
|
-
let hasUri = res?.uri
|
|
143
|
-
if (hasUri) {
|
|
144
|
-
result = res
|
|
145
|
-
} else if (res?.assets?.[0]) {
|
|
146
|
-
result = { ...res, ...res.assets[0] }
|
|
147
|
-
}
|
|
148
|
-
if (Platform.OS == 'ios' && options && options.crop) {
|
|
149
|
-
m.showCropper(result?.uri, options?.crop?.forceCrop, options?.crop?.ratio, options?.crop?.message, async (x) => {
|
|
150
|
-
let imageUri = await m.processImage(x, options?.maxDimension)
|
|
151
|
-
m.setResult(imageUri)
|
|
152
|
-
_r(imageUri)
|
|
153
|
-
})
|
|
154
|
-
} else {
|
|
155
|
-
let imageUri = await m.processImage(result, options?.maxDimension)
|
|
156
|
-
m.setResult(imageUri)
|
|
157
|
-
_r(imageUri)
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
})
|
|
161
|
-
clearTimeout(timer)
|
|
162
|
-
}, 1);
|
|
135
|
+
const [w, h] = m.ratio2Size(options?.crop?.ratio)
|
|
136
|
+
ImagePicker.openCamera({
|
|
137
|
+
width: w,
|
|
138
|
+
height: h,
|
|
139
|
+
cropping: true,
|
|
140
|
+
}).then(async (image) => {
|
|
141
|
+
let imageUri = await m.processImage(image.path, options?.maxDimension)
|
|
142
|
+
m.setResult(imageUri)
|
|
143
|
+
_r(imageUri)
|
|
144
|
+
});
|
|
145
|
+
|
|
163
146
|
})
|
|
164
147
|
}
|
|
165
148
|
|
|
166
149
|
/** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/image.md#fromGallery) untuk melihat dokumentasi*/
|
|
167
150
|
static fromGallery(options?: LibImageGalleryOptions): Promise<string | string[]> {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
151
|
+
const [w, h] = m.ratio2Size(options?.crop?.ratio)
|
|
152
|
+
return new Promise(async (_r) => {
|
|
153
|
+
ImagePicker.openPicker({
|
|
154
|
+
width: w,
|
|
155
|
+
height: h,
|
|
156
|
+
cropping: true,
|
|
157
|
+
}).then(async (z) => {
|
|
158
|
+
if (z) {
|
|
159
|
+
let imageUri = await m.processImage(z.path, options?.maxDimension)
|
|
160
|
+
m.setResult(imageUri)
|
|
161
|
+
_r(imageUri)
|
|
179
162
|
}
|
|
180
|
-
|
|
181
|
-
if (options?.multiple == true) {
|
|
182
|
-
max = options?.max || 0
|
|
183
|
-
} else {
|
|
184
|
-
max = 1
|
|
185
|
-
}
|
|
186
|
-
if (max == 1) {
|
|
187
|
-
ImagePicker.launchImageLibraryAsync({
|
|
188
|
-
presentationStyle: ImagePicker.UIImagePickerPresentationStyle.FULL_SCREEN,
|
|
189
|
-
allowsEditing: Platform.OS != 'ios' && options && options.crop ? true : false,
|
|
190
|
-
aspect: options?.crop?.ratio?.split(':').map((x) => Number(x)),
|
|
191
|
-
quality: 1,
|
|
192
|
-
}).then(async (z: any) => {
|
|
193
|
-
if (!z.cancelled) {
|
|
194
|
-
let x: any = undefined
|
|
195
|
-
let hasUri = z?.uri
|
|
196
|
-
if (hasUri) {
|
|
197
|
-
x = z
|
|
198
|
-
} else if (z?.assets?.[0]) {
|
|
199
|
-
x = { ...z, ...z.assets[0] }
|
|
200
|
-
}
|
|
201
|
-
if (Platform.OS == 'ios' && options && options.crop) {
|
|
202
|
-
m.showCropper(x.uri, options.crop.forceCrop, options.crop.ratio, options.crop?.message, async (x) => {
|
|
203
|
-
let imageUri = await m.processImage(x, options?.maxDimension)
|
|
204
|
-
m.setResult(imageUri)
|
|
205
|
-
_r(imageUri)
|
|
206
|
-
})
|
|
207
|
-
} else {
|
|
208
|
-
let imageUri = await m.processImage(x, options?.maxDimension)
|
|
209
|
-
m.setResult(imageUri)
|
|
210
|
-
_r(imageUri)
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
})
|
|
214
|
-
return
|
|
215
|
-
}
|
|
216
|
-
LibNavigation.navigateForResult("lib/image_multi", { max: max }).then((x: any[]) => {
|
|
217
|
-
let a: string[] = []
|
|
218
|
-
x.forEach(async (t: any, i) => {
|
|
219
|
-
if (i == 0) {
|
|
220
|
-
LibProgress.show(esp.lang("lib/image", "wait"))
|
|
221
|
-
}
|
|
222
|
-
var wantedMaxSize = options?.maxDimension || 1280
|
|
223
|
-
var rawheight = t.height
|
|
224
|
-
var rawwidth = t.width
|
|
225
|
-
var ratio = rawwidth / rawheight
|
|
226
|
-
if (rawheight > rawwidth) {
|
|
227
|
-
var wantedwidth = wantedMaxSize * ratio;
|
|
228
|
-
var wantedheight = wantedMaxSize;
|
|
229
|
-
} else {
|
|
230
|
-
var wantedwidth = wantedMaxSize;
|
|
231
|
-
var wantedheight = wantedMaxSize / ratio;
|
|
232
|
-
}
|
|
233
|
-
const manipImage = await ImageManipulator.manipulateAsync(
|
|
234
|
-
t.uri,
|
|
235
|
-
[{ resize: { width: wantedwidth, height: wantedheight } }],
|
|
236
|
-
{ format: SaveFormat.JPEG }
|
|
237
|
-
);
|
|
238
|
-
new LibCurl().upload('image_upload', "image", String(manipImage.uri), 'image/jpeg',
|
|
239
|
-
(res: any, msg: string) => {
|
|
240
|
-
a.push(String(res));
|
|
241
|
-
if (a.length == x.length) {
|
|
242
|
-
if (max == 1) {
|
|
243
|
-
_r(res)
|
|
244
|
-
} else {
|
|
245
|
-
_r(a)
|
|
246
|
-
}
|
|
247
|
-
LibProgress.hide()
|
|
248
|
-
}
|
|
249
|
-
},
|
|
250
|
-
(msg: any) => {
|
|
251
|
-
console.log(msg.message, "NOOO")
|
|
252
|
-
if (x.length - 1 == i)
|
|
253
|
-
LibProgress.hide()
|
|
254
|
-
}, 1)
|
|
255
|
-
});
|
|
256
|
-
})
|
|
257
|
-
clearTimeout(timer)
|
|
258
|
-
}, 1)
|
|
163
|
+
});
|
|
259
164
|
})
|
|
260
165
|
}
|
|
261
166
|
|
|
262
167
|
/** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/image.md#processImage) untuk melihat dokumentasi*/
|
|
263
168
|
static processImage(result: any, maxDimension?: number): Promise<string> {
|
|
264
169
|
return new Promise((r) => {
|
|
265
|
-
if (
|
|
170
|
+
if (result) {
|
|
266
171
|
LibProgress.show(esp.lang("lib/image", "wait_upload"))
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
var wantedheight = wantedMaxSize;
|
|
277
|
-
} else {
|
|
278
|
-
var wantedwidth = wantedMaxSize;
|
|
279
|
-
var wantedheight = wantedMaxSize / ratio;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
const timer = setTimeout(async () => {
|
|
284
|
-
const manipImage = await ImageManipulator.manipulateAsync(
|
|
285
|
-
result.uri,
|
|
286
|
-
doResize ? [{ resize: { width: wantedwidth, height: wantedheight } }] : [],
|
|
287
|
-
{ format: SaveFormat.JPEG, compress: 1.0 }
|
|
288
|
-
);
|
|
289
|
-
new LibCurl().upload('image_upload', "image", String(manipImage.uri), 'image/jpeg',
|
|
290
|
-
(res: any, msg: string) => {
|
|
291
|
-
r(res);
|
|
292
|
-
LibProgress.hide()
|
|
293
|
-
},
|
|
294
|
-
(msg: any) => {
|
|
295
|
-
LibProgress.hide()
|
|
296
|
-
r(msg.message);
|
|
297
|
-
}, 1)
|
|
298
|
-
clearTimeout(timer)
|
|
299
|
-
}, 1);
|
|
172
|
+
new LibCurl().upload('image_upload', "image", String(result), 'image/jpeg',
|
|
173
|
+
(res: any, msg: string) => {
|
|
174
|
+
r(res);
|
|
175
|
+
LibProgress.hide()
|
|
176
|
+
},
|
|
177
|
+
(msg: any) => {
|
|
178
|
+
LibProgress.hide()
|
|
179
|
+
r(msg.message);
|
|
180
|
+
}, 1)
|
|
300
181
|
}
|
|
301
182
|
})
|
|
302
183
|
}
|
package/modules/lib/version.tsx
CHANGED
|
@@ -51,8 +51,9 @@ export default class m extends LibComponent<LibVersionProps, LibVersionState> {
|
|
|
51
51
|
|
|
52
52
|
function isAvailableNewVersion(newVersion: string): boolean {
|
|
53
53
|
let oldVersion = m.appVersion()
|
|
54
|
-
return newVersion > oldVersion
|
|
54
|
+
return Number(newVersion) > Number(oldVersion)
|
|
55
55
|
}
|
|
56
|
+
|
|
56
57
|
if (!__DEV__)
|
|
57
58
|
if (isAvailableNewVersion(version)) {
|
|
58
59
|
LibNavigation.backToRoot()
|
|
@@ -71,7 +72,14 @@ export default class m extends LibComponent<LibVersionProps, LibVersionState> {
|
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
render(): any {
|
|
74
|
-
const { res
|
|
75
|
+
const { res, msg } = LibNavigation.getArgsAll<any>(this.props)
|
|
76
|
+
let title, version, android, ios
|
|
77
|
+
if (res) {
|
|
78
|
+
title = res.title
|
|
79
|
+
version = res.version
|
|
80
|
+
android = res.android
|
|
81
|
+
ios = res.ios
|
|
82
|
+
}
|
|
75
83
|
const link = Platform.OS == 'ios' ? ios : android
|
|
76
84
|
return (
|
|
77
85
|
<ImageBackground source={esp.assets("splash.png")} blurRadius={100} style={{ flex: 1, justifyContent: 'center', alignItems: 'center', borderStartColor: 'white', paddingHorizontal: 17 }} >
|
package/package.json
CHANGED
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
// withHooks
|
|
2
|
-
import esp from 'esoftplay/esp';
|
|
3
|
-
import useSafeState from 'esoftplay/state';
|
|
4
|
-
|
|
5
|
-
import * as ImageManipulator from "expo-image-manipulator";
|
|
6
|
-
import { useEffect, useRef } from 'react';
|
|
7
|
-
import { Image, Pressable, Text, TouchableOpacity, View } from 'react-native';
|
|
8
|
-
import PanPinchView from "react-native-pan-pinch-view";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export interface LibImage_cropProps {
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/image_crop.md) untuk melihat dokumentasi*/
|
|
16
|
-
export default function m(props: LibImage_cropProps): any {
|
|
17
|
-
const LibIcon = useRef(esp.mod("lib/icon")).current
|
|
18
|
-
const LibNavigation = useRef(esp.mod("lib/navigation")).current
|
|
19
|
-
const LibProgress = useRef(esp.mod("lib/progress")).current
|
|
20
|
-
const LibStatusbar = useRef(esp.mod("lib/statusbar")).current
|
|
21
|
-
const LibStyle = useRef(esp.mod("lib/style")).current
|
|
22
|
-
const LibTextstyle = useRef(esp.mod("lib/textstyle")).current
|
|
23
|
-
const LibToastProperty = useRef(esp.modProp("lib/toast")).current
|
|
24
|
-
|
|
25
|
-
const { image, ratio, forceCrop, message } = LibNavigation.getArgsAll(props)
|
|
26
|
-
const [_image, setImage] = useSafeState(image)
|
|
27
|
-
const [counter, setCounter] = useSafeState(0)
|
|
28
|
-
const [size, setSize] = useSafeState(LibStyle.width)
|
|
29
|
-
const [hint, setHint] = useSafeState(true)
|
|
30
|
-
const [cropCount, setCropCount] = useSafeState(0)
|
|
31
|
-
|
|
32
|
-
const _ratio = ratio && ratio.includes(":") ? ratio.split(":") : [3, 2]
|
|
33
|
-
const maxRatio = Math.max(_ratio)
|
|
34
|
-
const marginTop = 60 + LibStyle.STATUSBAR_HEIGHT
|
|
35
|
-
const viewRef = useRef<any>(null)
|
|
36
|
-
const imageRef = useRef<any>(null)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const minimalRatioSize = (LibStyle.width / size).toFixed(1) == (_ratio[0] / _ratio[1]).toFixed(1) ? LibStyle.width : Math.min(LibStyle.width, size)
|
|
40
|
-
|
|
41
|
-
let ratioSize = [minimalRatioSize, minimalRatioSize]
|
|
42
|
-
if (maxRatio == _ratio[0]) {
|
|
43
|
-
ratioSize[0] = _ratio[0] / _ratio[1] * minimalRatioSize
|
|
44
|
-
} else {
|
|
45
|
-
ratioSize[1] = _ratio[1] / _ratio[0] * minimalRatioSize
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
function resize(image: string) {
|
|
51
|
-
LibProgress.show(esp.lang("lib/image_crop", "waiting"))
|
|
52
|
-
Image.getSize(image, async (actualWidth, actualHeight) => {
|
|
53
|
-
var wantedMaxSize = 900
|
|
54
|
-
var rawheight = actualHeight
|
|
55
|
-
var rawwidth = actualWidth
|
|
56
|
-
var ratio = rawwidth / rawheight
|
|
57
|
-
if (rawheight > rawwidth) {
|
|
58
|
-
var wantedwidth = wantedMaxSize * ratio;
|
|
59
|
-
var wantedheight = wantedMaxSize;
|
|
60
|
-
} else {
|
|
61
|
-
var wantedwidth = wantedMaxSize;
|
|
62
|
-
var wantedheight = wantedMaxSize / ratio;
|
|
63
|
-
}
|
|
64
|
-
const manipImage = await ImageManipulator.manipulateAsync(
|
|
65
|
-
image,
|
|
66
|
-
[{ resize: { width: wantedwidth, height: wantedheight } }],
|
|
67
|
-
{ format: ImageManipulator.SaveFormat.JPEG }
|
|
68
|
-
);
|
|
69
|
-
setImage(manipImage.uri)
|
|
70
|
-
LibProgress.hide()
|
|
71
|
-
}, () => { LibProgress.hide() })
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
useEffect(() => {
|
|
75
|
-
resize(_image)
|
|
76
|
-
}, [])
|
|
77
|
-
|
|
78
|
-
useEffect(() => {
|
|
79
|
-
Image.getSize(_image, async (actualWidth, actualHeight) => {
|
|
80
|
-
const h = actualHeight * LibStyle.width / actualWidth
|
|
81
|
-
setSize(h)
|
|
82
|
-
}, () => { })
|
|
83
|
-
}, [_image])
|
|
84
|
-
|
|
85
|
-
useEffect(() => {
|
|
86
|
-
return () => LibNavigation.cancelBackResult(LibNavigation.getResultKey(props))
|
|
87
|
-
}, [])
|
|
88
|
-
|
|
89
|
-
function reset() {
|
|
90
|
-
LibNavigation.replace('lib/image_crop', LibNavigation.getArgsAll(props))
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function capture() {
|
|
94
|
-
LibProgress.show(esp.lang("lib/image_crop", "waiting_crop"))
|
|
95
|
-
let crop = {
|
|
96
|
-
x: 0,
|
|
97
|
-
y: 0,
|
|
98
|
-
width: 0,
|
|
99
|
-
height: 0,
|
|
100
|
-
pageX: 0,
|
|
101
|
-
pageY: 0
|
|
102
|
-
}
|
|
103
|
-
let img = {
|
|
104
|
-
x: 0,
|
|
105
|
-
y: 0,
|
|
106
|
-
width: 0,
|
|
107
|
-
height: 0,
|
|
108
|
-
pageX: 0,
|
|
109
|
-
pageY: 0
|
|
110
|
-
}
|
|
111
|
-
Image.getSize(_image, (actualWidth, actualHeight) => {
|
|
112
|
-
viewRef.current?.measure((...vls: number[]) => {
|
|
113
|
-
crop = {
|
|
114
|
-
x: vls[0],
|
|
115
|
-
y: vls[1],
|
|
116
|
-
width: vls[2],
|
|
117
|
-
height: vls[3],
|
|
118
|
-
pageX: vls[4],
|
|
119
|
-
pageY: vls[5]
|
|
120
|
-
}
|
|
121
|
-
imageRef.current?.measure((...vls: number[]) => {
|
|
122
|
-
img = {
|
|
123
|
-
x: vls[0],
|
|
124
|
-
y: vls[1],
|
|
125
|
-
width: vls[2],
|
|
126
|
-
height: vls[3],
|
|
127
|
-
pageX: vls[4],
|
|
128
|
-
pageY: vls[5]
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
let fixPageY = crop.pageY - marginTop
|
|
132
|
-
|
|
133
|
-
if (crop.pageX < 0) {
|
|
134
|
-
// cropWidth = cropWidth + crop.pageX
|
|
135
|
-
crop.pageX = 0
|
|
136
|
-
}
|
|
137
|
-
if (fixPageY < 0) {
|
|
138
|
-
// cropHeight = cropHeight + fixPageY
|
|
139
|
-
fixPageY = 0
|
|
140
|
-
}
|
|
141
|
-
let scale = actualWidth / img.width
|
|
142
|
-
let totalCropWidth = (crop.pageX + crop.width)
|
|
143
|
-
let totalCropHeight = (fixPageY + crop.height)
|
|
144
|
-
let cropWidth = totalCropWidth > img.width ? img.width - crop.pageX : crop.width
|
|
145
|
-
let cropHeight = totalCropHeight > img.height ? img.height - fixPageY : crop.height
|
|
146
|
-
// if (totalCropHeight > img.height) {
|
|
147
|
-
// fixPageY = img.height - fixPageY
|
|
148
|
-
// }
|
|
149
|
-
// if (totalCropWidth > img.width) {
|
|
150
|
-
// crop.pageX = img.width - crop.width
|
|
151
|
-
// }
|
|
152
|
-
|
|
153
|
-
const cropOption = {
|
|
154
|
-
originX: scale * (crop.pageX > img.width ? 0 : crop.pageX),
|
|
155
|
-
originY: scale * ((fixPageY) > img.height ? 0 : (fixPageY)),
|
|
156
|
-
width: (scale * cropWidth) > 0 ? (scale * cropWidth) : 0,
|
|
157
|
-
height: (scale * cropHeight) > 0 ? (scale * cropHeight) : 0,
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
ImageManipulator.manipulateAsync(
|
|
162
|
-
_image,
|
|
163
|
-
[{
|
|
164
|
-
crop: cropOption
|
|
165
|
-
}],
|
|
166
|
-
{ compress: 1, format: ImageManipulator.SaveFormat.PNG }
|
|
167
|
-
).then((x) => {
|
|
168
|
-
if (x.uri) {
|
|
169
|
-
setImage(x.uri)
|
|
170
|
-
setCropCount(cropCount + 1)
|
|
171
|
-
}
|
|
172
|
-
LibProgress.hide()
|
|
173
|
-
}).catch(() => {
|
|
174
|
-
LibProgress.hide()
|
|
175
|
-
LibToastProperty.show(esp.lang("lib/image_crop", "alert_out"))
|
|
176
|
-
})
|
|
177
|
-
})
|
|
178
|
-
})
|
|
179
|
-
}, () => {
|
|
180
|
-
LibProgress.hide()
|
|
181
|
-
})
|
|
182
|
-
}
|
|
183
|
-
return (
|
|
184
|
-
<View style={{ flex: 1, backgroundColor: "#000" }} key={counter} >
|
|
185
|
-
<LibStatusbar style="light" />
|
|
186
|
-
<View style={{ marginTop: LibStyle.STATUSBAR_HEIGHT, height: 50, flexDirection: "row", justifyContent: 'space-between' }} >
|
|
187
|
-
<TouchableOpacity
|
|
188
|
-
onPress={() => LibNavigation.back()}
|
|
189
|
-
style={{ height: 50, width: 50, alignItems: 'center', justifyContent: 'center' }} >
|
|
190
|
-
<LibIcon name="close" color={'white'} />
|
|
191
|
-
</TouchableOpacity>
|
|
192
|
-
<View style={{ flexDirection: "row" }} >
|
|
193
|
-
<TouchableOpacity
|
|
194
|
-
onPress={reset}
|
|
195
|
-
style={{ height: 50, width: 50, alignItems: 'center', justifyContent: 'center' }} >
|
|
196
|
-
<LibIcon name="undo" color={'white'} />
|
|
197
|
-
</TouchableOpacity>
|
|
198
|
-
<TouchableOpacity
|
|
199
|
-
onPress={capture}
|
|
200
|
-
style={{ height: 50, width: 50, alignItems: 'center', justifyContent: 'center' }} >
|
|
201
|
-
<LibIcon name="crop" color={'white'} />
|
|
202
|
-
</TouchableOpacity>
|
|
203
|
-
</View>
|
|
204
|
-
</View>
|
|
205
|
-
<View style={{ flex: 1 }} >
|
|
206
|
-
|
|
207
|
-
<Image
|
|
208
|
-
ref={imageRef}
|
|
209
|
-
style={{ resizeMode: "contain", height: size, width: LibStyle.width }} source={{ uri: _image }} />
|
|
210
|
-
<View style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, alignItems: 'center', justifyContent: 'center' }} >
|
|
211
|
-
<PanPinchView
|
|
212
|
-
key={_image}
|
|
213
|
-
minScale={0.5}
|
|
214
|
-
containerDimensions={{
|
|
215
|
-
width: LibStyle.width,
|
|
216
|
-
height: size,
|
|
217
|
-
}}
|
|
218
|
-
contentDimensions={{
|
|
219
|
-
width: ratioSize[0],
|
|
220
|
-
height: ratioSize[1]
|
|
221
|
-
}}
|
|
222
|
-
// style={{ backgroundColor: "transparent", flex: undefined, width: LibStyle.height * 100, height: LibStyle.height * 100, alignSelf: 'center', justifyContent: 'center' }}
|
|
223
|
-
maxScale={2}>
|
|
224
|
-
{/* <> */}
|
|
225
|
-
{/* <View style={{ backgroundColor: "rgba(0,0,0,0.5 )", flex: 1 }} />
|
|
226
|
-
<View style={{ flexDirection: "row" }} >
|
|
227
|
-
<View style={{ backgroundColor: "rgba(0,0,0,0.5 )", flex: 1 }} /> */}
|
|
228
|
-
<View ref={viewRef} style={{ height: ratioSize[1], width: ratioSize[0], backgroundColor: 'transparent', borderWidth: 1, borderColor: "white", borderStyle: 'dashed', zIndex: 100 }} >
|
|
229
|
-
<View style={{ flex: 1, backgroundColor: 'transparent', borderWidth: 1, borderColor: "black", borderStyle: 'dashed' }} />
|
|
230
|
-
</View>
|
|
231
|
-
{/* <View style={{ backgroundColor: "rgba(0,0,0,0.5 )", flex: 1 }} />
|
|
232
|
-
</View>
|
|
233
|
-
<View style={{ backgroundColor: "rgba(0,0,0,0.5 )", flex: 1 }} /> */}
|
|
234
|
-
{/* </> */}
|
|
235
|
-
</PanPinchView>
|
|
236
|
-
</View>
|
|
237
|
-
|
|
238
|
-
{
|
|
239
|
-
// hint &
|
|
240
|
-
<Pressable
|
|
241
|
-
onPress={() => setHint(!hint)}
|
|
242
|
-
style={{ opacity: hint ? 1 : 0, position: 'absolute', left: 0, right: 0, bottom: 50, backgroundColor: 'rgba(0,0,0,0.5)', alignItems: 'center', justifyContent: 'center', padding: 30 }} >
|
|
243
|
-
<Text style={{ color: "white", textAlign: 'center' }} >{message || esp.lang("lib/image_crop", "text_msg")}</Text>
|
|
244
|
-
</Pressable>
|
|
245
|
-
}
|
|
246
|
-
{
|
|
247
|
-
(!forceCrop || cropCount > 0) &&
|
|
248
|
-
<View style={{ position: "absolute", bottom: 10, left: 0, right: 0 }} >
|
|
249
|
-
<TouchableOpacity
|
|
250
|
-
onPress={() => {
|
|
251
|
-
Image.getSize(_image, (width, height) => {
|
|
252
|
-
LibNavigation.sendBackResult({ uri: _image, width, height }, LibNavigation.getResultKey(props))
|
|
253
|
-
}, () => { })
|
|
254
|
-
}}
|
|
255
|
-
style={{ height: 50, alignItems: 'center', justifyContent: 'center', backgroundColor: 'rgba(255,255,255,0.3)' }} >
|
|
256
|
-
<LibTextstyle textStyle="body" text={esp.lang("lib/image_crop", "btn_save")} style={{ color: "white" }} />
|
|
257
|
-
</TouchableOpacity>
|
|
258
|
-
</View>
|
|
259
|
-
}
|
|
260
|
-
</View>
|
|
261
|
-
</View>
|
|
262
|
-
)
|
|
263
|
-
}
|