diff --git a/README.md b/README.md index 912cf84..bedc099 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ Option | Type | Description ------ | ------ | ------------------------------------------------ width | number | The width of the image you would like returned. height | number | The height of the image you would like returned. +lockSquare | boolean | Pass this as true, to lock square aspect ratio on iOS, on android, this option doesn't make any difference. ### Additional notes for Android You can override library colors just specifying colors with the same names in your colors.xml file. diff --git a/src/imagecropper.ios.ts b/src/imagecropper.ios.ts index 7e38bc4..9f9472a 100644 --- a/src/imagecropper.ios.ts +++ b/src/imagecropper.ios.ts @@ -20,6 +20,8 @@ declare class TOCropViewController extends UIViewController { delegate: any; cropView: TOCropView; toolbar: TOCropToolbar; + defaultAspectRatio: any; + aspectRatioLocked: boolean; public setAspectRatioLocked(aspectRatioLocked: boolean): void; public setRotateButtonHidden(rotateButtonHidden: boolean): void; public setRotateClockwiseButtonHidden(rotateClockwiseButtonHidden: boolean): void; @@ -115,21 +117,22 @@ export class ImageCropper { if (image.ios) { var viewController = TOCropViewController.alloc().initWithImage(image.ios); var delegate = TOCropViewControllerDelegateImpl.initWithOwner(new WeakRef(viewController)); - delegate.initResolveReject(resolve, reject); - CFRetain(delegate); viewController.delegate = delegate; - var page = frame.topmost().ios.controller; + if (_options.lockSquare) { + viewController.defaultAspectRatio = 1; + viewController.aspectRatioLocked = true; // The crop box is locked to the aspect ratio and can't be resized away from it + } page.presentViewControllerAnimatedCompletion(viewController, true, function () { - //Set Fixed Crop Size - if (_options && _options.width && _options.height) { - var gcd = _that._gcd(_options.width, _options.height); + if (_options) { + if (_options.width && _options.height) { + var gcd = _that._gcd(_options.width, _options.height); + viewController.toolbar.clampButtonHidden = true; + viewController.cropView.setAspectLockEnabledWithAspectRatioAnimated(CGSizeMake(_options.width / gcd, _options.height / gcd), false); + } - viewController.toolbar.clampButtonHidden = true; - // viewController.toolbar.setNeedsLayout(); - viewController.cropView.setAspectLockEnabledWithAspectRatioAnimated(CGSizeMake(_options.width / gcd, _options.height / gcd), false); } }); } diff --git a/src/interfaces.ts b/src/interfaces.ts index 28507d4..905550b 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -2,7 +2,8 @@ import * as imageSource from 'tns-core-modules/image-source'; export interface OptionsCommon{ width?: number, - height?: number + height?: number, + lockSquare?: number } export interface Result{ diff --git a/src/package.json b/src/package.json index f19224b..d0e75e5 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "nativescript-imagecropper", - "version": "0.1.1", + "version": "0.1.2", "description": "NativeScript Image Cropper Plugin", "main": "imagecropper", "typings": "index.d.ts",