@@ -50,12 +50,14 @@ - (void) cropImage:(NSString *)uri
50
50
CGSize size = [RCTConvert CGSize: @{ @" width" : @(data.size ().width ()), @" height" : @(data.size ().height ()) }];
51
51
CGPoint offset = [RCTConvert CGPoint: @{ @" x" : @(data.offset ().x ()), @" y" : @(data.offset ().y ()) }];
52
52
CGSize targetSize = size;
53
- if (data.displaySize ().has_value ()) {
54
- JS::NativeRNCImageEditor::SpecCropImageCropDataDisplaySize displaySize = *data.displaySize (); // Extract the value from the optional
53
+ CGSize displaySize = CGSizeZero;
54
+ BOOL hasDisplaySizeValue = data.displaySize ().has_value ();
55
+ if (hasDisplaySizeValue) {
56
+ JS::NativeRNCImageEditor::SpecCropImageCropDataDisplaySize rawDisplaySize = *data.displaySize (); // Extract the value from the optional
55
57
// in pixels
56
- targetSize = [RCTConvert CGSize: @{ @" width" : @(displaySize .width ()), @" height" : @(displaySize .height ()) }];
58
+ displaySize = [RCTConvert CGSize: @{ @" width" : @(rawDisplaySize .width ()), @" height" : @(rawDisplaySize .height ()) }];
57
59
}
58
- NSString *displaySize = data.resizeMode ();
60
+ RCTResizeMode resizeMode = [RCTConvert RCTResizeMode: data.resizeMode () ?: @" contain " ] ;
59
61
NSURLRequest *imageRequest = [NSURLRequest requestWithURL: [NSURL URLWithString: uri]];
60
62
CGFloat compressionQuality = 1 ;
61
63
if (data.quality ().has_value ()) {
@@ -70,10 +72,11 @@ - (void) cropImage:(NSString *)uri
70
72
NSString *format = cropData[@" format" ];
71
73
CGSize size = [RCTConvert CGSize: cropData[@" size" ]];
72
74
CGPoint offset = [RCTConvert CGPoint: cropData[@" offset" ]];
73
- CGSize targetSize = size;
74
- NSString *displaySize = cropData[@" resizeMode" ];
75
- if (displaySize){
76
- targetSize = [RCTConvert CGSize: cropData[@" displaySize" ]];
75
+ RCTResizeMode resizeMode = [RCTConvert RCTResizeMode: cropData[@" resizeMode" ] ?: @" contain" ];
76
+ CGSize displaySize = CGSizeZero;
77
+ BOOL hasDisplaySizeValue = cropData[@" displaySize" ];
78
+ if (hasDisplaySizeValue){
79
+ displaySize = [RCTConvert CGSize: cropData[@" displaySize" ]];
77
80
}
78
81
CGFloat compressionQuality = 1 ;
79
82
if (cropData[@" quality" ]){
@@ -99,13 +102,14 @@ - (void) cropImage:(NSString *)uri
99
102
}
100
103
101
104
// Crop image
105
+ CGSize targetSize = rect.size ;
102
106
CGRect targetRect = {{-rect.origin .x , -rect.origin .y }, image.size };
103
107
CGAffineTransform transform = RCTTransformFromTargetRect (image.size , targetRect);
104
108
UIImage *croppedImage = RCTTransformImage (image, targetSize, image.scale , transform);
105
109
106
110
// Scale image
107
- if (displaySize ) {
108
- RCTResizeMode resizeMode = [RCTConvert RCTResizeMode: displaySize ?: @" contain " ] ;
111
+ if (hasDisplaySizeValue ) {
112
+ targetSize = displaySize;
109
113
targetRect = RCTTargetRect (croppedImage.size , targetSize, 1 , resizeMode);
110
114
transform = RCTTransformFromTargetRect (croppedImage.size , targetRect);
111
115
croppedImage = RCTTransformImage (croppedImage, targetSize, image.scale , transform);
0 commit comments