Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Set initial zoom level of the cropper #1942

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
10 changes: 10 additions & 0 deletions ios/src/ImageCropPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ - (instancetype)init
@"sortOrder": @"none",
@"cropperCancelText": @"Cancel",
@"cropperChooseText": @"Choose",
@"cropperInitialZoom": @1,
@"cropperRotateButtonsHidden": @NO
};
self.compression = [[Compression alloc] init];
Expand Down Expand Up @@ -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];
}
Expand Down