@react-native-ohos/react-native-image-crop-picker 0.40.5-rc.7 → 0.40.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ### v0.40.5-rc.11
4
+
5
+ - pre-release: @react-native-ohos/react-native-image-crop-picker@0.40.5-rc.11
6
+
7
+ ### v0.40.5-rc.10
8
+
9
+ - fix: Adjust the saved format after image cropping and compression
10
+ - pre-release: @react-native-ohos/react-native-image-crop-picker@0.40.5-rc.10
11
+
12
+ ### v0.40.5-rc.9
13
+
14
+ - fix: Add the "freeStyleCropEnabled" attribute
15
+ - pre-release: @react-native-ohos/react-native-image-crop-picker@0.40.5-rc.9
16
+
3
17
  ## v0.40.5-rc.1
4
18
  - Fix the issue where the file size after compression is larger than the original file.
5
19
 
@@ -3,7 +3,7 @@
3
3
  "description": "Please describe the basic information.",
4
4
  main: 'index.ets',
5
5
  type: 'module',
6
- version: '0.40.5-rc.7',
6
+ version: '0.40.5',
7
7
  dependencies: {
8
8
  "@rnoh/react-native-openharmony": "^0.72.38"
9
9
  },
@@ -20,8 +20,6 @@ import { JSON } from '@kit.ArkTS';
20
20
  import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
21
21
  import { PermissionRequestResult } from '@ohos.abilityAccessCtrl';
22
22
 
23
- import { window } from '@kit.ArkUI';
24
-
25
23
 
26
24
  export type MediaType = 'photo' | 'video' | 'any';
27
25
 
@@ -275,7 +273,7 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
275
273
  }
276
274
  let tempFilePaths = null;
277
275
  Logger.info(`${TAG} into openPicker tempFilePaths ${JSON.stringify(sourceFilePaths)}`);
