@@ -52,12 +52,14 @@ - (void) cropImage:(NSString *)uri
5252 CGSize size = [RCTConvert CGSize: @{ @" width" : @(data.size ().width ()), @" height" : @(data.size ().height ()) }];
5353 CGPoint offset = [RCTConvert CGPoint: @{ @" x" : @(data.offset ().x ()), @" y" : @(data.offset ().y ()) }];
5454 CGSize targetSize = size;
55- if (data.displaySize ().has_value ()) {
56- JS::NativeRNCImageEditor::SpecCropImageCropDataDisplaySize displaySize = *data.displaySize (); // Extract the value from the optional
55+ CGSize displaySize = CGSizeZero;
56+ BOOL hasDisplaySizeValue = data.displaySize ().has_value ();
57+ if (hasDisplaySizeValue) {
58+ JS::NativeRNCImageEditor::SpecCropImageCropDataDisplaySize rawDisplaySize = *data.displaySize (); // Extract the value from the optional
5759 // in pixels
58- targetSize = [RCTConvert CGSize: @{ @" width" : @(displaySize .width ()), @" height" : @(displaySize .height ()) }];
60+ displaySize = [RCTConvert CGSize: @{ @" width" : @(rawDisplaySize .width ()), @" height" : @(rawDisplaySize .height ()) }];
5961 }
60- NSString *displaySize = data.resizeMode ();
62+ RCTResizeMode resizeMode = [RCTConvert RCTResizeMode: data.resizeMode () ?: @" contain " ] ;
6163 NSURLRequest *imageRequest = [NSURLRequest requestWithURL: [NSURL URLWithString: uri]];
6264 CGFloat compressionQuality = DEFAULT_COMPRESSION_QUALITY;
6365 if (data.quality ().has_value ()) {
@@ -72,10 +74,11 @@ - (void) cropImage:(NSString *)uri
7274 NSString *format = cropData[@" format" ];
7375 CGSize size = [RCTConvert CGSize: cropData[@" size" ]];
7476 CGPoint offset = [RCTConvert CGPoint: cropData[@" offset" ]];
75- CGSize targetSize = size;
76- NSString *displaySize = cropData[@" resizeMode" ];
77- if (displaySize){
78- targetSize = [RCTConvert CGSize: cropData[@" displaySize" ]];
77+ RCTResizeMode resizeMode = [RCTConvert RCTResizeMode: cropData[@" resizeMode" ] ?: @" contain" ];
78+ CGSize displaySize = CGSizeZero;
79+ BOOL hasDisplaySizeValue = cropData[@" displaySize" ];
80+ if (hasDisplaySizeValue){
81+ displaySize = [RCTConvert CGSize: cropData[@" displaySize" ]];
7982 }
8083 CGFloat compressionQuality = DEFAULT_COMPRESSION_QUALITY;
8184 if (cropData[@" quality" ]){
@@ -101,13 +104,14 @@ - (void) cropImage:(NSString *)uri
101104 }
102105
103106 // Crop image
107+ CGSize targetSize = rect.size ;
104108 CGRect targetRect = {{-rect.origin .x , -rect.origin .y }, image.size };
105109 CGAffineTransform transform = RCTTransformFromTargetRect (image.size , targetRect);
106110 UIImage *croppedImage = RCTTransformImage (image, targetSize, image.scale , transform);
107111
108112 // Scale image
109- if (displaySize ) {
110- RCTResizeMode resizeMode = [RCTConvert RCTResizeMode: displaySize ?: @" contain " ] ;
113+ if (hasDisplaySizeValue ) {
114+ targetSize = displaySize;
111115 targetRect = RCTTargetRect (croppedImage.size , targetSize, 1 , resizeMode);
112116 transform = RCTTransformFromTargetRect (croppedImage.size , targetRect);
113117 croppedImage = RCTTransformImage (croppedImage, targetSize, image.scale , transform);
0 commit comments