From d6363c613e861f59ed376a022cbbd428f0736bca Mon Sep 17 00:00:00 2001 From: Gevorg Gasparyan Date: Fri, 7 Jul 2023 12:53:56 +0400 Subject: [PATCH] feat: Set initial zoom level of the cropper --- README.md | 1 + index.d.ts | 8 ++++++++ ios/src/ImageCropPicker.m | 10 ++++++++++ 3 files changed, 19 insertions(+) diff --git a/README.md b/README.md index 2aaad26f6..de88b97e4 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,7 @@ ImagePicker.clean().then(() => { | cropperCancelText (ios only) | string (default Cancel) | Cancel button text | | cropperCancelColor (ios only) | string (default tint `iOS` color ) | HEX format color for the Cancel button. Default value is the default tint iOS color [controlled by TOCropViewController](https://github.com/TimOliver/TOCropViewController/blob/a942414508012b13102f776eb65dac655f31cabb/Objective-C/TOCropViewController/Views/TOCropToolbar.m#L433) | | cropperRotateButtonsHidden (ios only)  |           bool (default false)        | Enable or disable cropper rotate buttons | +| cropperInitialZoom (ios only)  |           number (default 1)        | Set initial zoom level of the cropper | #### Smart Album Types (ios) diff --git a/index.d.ts b/index.d.ts index ef2a88269..27595cee5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -286,6 +286,14 @@ declare module "react-native-image-crop-picker" { */ cropperRotateButtonsHidden?: boolean + /** + * Initial zoom level of the cropper. + * + * @platform iOS only + * @default 1 + */ + cropperInitialZoom?: number + /** * Whether to show the 3x3 grid on top of the image during cropping. * diff --git a/ios/src/ImageCropPicker.m b/ios/src/ImageCropPicker.m index 9f20973f1..153dcfaa6 100644 --- a/ios/src/ImageCropPicker.m +++ b/ios/src/ImageCropPicker.m @@ -72,6 +72,7 @@ - (instancetype)init @"sortOrder": @"none", @"cropperCancelText": @"Cancel", @"cropperChooseText": @"Choose", + @"cropperInitialZoom": @1, @"cropperRotateButtonsHidden": @NO }; self.compression = [[Compression alloc] init]; @@ -900,6 +901,15 @@ - (void)cropImage:(UIImage *)image { NSString* rawDoneButtonColor = [self.options objectForKey:@"cropperChooseColor"]; NSString* rawCancelButtonColor = [self.options objectForKey:@"cropperCancelColor"]; + CGFloat zoomRatio = [[self.options objectForKey:@"cropperInitialZoom"] floatValue]; + if (zoomRatio > 1) { + CGFloat cropWidth = image.size.width - image.size.width / zoomRatio; + CGFloat cropHeight = image.size.width - image.size.height / zoomRatio; + CGFloat cropX = (image.size.width - cropWidth) / 2; + CGFloat cropY = (image.size.height - cropHeight) / 2; + cropVC.imageCropFrame = CGRectMake(cropX, cropY, cropWidth, cropHeight); + } + if (rawDoneButtonColor) { cropVC.doneButtonColor = [ImageCropPicker colorFromHexString: rawDoneButtonColor]; }