278
- if (qualityNumber !== 1 || forceJpg) {
276
+ if (!this.isNullOrUndefined(options.compressImageQuality) || forceJpg) {
279
277
  Logger.info(`${TAG} qualityNumber = ${qualityNumber} forceJpg = ${forceJpg}`);
280
278
  tempFilePaths = await this.compressPictures(qualityNumber * 100, forceJpg, sourceFilePaths);
281
279
  } else {
@@ -367,7 +365,6 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
367
365
  }
368
366
 
369
367
  async getPickerResult(options: Options, sourceFilePaths: Array<string>, tempFilePaths: Array<string>): Promise<ImageOrVideo[] | ImageOrVideo> {
370
- Logger.info(`${TAG}, into openPickerResult :`);
371
368
  let resultsList: ImageOrVideo[] = [];
372
369
  let includeExif = this.isNullOrUndefined(options?.includeExif) ? false : options?.includeExif;
373
370
  let images = this.isNullOrUndefined(tempFilePaths) ? sourceFilePaths : tempFilePaths;
@@ -423,8 +420,8 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
423
420
  results.size = length;
424
421
  results.creationDate = stat.ctime + '';
425
422
  results.modificationDate = stat.mtime + '';
423
+ results.path = this.isNullOrUndefined(tempFilePaths) ? null : filePrefix + value;
426
424
  if (this.isImage(value)) {
427
- results.path = this.isNullOrUndefined(tempFilePaths) ? null : filePrefix + value;
428
425
  results.data = includeBase64 ? this.imageToBase64(value) : null;
429
426
  results.mime = 'image/' + imageType;
430
427
  Logger.info(`${TAG} into openPickerResult value : ${value}`);
@@ -443,8 +440,9 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
443
440
  results.duration = null;
444
441
  } else {
445
442
  Logger.info(`${TAG} into getPickerResult video start`);
446
- let qualityNumber = this.isNullOrUndefined(options.compressImageQuality) ? ImageQuality : options.compressImageQuality;
447
- if(qualityNumber !== 1){
443
+ let qualityNumber =
444
+ this.isNullOrUndefined(options.compressImageQuality) ? ImageQuality : options.compressImageQuality;
445
+ if (!this.isNullOrUndefined(options.compressImageQuality)) {
448
446
  results.path = this.isNullOrUndefined(tempFilePaths) ? null : value;
449
447
  } else {
450
448
  results.path = this.isNullOrUndefined(tempFilePaths) ? null : filePrefix + value;
@@ -529,7 +527,13 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
529
527
  if (isImg) {
530
528
  let file = fs.openSync(imgOrVideoPath, fs.OpenMode.READ_ONLY);
531
529
  try {
532
- let dstPath = this.ctx.uiAbilityContext.tempDir + '/rn_image_crop_picker_lib_temp_' + util.generateRandomUUID(true) + '.jpeg';
530
+ let i = imgOrVideoPath.lastIndexOf('.');
531
+ let imageType = '';
532
+ if (i != -1) {
533
+ imageType = imgOrVideoPath.substring(i + 1);
534
+ Logger.info(`${TAG} getTempFilePaths img imageType = ${imageType}`);
535
+ }
536
+ let dstPath = this.ctx.uiAbilityContext.tempDir + '/rn_image_crop_picker_lib_temp_' + util.generateRandomUUID(true) + '.' + imageType;
533
537
  fs.copyFileSync(file.fd, dstPath, 0);
534
538
  imgOrVideoPath = dstPath;
535
539
  Logger.info(`${TAG} into openCamera suc dstPath = ${dstPath}`);
@@ -540,7 +544,7 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
540
544
  }
541
545
  let tempFilePaths = null;
542
546
  let sourceFilePaths: Array<string> = [imgOrVideoPath];
543
- if (qualityNumber !== 1 || forceJpg) {
547
+ if (!this.isNullOrUndefined(options.compressImageQuality) || forceJpg) {
544
548
  Logger.info(`${TAG} into openCamera qualityNumber = ${qualityNumber} forceJpg = ${forceJpg}`);
545
549
  tempFilePaths = await this.compressPictures(qualityNumber * 100, forceJpg, sourceFilePaths);
546
550
  } else {
@@ -645,7 +649,8 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
645
649
 
646
650
  isImage(filePath: string): boolean {
647
651
  Logger.info(`${TAG} into isImage fileName = ${filePath}`);
648
- const imageExtensionsRegex = /\.(jpg|jpeg|png|gif|bmp|webp|heic)$/i;
652
+ const imageExtensionsRegex =
653
+ /\.(jpg|jpeg|png|gif|bmp|webp|heic|heif|sdr_astc_4x4|sdr_sut_superfast_4x4|hdr_astc_4x4)$/i;
649
654
  return imageExtensionsRegex.test(filePath);
650
655
  }
651
656
 
@@ -670,23 +675,19 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
670
675
  let imageISs = image.createImageSource(files.fd);
671
676
  let imagePMs = await imageISs.createPixelMap();
672
677
  let imagePackerApi = await image.createImagePacker();
678
+ let dstPath =
679
+ this.ctx.uiAbilityContext.tempDir + '/rn_image_crop_picker_lib_temp_' + util.generateRandomUUID(true) +
680
+ '.' + imageType;
673
681
  let options: image.PackingOption = {
674
- format: 'image/jpeg',
682
+ format: `image/jpeg`,
675
683
  quality: quality,
676
684
  };
677
- try {
678
- let packerData = await imagePackerApi.packing(imagePMs, options);
679
- Logger.info(`${TAG} into compressPictures data = ${JSON.stringify(packerData)}`);
680
- let dstPath = this.ctx.uiAbilityContext.tempDir + '/rn_image_crop_picker_lib_temp_' + util.generateRandomUUID(true) + '.' + imageType;
681
- let newFile = fs.openSync(dstPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
682
- Logger.info(`${TAG} into compressPictures newFile id = ${newFile.fd}`);
683
- const number = fs.writeSync(newFile.fd, packerData);
684
- Logger.info(`${TAG} into compressPictures write data to file succeed size = ${number}`);
685
- resultImages.push(dstPath);
686
- fs.closeSync(files);
687
- } catch (err) {
688
- Logger.error(`${TAG} into compressPictures write data to file failed err = ${JSON.stringify(err)}`);
689
- }
685
+ let newFile = fs.openSync(dstPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
686
+ let packerData = await imagePackerApi.packToData(imagePMs, options);
687
+ const number = fs.writeSync(newFile.fd, packerData);
688
+ fs.closeSync(newFile);
689
+ resultImages.push(dstPath);
690
+ fs.closeSync(files);
690
691
  } else {
691
692
  Logger.info(`${TAG} into compressPictures video srcPath = ${srcPath}`);
692
693
  resultImages.push(srcPath);
@@ -843,7 +844,7 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
843
844
  videoImageInfo.filename = fileName;
844
845
  videoImageInfo.mime = 'image/' + imageType;
845
846
 
846
- let file = fs.openSync(targetFilePath, fs.OpenMode.READ_ONLY)
847
+ let file = fs.openSync(targetFilePath, fs.OpenMode.READ_ONLY);
847
848
  let stat = fs.statSync(file.fd);
848
849
  let length = stat.size;
849
850
  videoImageInfo.size = length;
@@ -198,7 +198,7 @@ export struct CropView {
198
198
  build() {
199
199
  Stack() {
200
200
  Stack() {
201
- Image(this.model.path)
201
+ Image(this.model.src)
202
202
  .width('100%')
203
203
  .height('100%')
204
204
  .alt(this.model.previewSource)