@@ -52,12 +52,14 @@ - (void) cropImage:(NSString *)uri
52
52
CGSize size = [RCTConvert CGSize: @{ @" width" : @(data.size ().width ()), @" height" : @(data.size ().height ()) }];
53
53
CGPoint offset = [RCTConvert CGPoint: @{ @" x" : @(data.offset ().x ()), @" y" : @(data.offset ().y ()) }];
54
54
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
57
59
// in pixels
58
- targetSize = [RCTConvert CGSize: @{ @" width" : @(displaySize .width ()), @" height" : @(displaySize .height ()) }];
60
+ displaySize = [RCTConvert CGSize: @{ @" width" : @(rawDisplaySize .width ()), @" height" : @(rawDisplaySize .height ()) }];
59
61
}
60
- NSString *displaySize = data.resizeMode ();
62
+ RCTResizeMode resizeMode = [RCTConvert RCTResizeMode: data.resizeMode () ?: @" contain " ] ;
61
63
NSURLRequest *imageRequest = [NSURLRequest requestWithURL: [NSURL URLWithString: uri]];
62
64
CGFloat compressionQuality = DEFAULT_COMPRESSION_QUALITY;
63
65
if (data.quality ().has_value ()) {
@@ -72,10 +74,11 @@ - (void) cropImage:(NSString *)uri
72
74
NSString *format = cropData[@" format" ];
73
75
CGSize size = [RCTConvert CGSize: cropData[@" size" ]];
74
76
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" ]];
79
82
}
80
83
CGFloat compressionQuality = DEFAULT_COMPRESSION_QUALITY;
81
84
if (cropData[@" quality" ]){
@@ -101,13 +104,14 @@ - (void) cropImage:(NSString *)uri
101
104
}
102
105
103
106
// Crop image
107
+ CGSize targetSize = rect.size ;
104
108
CGRect targetRect = {{-rect.origin .x , -rect.origin .y }, image.size };
105
109
CGAffineTransform transform = RCTTransformFromTargetRect (image.size , targetRect);
106
110
UIImage *croppedImage = RCTTransformImage (image, targetSize, image.scale , transform);
107
111
108
112
// Scale image
109
- if (displaySize ) {
110
- RCTResizeMode resizeMode = [RCTConvert RCTResizeMode: displaySize ?: @" contain " ] ;
113
+ if (hasDisplaySizeValue ) {
114
+ targetSize = displaySize;
111
115
targetRect = RCTTargetRect (croppedImage.size , targetSize, 1 , resizeMode);
112
116
transform = RCTTransformFromTargetRect (croppedImage.size , targetRect);
113
117
croppedImage = RCTTransformImage (croppedImage, targetSize, image.scale , transform);
0 commit comments