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

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,22 @@
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
+
17
+ ## v0.40.5-rc.1
18
+ - Fix the issue where the file size after compression is larger than the original file.
19
+
3
20
  ## v0.40.4-rc.1
4
21
  - react-native-image-crop-picker仓库迁移 ([e09dff16cc4c51bfdcec842921d3c30d49d39a19](https://gitee.com/openharmony-sig/rntpc_react-native-image-crop-picker/pulls/1))
5
22
  - chore: add COMMITTERS.md ([6e71f31b17e5aba5a60215b58ddc6f656def74f9](https://gitee.com/openharmony-sig/rntpc_react-native-image-crop-picker/pulls/2))
package/COMMITTERS.md CHANGED
@@ -2,8 +2,4 @@
2
2
  ## 以下是此项目的committer人员
3
3
  不区分先后顺序
4
4
 
5
- - [MaDiXin](https://gitee.com/MaDiXin)
6
- - [xiafeng_xf_admin](https://gitee.com/xiafeng_xf_admin)
7
- - [chenLixi](https://gitee.com/Louis-C7)
8
- - [LinJiacheng](https://gitee.com/LLLLLLin)
9
- - [ZhengJinshou](https://gitee.com/longziz)
5
+ - [xiafeng_xf_admin](https://gitee.com/xiafeng_xf_admin)
@@ -1,6 +1,8 @@
1
1
  // Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
2
2
  // Use of this source code is governed by a MIT license that can be
3
3
  // found in the LICENSE file.
4
-
4
+ import { ImageCropPickerPackage } from './src/main/ets/ImageCropPickerPackage'
5
5
  export { ImageEditInfo } from "./src/main/ets/pages/ImageEditInfo"
6
+ export { CircleImageInfo } from "./src/main/ets/pages/CircleImageInfo"
6
7
  export * from "./ts";
8
+ export default ImageCropPickerPackage
@@ -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.4',
6
+ version: '0.40.5-rc.11',
7
7
  dependencies: {
8
8
  "@rnoh/react-native-openharmony": "^0.72.38"
9
9
  },
@@ -63,4 +63,3 @@ class BaseReactNativeImageCropPickerPackage : public Package {
63
63
  };
64
64
 
65
65
  } // namespace rnoh
66
-
@@ -3,6 +3,7 @@
3
3
  // found in the LICENSE file.
4
4
 
5
5
  import { RNPackage, TurboModulesFactory } from '@rnoh/react-native-openharmony/ts';
6
+ import { RNOHPackage } from '@rnoh/react-native-openharmony'
6
7
  import type { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
7
8
  import { ImageCropPickerTurboModule } from './ImageCropPickerTurboModule';
8
9
 
@@ -21,7 +22,7 @@ class ImageCropPickerTurboModulesFactory extends TurboModulesFactory {
21
22
 
22
23
  }
23
24
 
24
- export class ImageCropPickerPackage extends RNPackage {
25
+ export class ImageCropPickerPackage extends RNOHPackage {
25
26
  createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
26
27
  return new ImageCropPickerTurboModulesFactory(ctx);
27
28
  }
@@ -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;
@@ -443,6 +440,13 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
443
440
  results.duration = null;
444
441
  } else {
445
442
  Logger.info(`${TAG} into getPickerResult video start`);
443
+ let qualityNumber =
444
+ this.isNullOrUndefined(options.compressImageQuality) ? ImageQuality : options.compressImageQuality;
445
+ if (!this.isNullOrUndefined(options.compressImageQuality)) {
446
+ results.path = this.isNullOrUndefined(tempFilePaths) ? null : value;
447
+ } else {
448
+ results.path = this.isNullOrUndefined(tempFilePaths) ? null : filePrefix + value;
449
+ }
446
450
  results.data = null;
447
451
  results.mime = 'video/' + imageType;
448
452
  let url = 'fd://' + file.fd;
@@ -523,7 +527,13 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
523
527
  if (isImg) {
524
528
  let file = fs.openSync(imgOrVideoPath, fs.OpenMode.READ_ONLY);
525
529
  try {
526
- 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;
527
537
  fs.copyFileSync(file.fd, dstPath, 0);
528
538
  imgOrVideoPath = dstPath;
529
539
  Logger.info(`${TAG} into openCamera suc dstPath = ${dstPath}`);
@@ -534,7 +544,7 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
534
544
  }
535
545
  let tempFilePaths = null;
536
546
  let sourceFilePaths: Array<string> = [imgOrVideoPath];
537
- if (qualityNumber !== 1 || forceJpg) {
547
+ if (!this.isNullOrUndefined(options.compressImageQuality) || forceJpg) {
538
548
  Logger.info(`${TAG} into openCamera qualityNumber = ${qualityNumber} forceJpg = ${forceJpg}`);
539
549
  tempFilePaths = await this.compressPictures(qualityNumber * 100, forceJpg, sourceFilePaths);
540
550
  } else {
@@ -639,7 +649,8 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
639
649
 
640
650
  isImage(filePath: string): boolean {
641
651
  Logger.info(`${TAG} into isImage fileName = ${filePath}`);
642
- 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;
643
654
  return imageExtensionsRegex.test(filePath);
644
655
  }
645
656
 
@@ -664,23 +675,19 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
664
675
  let imageISs = image.createImageSource(files.fd);
665
676
  let imagePMs = await imageISs.createPixelMap();
666
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;
667
681
  let options: image.PackingOption = {
668
- format: 'image/jpeg',
682
+ format: `image/jpeg`,
669
683
  quality: quality,
670
684
  };
671
- try {
672
- let packerData = await imagePackerApi.packing(imagePMs, options);
673
- Logger.info(`${TAG} into compressPictures data = ${JSON.stringify(packerData)}`);
674
- let dstPath = this.ctx.uiAbilityContext.tempDir + '/rn_image_crop_picker_lib_temp_' + util.generateRandomUUID(true) + '.' + imageType;
675
- let newFile = fs.openSync(dstPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
676
- Logger.info(`${TAG} into compressPictures newFile id = ${newFile.fd}`);
677
- const number = fs.writeSync(newFile.fd, packerData);
678
- Logger.info(`${TAG} into compressPictures write data to file succeed size = ${number}`);
679
- resultImages.push(dstPath);
680
- fs.closeSync(files);
681
- } catch (err) {
682
- Logger.error(`${TAG} into compressPictures write data to file failed err = ${JSON.stringify(err)}`);
683
- }
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);
684
691
  } else {
685
692
  Logger.info(`${TAG} into compressPictures video srcPath = ${srcPath}`);
686
693
  resultImages.push(srcPath);
@@ -823,30 +830,37 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
823
830
  async getFileInfo(includeBase64: boolean, filePath: string, compressOrTempFilePath: string, exifInfo: Exif): Promise<VideoImageInfo> {
824
831
  let videoImageInfo: VideoImageInfo = { duration: null };
825
832
  let imageType;
826
- let i = this.isNullOrUndefined(compressOrTempFilePath) ? filePath.lastIndexOf('/') : compressOrTempFilePath.lastIndexOf('/')
827
- let fileName = this.isNullOrUndefined(compressOrTempFilePath) ? filePath.substring(i + 1) : compressOrTempFilePath.substring(i + 1)
828
- i = filePath.lastIndexOf('.')
833
+
834
+ const targetFilePath = !this.isNullOrUndefined(compressOrTempFilePath) ? compressOrTempFilePath : filePath;
835
+
836
+ let i = targetFilePath.lastIndexOf('/');
837
+ let fileName = targetFilePath.substring(i + 1);
838
+ i = targetFilePath.lastIndexOf('.');
829
839
  if (i != -1) {
830
- imageType = filePath.substring(i + 1)
840
+ imageType = targetFilePath.substring(i + 1);
831
841
  }
832
- videoImageInfo.path = this.isNullOrUndefined(compressOrTempFilePath) ? filePrefix + filePath : compressOrTempFilePath + filePath;
842
+
843
+ videoImageInfo.path = filePrefix + targetFilePath;
833
844
  videoImageInfo.filename = fileName;
834
845
  videoImageInfo.mime = 'image/' + imageType;
835
846
 
836
- let file = fs.openSync(filePath, fs.OpenMode.READ_ONLY)
847
+ let file = fs.openSync(targetFilePath, fs.OpenMode.READ_ONLY);
837
848
  let stat = fs.statSync(file.fd);
838
849
  let length = stat.size;
839
850
  videoImageInfo.size = length;
840
851
  videoImageInfo.creationDate = stat.ctime;
841
852
  videoImageInfo.modificationDate = stat.mtime;
842
- if (this.isImage(filePath)) {
853
+
854
+ if (this.isImage(targetFilePath)) {
843
855
  let imageIS = image.createImageSource(file.fd)
844
856
  let imagePM = await imageIS.createPixelMap()
845
857
  let imgInfo = await imagePM.getImageInfo();
846
- videoImageInfo.data = includeBase64 ? this.imageToBase64(compressOrTempFilePath || filePath) : null;
858
+
859
+ videoImageInfo.data = includeBase64 ? this.imageToBase64(targetFilePath) : null;
847
860
  videoImageInfo.height = imgInfo.size.height;
848
861
  videoImageInfo.width = imgInfo.size.width;
849
862
  videoImageInfo.exif = exifInfo;
863
+
850
864
  imagePM.release().then(() => {
851
865
  imagePM = undefined;
852
866
  })
@@ -892,6 +906,7 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
892
906
  const showCropGuidelines: boolean = this.isNullOrUndefined(options?.showCropGuidelines) ? true : options?.showCropGuidelines;
893
907
  const showCropFrame: boolean = this.isNullOrUndefined(options?.showCropFrame) ? true : options?.showCropFrame;
894
908
  const freeStyleCropEnabled: boolean = this.isNullOrUndefined(options?.freeStyleCropEnabled) ? false : options?.freeStyleCropEnabled;
909
+ const cropperCircleOverlay: boolean = this.isNullOrUndefined(options?.cropperCircleOverlay) ? false : options?.cropperCircleOverlay;
895
910
  const cropperRotate: string = options?.cropperRotateButtonsHidden + '';
896
911
  AppStorage.setOrCreate('initWidth', initWidth);
897
912
  AppStorage.setOrCreate('initHeight', initHeight);
@@ -905,7 +920,7 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
905
920
  AppStorage.setOrCreate('showCropGuidelines', showCropGuidelines);
906
921
  AppStorage.setOrCreate('showCropFrame', showCropFrame);
907
922
  AppStorage.setOrCreate('freeStyleCropEnabled', freeStyleCropEnabled);
908
-
923
+ AppStorage.setOrCreate('cropperCircleOverlay', cropperCircleOverlay);
909
924
  try {
910
925
  let want: Want = {
911
926
  "bundleName": bundleName,
@@ -2,4 +2,4 @@
2
2
  /**
3
3
  */
4
4
 
5
- export {}
5
+ export {}
@@ -2,6 +2,8 @@
2
2
  * This code was generated by "react-native codegen-lib-harmony"
3
3
  */
4
4
 
5
+ import { Tag } from "@rnoh/react-native-openharmony/ts"
6
+
5
7
  export namespace ImageCropPicker {
6
8
  export const NAME = 'ImageCropPicker' as const
7
9