Skip to content

Commit 01bed3d

Browse files
authored
Merge pull request #139 from callstack/feature/retyui/resizeMode-default-value
feature: Use the default `resizeMode: cover` value across all platforms
2 parents 3a93a25 + d74d969 commit 01bed3d

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ ImageEditor.cropImage(uri, cropData).then((url) => {
5252
| `offset` | Yes | The top-left corner of the cropped image, specified in the original image's coordinate space |
5353
| `size` | Yes | Size (dimensions) of the cropped image |
5454
| `displaySize` | No | Size to which you want to scale the cropped image |
55-
| `resizeMode` | No | Resizing mode to use when scaling the image (iOS only, Android resize mode is always 'cover', Web - no support) **Default value**: 'contain' |
55+
| `resizeMode` | No | Resizing mode to use when scaling the image (iOS only, Android resize mode is always `'cover'`, Web - no support) **Default value**: `'cover'` |
5656
| `quality` | No | The quality of the resulting image, expressed as a value from `0.0` to `1.0`. <br/>The value `0.0` represents the maximum compression (or lowest quality) while the value `1.0` represents the least compression (or best quality).<br/>iOS supports only `JPEG` format, while Android/Web supports both `JPEG`, `WEBP` and `PNG` formats.<br/>**Default value**: `0.9` |
5757
| `format` | No | The format of the resulting image, possible values are `jpeg`, `png`, `webp`. <br/> **Default value**: based on the provided image; if value determination is not possible, `jpeg` will be used as a fallback. <br/> `webp` isn't supported by iOS. |
5858

ios/RNCImageEditor.mm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#endif
2525

2626
#define DEFAULT_COMPRESSION_QUALITY 0.9
27+
#define DEFAULT_RESIZE_MODE "cover"
2728

2829
@implementation RNCImageEditor
2930

@@ -59,7 +60,7 @@ - (void) cropImage:(NSString *)uri
5960
// in pixels
6061
displaySize = [RCTConvert CGSize:@{ @"width": @(rawDisplaySize.width()), @"height": @(rawDisplaySize.height()) }];
6162
}
62-
RCTResizeMode resizeMode = [RCTConvert RCTResizeMode:data.resizeMode() ?: @"contain"];
63+
RCTResizeMode resizeMode = [RCTConvert RCTResizeMode:data.resizeMode() ?: @(DEFAULT_RESIZE_MODE)];
6364
NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString: uri]];
6465
CGFloat compressionQuality = DEFAULT_COMPRESSION_QUALITY;
6566
if (data.quality().has_value()) {
@@ -74,7 +75,7 @@ - (void) cropImage:(NSString *)uri
7475
NSString *format = cropData[@"format"];
7576
CGSize size = [RCTConvert CGSize:cropData[@"size"]];
7677
CGPoint offset = [RCTConvert CGPoint:cropData[@"offset"]];
77-
RCTResizeMode resizeMode = [RCTConvert RCTResizeMode:cropData[@"resizeMode"] ?: @"contain"];
78+
RCTResizeMode resizeMode = [RCTConvert RCTResizeMode:cropData[@"resizeMode"] ?: @(DEFAULT_RESIZE_MODE)];
7879
CGSize displaySize = CGSizeZero;
7980
BOOL hasDisplaySizeValue = cropData[@"displaySize"];
8081
if(hasDisplaySizeValue){

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type ImageCropDataFromSpec = Parameters<Spec['cropImage']>[1];
55
export interface ImageCropData
66
extends Omit<ImageCropDataFromSpec, 'resizeMode' | 'format'> {
77
format?: 'png' | 'jpeg' | 'webp';
8-
resizeMode?: 'contain' | 'cover' | 'stretch';
8+
resizeMode?: 'contain' | 'cover' | 'stretch' | 'center';
99
// ^^^ codegen doesn't support union types yet
1010
// so to provide more type safety we override the type here
1111
}

0 commit comments

Comments
 (0)