@teamnhz/rn-ui-toolkit 1.2.2 → 1.2.4
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.
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
type Props = {
|
|
3
3
|
mediaType: "photo" | "video";
|
|
4
|
+
isMultiSelect?: boolean;
|
|
5
|
+
onSuccess: (data: any) => void;
|
|
4
6
|
visible: boolean;
|
|
5
|
-
onSuccess: (res: any) => void;
|
|
6
7
|
onClose: () => void;
|
|
7
8
|
enableCompression?: boolean;
|
|
9
|
+
imageCompressionOptions?: {
|
|
10
|
+
maxWidth?: number;
|
|
11
|
+
quality?: number;
|
|
12
|
+
};
|
|
13
|
+
videoCompressionOptions?: {
|
|
14
|
+
compressionMethod?: "auto" | "manual";
|
|
15
|
+
};
|
|
8
16
|
};
|
|
9
17
|
declare const ImagePicker: React.FC<Props>;
|
|
10
18
|
export default ImagePicker;
|
|
@@ -1,164 +1,498 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import {
|
|
1
|
+
// // import React, { useCallback } from "react";
|
|
2
|
+
// // import {
|
|
3
|
+
// // View,
|
|
4
|
+
// // Text,
|
|
5
|
+
// // TouchableOpacity,
|
|
6
|
+
// // StyleSheet,
|
|
7
|
+
// // Image,
|
|
8
|
+
// // Alert,
|
|
9
|
+
// // ViewStyle,
|
|
10
|
+
// // TextStyle,
|
|
11
|
+
// // ImageStyle,
|
|
12
|
+
// // } from "react-native";
|
|
13
|
+
// // import { BottomSheet, Dividers } from "../index";
|
|
14
|
+
// // import { launchCamera, launchImageLibrary } from "react-native-image-picker";
|
|
15
|
+
// // import ImageCropPicker from "react-native-image-crop-picker";
|
|
16
|
+
// // import { Colors, Images, Scale, Typography } from "../../styles";
|
|
17
|
+
// // type StyleProps = {
|
|
18
|
+
// // containerStyle?: ViewStyle;
|
|
19
|
+
// // rowStyle?: ViewStyle;
|
|
20
|
+
// // textStyle?: TextStyle;
|
|
21
|
+
// // iconStyle?: ImageStyle;
|
|
22
|
+
// // };
|
|
23
|
+
// // type Props = {
|
|
24
|
+
// // mediaType: "photo" | "video";
|
|
25
|
+
// // isMultiSelect?: boolean;
|
|
26
|
+
// // onSuccess: (data: any) => void;
|
|
27
|
+
// // visible: boolean;
|
|
28
|
+
// // onClose: () => void;
|
|
29
|
+
// // } & StyleProps;
|
|
30
|
+
// // const ImagePicker: React.FC<Props> = ({
|
|
31
|
+
// // mediaType,
|
|
32
|
+
// // isMultiSelect = false,
|
|
33
|
+
// // onSuccess,
|
|
34
|
+
// // visible,
|
|
35
|
+
// // onClose,
|
|
36
|
+
// // containerStyle,
|
|
37
|
+
// // rowStyle,
|
|
38
|
+
// // textStyle,
|
|
39
|
+
// // iconStyle,
|
|
40
|
+
// // }) => {
|
|
41
|
+
// // const onComplete = useCallback(
|
|
42
|
+
// // (data: any) => {
|
|
43
|
+
// // onSuccess(data);
|
|
44
|
+
// // onClose();
|
|
45
|
+
// // },
|
|
46
|
+
// // [onSuccess, onClose]
|
|
47
|
+
// // );
|
|
48
|
+
// // const onCamera = () => {
|
|
49
|
+
// // if (mediaType === "photo") {
|
|
50
|
+
// // if (isMultiSelect) {
|
|
51
|
+
// // ImageCropPicker.openCamera({ mediaType: "photo" })
|
|
52
|
+
// // .then((response) => onComplete([response]))
|
|
53
|
+
// // .catch(() => {});
|
|
54
|
+
// // } else {
|
|
55
|
+
// // ImageCropPicker.openCamera({ mediaType: "photo" })
|
|
56
|
+
// // .then((response) =>
|
|
57
|
+
// // ImageCropPicker.openCropper({
|
|
58
|
+
// // path: response?.path,
|
|
59
|
+
// // width: response?.width,
|
|
60
|
+
// // height: response?.height,
|
|
61
|
+
// // mediaType: "photo",
|
|
62
|
+
// // freeStyleCropEnabled: true,
|
|
63
|
+
// // }).then(onComplete)
|
|
64
|
+
// // )
|
|
65
|
+
// // .catch(() => {});
|
|
66
|
+
// // }
|
|
67
|
+
// // } else {
|
|
68
|
+
// // launchCamera({ mediaType: "video" }, (response) => {
|
|
69
|
+
// // if (response?.assets) {
|
|
70
|
+
// // onComplete({
|
|
71
|
+
// // path: response.assets[0]?.uri,
|
|
72
|
+
// // duration: response.assets[0]?.duration,
|
|
73
|
+
// // });
|
|
74
|
+
// // }
|
|
75
|
+
// // });
|
|
76
|
+
// // }
|
|
77
|
+
// // };
|
|
78
|
+
// // const onGallery = () => {
|
|
79
|
+
// // if (mediaType === "photo") {
|
|
80
|
+
// // if (isMultiSelect) {
|
|
81
|
+
// // ImageCropPicker.openPicker({
|
|
82
|
+
// // mediaType: "photo",
|
|
83
|
+
// // multiple: true,
|
|
84
|
+
// // maxFiles: 5,
|
|
85
|
+
// // })
|
|
86
|
+
// // .then((images) => {
|
|
87
|
+
// // if (images.length > 5) {
|
|
88
|
+
// // Alert.alert(
|
|
89
|
+
// // "Limit Exceeded",
|
|
90
|
+
// // "You can only select up to 5 images."
|
|
91
|
+
// // );
|
|
92
|
+
// // } else {
|
|
93
|
+
// // onComplete(images);
|
|
94
|
+
// // }
|
|
95
|
+
// // })
|
|
96
|
+
// // .catch(() => {});
|
|
97
|
+
// // } else {
|
|
98
|
+
// // ImageCropPicker.openPicker({ mediaType: "photo" })
|
|
99
|
+
// // .then((response) =>
|
|
100
|
+
// // ImageCropPicker.openCropper({
|
|
101
|
+
// // path: response?.path,
|
|
102
|
+
// // width: response?.width,
|
|
103
|
+
// // height: response?.height,
|
|
104
|
+
// // mediaType: "photo",
|
|
105
|
+
// // freeStyleCropEnabled: true,
|
|
106
|
+
// // }).then(onComplete)
|
|
107
|
+
// // )
|
|
108
|
+
// // .catch(() => {});
|
|
109
|
+
// // }
|
|
110
|
+
// // } else {
|
|
111
|
+
// // launchImageLibrary({ mediaType: "video" }, (result) => {
|
|
112
|
+
// // if (result?.assets) {
|
|
113
|
+
// // onComplete({
|
|
114
|
+
// // path: result.assets[0]?.uri,
|
|
115
|
+
// // duration: result.assets[0]?.duration,
|
|
116
|
+
// // });
|
|
117
|
+
// // }
|
|
118
|
+
// // });
|
|
119
|
+
// // }
|
|
120
|
+
// // };
|
|
121
|
+
// // return (
|
|
122
|
+
// // <BottomSheet visible={visible} onClose={onClose} height={230}>
|
|
123
|
+
// // <View style={[styles.container, containerStyle]}>
|
|
124
|
+
// // {/* Camera */}
|
|
125
|
+
// // <TouchableOpacity style={[styles.row, rowStyle]} onPress={onCamera}>
|
|
126
|
+
// // <Image source={Images.video_icon} style={[styles.icon, iconStyle]} />
|
|
127
|
+
// // <Text style={[styles.text, textStyle]}>Camera</Text>
|
|
128
|
+
// // </TouchableOpacity>
|
|
129
|
+
// // <Dividers small />
|
|
130
|
+
// // {/* Gallery */}
|
|
131
|
+
// // <TouchableOpacity style={[styles.row, rowStyle]} onPress={onGallery}>
|
|
132
|
+
// // <Image source={Images.image_icon} style={[styles.icon, iconStyle]} />
|
|
133
|
+
// // <Text style={[styles.text, textStyle]}>Gallery</Text>
|
|
134
|
+
// // </TouchableOpacity>
|
|
135
|
+
// // <Dividers small />
|
|
136
|
+
// // {/* Cancel */}
|
|
137
|
+
// // <TouchableOpacity style={[styles.row, rowStyle]} onPress={onClose}>
|
|
138
|
+
// // <Image source={Images.cancel} style={[styles.icon, iconStyle]} />
|
|
139
|
+
// // <Text style={[styles.text, textStyle]}>Cancel</Text>
|
|
140
|
+
// // </TouchableOpacity>
|
|
141
|
+
// // </View>
|
|
142
|
+
// // </BottomSheet>
|
|
143
|
+
// // );
|
|
144
|
+
// // };
|
|
145
|
+
// // export default ImagePicker;
|
|
146
|
+
// // const styles = StyleSheet.create({
|
|
147
|
+
// // container: { flex: 1, padding: 16 },
|
|
148
|
+
// // row: {
|
|
149
|
+
// // flexDirection: "row",
|
|
150
|
+
// // alignItems: "center",
|
|
151
|
+
// // },
|
|
152
|
+
// // text: { ...Typography.style.standardU(), color: Colors.white },
|
|
153
|
+
// // icon: {
|
|
154
|
+
// // width: Scale.moderateScale(20),
|
|
155
|
+
// // height: Scale.moderateScale(20),
|
|
156
|
+
// // marginRight: 10,
|
|
157
|
+
// // tintColor: Colors.white,
|
|
158
|
+
// // },
|
|
159
|
+
// // });
|
|
160
|
+
// import React, { useCallback } from "react";
|
|
161
|
+
// import {
|
|
162
|
+
// View,
|
|
163
|
+
// Text,
|
|
164
|
+
// TouchableOpacity,
|
|
165
|
+
// StyleSheet,
|
|
166
|
+
// Image,
|
|
167
|
+
// Alert,
|
|
168
|
+
// } from "react-native";
|
|
169
|
+
// import { BottomSheet, Dividers } from "../index";
|
|
170
|
+
// import { launchCamera, launchImageLibrary } from "react-native-image-picker";
|
|
171
|
+
// import ImageCropPicker from "react-native-image-crop-picker";
|
|
172
|
+
// import { Colors, Images, Scale, Typography } from "../../styles";
|
|
173
|
+
// // 👇 Import your permission utilities
|
|
174
|
+
// import {
|
|
175
|
+
// cameraPermissions,
|
|
176
|
+
// galleryPermissions,
|
|
177
|
+
// } from "../../utils/permissions"; // ✅ Make sure path is correct
|
|
178
|
+
// type Props = {
|
|
179
|
+
// mediaType: "photo" | "video";
|
|
180
|
+
// isMultiSelect?: boolean;
|
|
181
|
+
// onSuccess: (data: any) => void;
|
|
182
|
+
// visible: boolean;
|
|
183
|
+
// onClose: () => void;
|
|
184
|
+
// };
|
|
185
|
+
// const ImagePicker: React.FC<Props> = ({
|
|
186
|
+
// mediaType,
|
|
187
|
+
// isMultiSelect = false,
|
|
188
|
+
// onSuccess,
|
|
189
|
+
// visible,
|
|
190
|
+
// onClose,
|
|
191
|
+
// }) => {
|
|
192
|
+
// // ✅ Success handler
|
|
193
|
+
// const onComplete = useCallback(
|
|
194
|
+
// (data: any) => {
|
|
195
|
+
// onSuccess(data);
|
|
196
|
+
// onClose();
|
|
197
|
+
// },
|
|
198
|
+
// [onSuccess, onClose]
|
|
199
|
+
// );
|
|
200
|
+
// // ✅ CAMERA HANDLER with permission check
|
|
201
|
+
// const handleCamera = async () => {
|
|
202
|
+
// await cameraPermissions(async (granted: boolean) => {
|
|
203
|
+
// if (!granted) return; // ❌ Permission denied, handled by your alert
|
|
204
|
+
// if (mediaType === "photo") {
|
|
205
|
+
// if (isMultiSelect) {
|
|
206
|
+
// // single capture, multiple not supported directly from camera
|
|
207
|
+
// ImageCropPicker.openCamera({ mediaType: "photo" })
|
|
208
|
+
// .then((response) => onComplete([response]))
|
|
209
|
+
// .catch(() => {});
|
|
210
|
+
// } else {
|
|
211
|
+
// ImageCropPicker.openCamera({ mediaType: "photo" })
|
|
212
|
+
// .then((response) =>
|
|
213
|
+
// ImageCropPicker.openCropper({
|
|
214
|
+
// path: response?.path,
|
|
215
|
+
// width: response?.width,
|
|
216
|
+
// height: response?.height,
|
|
217
|
+
// mediaType: "photo",
|
|
218
|
+
// freeStyleCropEnabled: true,
|
|
219
|
+
// }).then(onComplete)
|
|
220
|
+
// )
|
|
221
|
+
// .catch(() => {});
|
|
222
|
+
// }
|
|
223
|
+
// } else {
|
|
224
|
+
// // 🎥 VIDEO CAPTURE
|
|
225
|
+
// launchCamera({ mediaType: "video" }, (response) => {
|
|
226
|
+
// if (response?.assets?.length) {
|
|
227
|
+
// onComplete({
|
|
228
|
+
// path: response.assets[0]?.uri,
|
|
229
|
+
// duration: response.assets[0]?.duration,
|
|
230
|
+
// });
|
|
231
|
+
// }
|
|
232
|
+
// });
|
|
233
|
+
// }
|
|
234
|
+
// });
|
|
235
|
+
// };
|
|
236
|
+
// // ✅ GALLERY HANDLER with permission check
|
|
237
|
+
// const handleGallery = async () => {
|
|
238
|
+
// await galleryPermissions(async (granted: boolean) => {
|
|
239
|
+
// if (!granted) return; // ❌ Permission denied, handled by your alert
|
|
240
|
+
// if (mediaType === "photo") {
|
|
241
|
+
// if (isMultiSelect) {
|
|
242
|
+
// ImageCropPicker.openPicker({
|
|
243
|
+
// mediaType: "photo",
|
|
244
|
+
// multiple: true,
|
|
245
|
+
// maxFiles: 5,
|
|
246
|
+
// })
|
|
247
|
+
// .then((images) => {
|
|
248
|
+
// if (images.length > 5) {
|
|
249
|
+
// Alert.alert(
|
|
250
|
+
// "Limit Exceeded",
|
|
251
|
+
// "You can only select up to 5 images."
|
|
252
|
+
// );
|
|
253
|
+
// } else {
|
|
254
|
+
// onComplete(images);
|
|
255
|
+
// }
|
|
256
|
+
// })
|
|
257
|
+
// .catch(() => {});
|
|
258
|
+
// } else {
|
|
259
|
+
// ImageCropPicker.openPicker({ mediaType: "photo" })
|
|
260
|
+
// .then((response) =>
|
|
261
|
+
// ImageCropPicker.openCropper({
|
|
262
|
+
// path: response?.path,
|
|
263
|
+
// width: response?.width,
|
|
264
|
+
// height: response?.height,
|
|
265
|
+
// mediaType: "photo",
|
|
266
|
+
// freeStyleCropEnabled: true,
|
|
267
|
+
// }).then(onComplete)
|
|
268
|
+
// )
|
|
269
|
+
// .catch(() => {});
|
|
270
|
+
// }
|
|
271
|
+
// } else {
|
|
272
|
+
// // 🎥 VIDEO FROM GALLERY
|
|
273
|
+
// launchImageLibrary({ mediaType: "video" }, (result) => {
|
|
274
|
+
// if (result?.assets?.length) {
|
|
275
|
+
// onComplete({
|
|
276
|
+
// path: result.assets[0]?.uri,
|
|
277
|
+
// duration: result.assets[0]?.duration,
|
|
278
|
+
// });
|
|
279
|
+
// }
|
|
280
|
+
// });
|
|
281
|
+
// }
|
|
282
|
+
// });
|
|
283
|
+
// };
|
|
284
|
+
// return (
|
|
285
|
+
// <BottomSheet visible={visible} onClose={onClose} height={230}>
|
|
286
|
+
// <View style={styles.container}>
|
|
287
|
+
// {/* 📸 Camera */}
|
|
288
|
+
// <TouchableOpacity style={styles.row} onPress={handleCamera}>
|
|
289
|
+
// <Image source={Images.video_icon} style={styles.icon} />
|
|
290
|
+
// <Text style={styles.text}>Camera</Text>
|
|
291
|
+
// </TouchableOpacity>
|
|
292
|
+
// <Dividers small />
|
|
293
|
+
// {/* 🖼️ Gallery */}
|
|
294
|
+
// <TouchableOpacity style={styles.row} onPress={handleGallery}>
|
|
295
|
+
// <Image source={Images.image_icon} style={styles.icon} />
|
|
296
|
+
// <Text style={styles.text}>Gallery</Text>
|
|
297
|
+
// </TouchableOpacity>
|
|
298
|
+
// <Dividers small />
|
|
299
|
+
// {/* ❌ Cancel */}
|
|
300
|
+
// <TouchableOpacity style={styles.row} onPress={onClose}>
|
|
301
|
+
// <Image source={Images.cancel} style={styles.icon} />
|
|
302
|
+
// <Text style={styles.text}>Cancel</Text>
|
|
303
|
+
// </TouchableOpacity>
|
|
304
|
+
// </View>
|
|
305
|
+
// </BottomSheet>
|
|
306
|
+
// );
|
|
307
|
+
// };
|
|
308
|
+
// export default ImagePicker;
|
|
309
|
+
// const styles = StyleSheet.create({
|
|
310
|
+
// container: { flex: 1, padding: 16 },
|
|
311
|
+
// row: {
|
|
312
|
+
// flexDirection: "row",
|
|
313
|
+
// alignItems: "center",
|
|
314
|
+
// },
|
|
315
|
+
// text: { ...Typography.style.standardU(), color: Colors.white },
|
|
316
|
+
// icon: {
|
|
317
|
+
// width: Scale.moderateScale(20),
|
|
318
|
+
// height: Scale.moderateScale(20),
|
|
319
|
+
// marginRight: 10,
|
|
320
|
+
// tintColor: Colors.white,
|
|
321
|
+
// },
|
|
322
|
+
// });
|
|
323
|
+
import React, { useCallback } from "react";
|
|
324
|
+
import { View, Text, TouchableOpacity, StyleSheet, Image, Alert, } from "react-native";
|
|
3
325
|
import { BottomSheet, Dividers } from "../index";
|
|
4
326
|
import { launchCamera, launchImageLibrary } from "react-native-image-picker";
|
|
5
327
|
import ImageCropPicker from "react-native-image-crop-picker";
|
|
6
328
|
import { Image as ImageCompressor, Video as VideoCompressor, } from "react-native-compressor";
|
|
7
|
-
import
|
|
329
|
+
import RNFS from "react-native-fs";
|
|
8
330
|
import { Colors, Images, Scale, Typography } from "../../styles";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
path: normalizePath(compressed || raw?.path || raw?.uri),
|
|
22
|
-
originalPath: normalizePath(raw?.path || raw?.uri),
|
|
23
|
-
fileName: raw?.fileName || "",
|
|
24
|
-
type: raw?.type || "",
|
|
25
|
-
duration: raw?.duration || undefined,
|
|
26
|
-
});
|
|
27
|
-
//--------------------------------------
|
|
28
|
-
// 🟦 MAIN COMPONENT
|
|
29
|
-
//--------------------------------------
|
|
30
|
-
const ImagePicker = ({ mediaType, visible, onSuccess, onClose, enableCompression = true, }) => {
|
|
31
|
-
//--------------------------------------
|
|
32
|
-
// SEND RAW (loader ON)
|
|
33
|
-
//--------------------------------------
|
|
34
|
-
const sendRaw = (raw) => {
|
|
35
|
-
onSuccess({
|
|
36
|
-
loading: true,
|
|
37
|
-
data: buildResponse(raw),
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
//--------------------------------------
|
|
41
|
-
// SEND FINAL (loader OFF)
|
|
42
|
-
//--------------------------------------
|
|
43
|
-
const sendFinal = (raw, compressed) => {
|
|
44
|
-
onSuccess({
|
|
45
|
-
loading: false,
|
|
46
|
-
data: buildResponse(raw, compressed),
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
//--------------------------------------
|
|
50
|
-
// COMPRESS IMAGE
|
|
51
|
-
//--------------------------------------
|
|
52
|
-
const compressImage = async (path) => {
|
|
331
|
+
// Import your permission utilities
|
|
332
|
+
import { cameraPermissions, galleryPermissions, checkMicroPhonePermission, } from "../../utils/permissions";
|
|
333
|
+
const ImagePicker = ({ mediaType, isMultiSelect = false, onSuccess, visible, onClose, enableCompression = true, imageCompressionOptions = { maxWidth: 1080, quality: 0.7 }, videoCompressionOptions = { compressionMethod: "auto" }, }) => {
|
|
334
|
+
// Success handler
|
|
335
|
+
const onComplete = useCallback((data) => {
|
|
336
|
+
onSuccess(data);
|
|
337
|
+
onClose();
|
|
338
|
+
}, [onSuccess, onClose]);
|
|
339
|
+
// Helper: Compress Image
|
|
340
|
+
const compressImage = async (imagePath) => {
|
|
341
|
+
if (!enableCompression)
|
|
342
|
+
return imagePath;
|
|
53
343
|
try {
|
|
54
|
-
|
|
55
|
-
maxWidth:
|
|
56
|
-
quality:
|
|
344
|
+
const compressedImage = await ImageCompressor.compress(imagePath, {
|
|
345
|
+
maxWidth: imageCompressionOptions.maxWidth,
|
|
346
|
+
quality: imageCompressionOptions.quality,
|
|
57
347
|
});
|
|
348
|
+
// Log compressed size (optional)
|
|
349
|
+
const stats = await RNFS.stat(compressedImage.replace("file://", ""));
|
|
350
|
+
const sizeInMB = stats.size / (1024 * 1024);
|
|
351
|
+
console.log("Compressed Image Size (MB):", sizeInMB);
|
|
352
|
+
return compressedImage;
|
|
58
353
|
}
|
|
59
|
-
catch {
|
|
60
|
-
|
|
354
|
+
catch (error) {
|
|
355
|
+
console.error("Image compression error:", error);
|
|
356
|
+
return imagePath; // Return original if compression fails
|
|
61
357
|
}
|
|
62
358
|
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
359
|
+
// Helper: Compress Video
|
|
360
|
+
const compressVideo = async (videoUri) => {
|
|
361
|
+
if (!enableCompression)
|
|
362
|
+
return videoUri;
|
|
67
363
|
try {
|
|
68
|
-
|
|
69
|
-
compressionMethod:
|
|
364
|
+
const compressedVideo = await VideoCompressor.compress(videoUri, {
|
|
365
|
+
compressionMethod: videoCompressionOptions.compressionMethod,
|
|
70
366
|
});
|
|
367
|
+
// Log compressed size (optional)
|
|
368
|
+
const stats = await RNFS.stat(compressedVideo.replace("file://", ""));
|
|
369
|
+
const sizeInMB = stats.size / (1024 * 1024);
|
|
370
|
+
console.log("Compressed Video Size (MB):", sizeInMB);
|
|
371
|
+
return compressedVideo;
|
|
71
372
|
}
|
|
72
|
-
catch {
|
|
73
|
-
|
|
373
|
+
catch (error) {
|
|
374
|
+
console.error("Video compression error:", error);
|
|
375
|
+
return videoUri; // Return original if compression fails
|
|
74
376
|
}
|
|
75
377
|
};
|
|
76
|
-
|
|
77
|
-
// CAMERA HANDLER
|
|
78
|
-
//--------------------------------------
|
|
378
|
+
// CAMERA HANDLER with permission check and compression
|
|
79
379
|
const handleCamera = async () => {
|
|
80
|
-
onClose(); // 🔥 CLOSE FIRST (best UX)
|
|
81
380
|
await cameraPermissions(async (granted) => {
|
|
82
381
|
if (!granted)
|
|
83
382
|
return;
|
|
84
|
-
// PHOTO
|
|
85
383
|
if (mediaType === "photo") {
|
|
86
384
|
try {
|
|
87
|
-
const
|
|
385
|
+
const response = await ImageCropPicker.openCamera({
|
|
88
386
|
mediaType: "photo",
|
|
89
|
-
cropping: true,
|
|
90
387
|
});
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
:
|
|
95
|
-
|
|
388
|
+
if (isMultiSelect) {
|
|
389
|
+
// Single capture for multi-select mode
|
|
390
|
+
const compressedPath = await compressImage(response.path);
|
|
391
|
+
onComplete([{ ...response, path: compressedPath }]);
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
// Crop and compress single image
|
|
395
|
+
const cropped = await ImageCropPicker.openCropper({
|
|
396
|
+
path: response?.path,
|
|
397
|
+
width: response?.width,
|
|
398
|
+
height: response?.height,
|
|
399
|
+
mediaType: "photo",
|
|
400
|
+
freeStyleCropEnabled: true,
|
|
401
|
+
});
|
|
402
|
+
const compressedPath = await compressImage(cropped.path);
|
|
403
|
+
onComplete({ ...cropped, path: compressedPath });
|
|
404
|
+
}
|
|
96
405
|
}
|
|
97
|
-
catch (
|
|
98
|
-
console.log("Camera
|
|
406
|
+
catch (error) {
|
|
407
|
+
console.log("Camera cancelled or error:", error);
|
|
99
408
|
}
|
|
100
409
|
}
|
|
101
|
-
// VIDEO
|
|
102
410
|
else {
|
|
103
|
-
|
|
104
|
-
|
|
411
|
+
// VIDEO CAPTURE - check microphone permission first
|
|
412
|
+
const micPermission = await checkMicroPhonePermission();
|
|
413
|
+
if (!micPermission) {
|
|
414
|
+
Alert.alert("Microphone Permission Required", "Please enable microphone access to record videos.");
|
|
105
415
|
return;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
416
|
+
}
|
|
417
|
+
launchCamera({
|
|
418
|
+
mediaType: "video",
|
|
419
|
+
durationLimit: 60,
|
|
420
|
+
videoQuality: "high",
|
|
421
|
+
}, async (response) => {
|
|
422
|
+
if (response?.assets?.length) {
|
|
423
|
+
const videoUri = response.assets[0]?.uri;
|
|
424
|
+
const compressedPath = await compressVideo(videoUri);
|
|
425
|
+
onComplete({
|
|
426
|
+
path: compressedPath,
|
|
427
|
+
duration: response.assets[0]?.duration,
|
|
428
|
+
});
|
|
429
|
+
}
|
|
115
430
|
});
|
|
116
431
|
}
|
|
117
432
|
});
|
|
118
433
|
};
|
|
119
|
-
|
|
120
|
-
// GALLERY HANDLER
|
|
121
|
-
//--------------------------------------
|
|
434
|
+
// GALLERY HANDLER with permission check and compression
|
|
122
435
|
const handleGallery = async () => {
|
|
123
|
-
onClose(); // 🔥 CLOSE IMMEDIATELY
|
|
124
436
|
await galleryPermissions(async (granted) => {
|
|
125
437
|
if (!granted)
|
|
126
438
|
return;
|
|
127
|
-
// PHOTO (Crop Picker)
|
|
128
439
|
if (mediaType === "photo") {
|
|
129
440
|
try {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
441
|
+
if (isMultiSelect) {
|
|
442
|
+
const images = await ImageCropPicker.openPicker({
|
|
443
|
+
mediaType: "photo",
|
|
444
|
+
multiple: true,
|
|
445
|
+
maxFiles: 5,
|
|
446
|
+
});
|
|
447
|
+
if (images.length > 5) {
|
|
448
|
+
Alert.alert("Limit Exceeded", "You can only select up to 5 images.");
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
// Compress multiple images
|
|
452
|
+
const compressedImages = await Promise.all(images.map(async (img) => ({
|
|
453
|
+
...img,
|
|
454
|
+
path: await compressImage(img.path),
|
|
455
|
+
})));
|
|
456
|
+
onComplete(compressedImages);
|
|
457
|
+
}
|
|
458
|
+
else {
|
|
459
|
+
// Single image with crop
|
|
460
|
+
const response = await ImageCropPicker.openPicker({
|
|
461
|
+
mediaType: "photo",
|
|
462
|
+
});
|
|
463
|
+
const cropped = await ImageCropPicker.openCropper({
|
|
464
|
+
path: response?.path,
|
|
465
|
+
width: response?.width,
|
|
466
|
+
height: response?.height,
|
|
467
|
+
mediaType: "photo",
|
|
468
|
+
freeStyleCropEnabled: true,
|
|
469
|
+
});
|
|
470
|
+
const compressedPath = await compressImage(cropped.path);
|
|
471
|
+
onComplete({ ...cropped, path: compressedPath });
|
|
472
|
+
}
|
|
139
473
|
}
|
|
140
|
-
catch (
|
|
141
|
-
console.log("Gallery
|
|
474
|
+
catch (error) {
|
|
475
|
+
console.log("Gallery cancelled or error:", error);
|
|
142
476
|
}
|
|
143
477
|
}
|
|
144
|
-
// VIDEO
|
|
145
478
|
else {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
479
|
+
// VIDEO FROM GALLERY
|
|
480
|
+
launchImageLibrary({
|
|
481
|
+
mediaType: "video",
|
|
482
|
+
assetRepresentationMode: "current",
|
|
483
|
+
}, async (result) => {
|
|
484
|
+
if (result?.assets?.length) {
|
|
485
|
+
const videoUri = result.assets[0]?.uri;
|
|
486
|
+
const compressedPath = await compressVideo(videoUri);
|
|
487
|
+
onComplete({
|
|
488
|
+
path: compressedPath,
|
|
489
|
+
duration: result.assets[0]?.duration,
|
|
490
|
+
});
|
|
491
|
+
}
|
|
155
492
|
});
|
|
156
493
|
}
|
|
157
494
|
});
|
|
158
495
|
};
|
|
159
|
-
//--------------------------------------
|
|
160
|
-
// RETURN UI
|
|
161
|
-
//--------------------------------------
|
|
162
496
|
return (React.createElement(BottomSheet, { visible: visible, onClose: onClose, height: 230 },
|
|
163
497
|
React.createElement(View, { style: styles.container },
|
|
164
498
|
React.createElement(TouchableOpacity, { style: styles.row, onPress: handleCamera },
|
|
@@ -174,23 +508,13 @@ const ImagePicker = ({ mediaType, visible, onSuccess, onClose, enableCompression
|
|
|
174
508
|
React.createElement(Text, { style: styles.text }, "Cancel")))));
|
|
175
509
|
};
|
|
176
510
|
export default ImagePicker;
|
|
177
|
-
//--------------------------------------
|
|
178
|
-
// STYLES
|
|
179
|
-
//--------------------------------------
|
|
180
511
|
const styles = StyleSheet.create({
|
|
181
512
|
container: { flex: 1, padding: 16 },
|
|
182
513
|
row: {
|
|
183
514
|
flexDirection: "row",
|
|
184
515
|
alignItems: "center",
|
|
185
|
-
justifyContent: "center", // 🔥 TEXT CENTERED
|
|
186
|
-
paddingVertical: 14,
|
|
187
|
-
},
|
|
188
|
-
text: {
|
|
189
|
-
...Typography.style.standardU(),
|
|
190
|
-
color: Colors.white,
|
|
191
|
-
marginLeft: 10,
|
|
192
|
-
textAlign: "center",
|
|
193
516
|
},
|
|
517
|
+
text: { ...Typography.style.standardU(), color: Colors.white },
|
|
194
518
|
icon: {
|
|
195
519
|
width: Scale.moderateScale(20),
|
|
196
520
|
height: Scale.moderateScale(20),
|