From c84c392fa24ff6d86d955f66237b134abc2a0889 Mon Sep 17 00:00:00 2001 From: Ivan Pusic Date: Wed, 27 Jul 2016 12:05:06 +0200 Subject: [PATCH] [iOS] Fix cropping mask on ios --- example/app.js | 5 ++--- example/ios/Podfile.lock | 20 +++++++++---------- .../xcshareddata/xcschemes/example.xcscheme | 11 ++++++---- ios/ImageCropPicker.h | 1 + ios/ImageCropPicker.m | 18 +++++------------ package.json | 2 +- 6 files changed, 26 insertions(+), 31 deletions(-) diff --git a/example/app.js b/example/app.js index 1e5078f74..abcfa8b13 100644 --- a/example/app.js +++ b/example/app.js @@ -1,7 +1,7 @@ import React, {Component} from 'react'; import {View, Text, StyleSheet, ScrollView, Image, TouchableOpacity} from 'react-native'; -import {NativeModules} from 'react-native'; +import {NativeModules, Dimensions} from 'react-native'; var ImagePicker = NativeModules.ImageCropPicker; const styles = StyleSheet.create({ @@ -64,9 +64,8 @@ export default class App extends Component { render() { return - - {this.state.image ? : null} + {this.state.image ? : null} {this.state.images ? this.state.images.map(i => ) : null} diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 57ac5264c..2f81cb932 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1,21 +1,21 @@ PODS: - QBImagePickerController (3.4.0) - - React (0.27.2): - - React/Core (= 0.27.2) - - react-native-image-crop-picker (0.4.1): + - React (0.30.0): + - React/Core (= 0.30.0) + - react-native-image-crop-picker (0.5.0): - QBImagePickerController (= 3.4.0) - React (>= 0.26.1) - RSKImageCropper (= 1.5.1) - UIImage-Resize (~> 1.0) - - React/Core (0.27.2) - - React/RCTImage (0.27.2): + - React/Core (0.30.0) + - React/RCTImage (0.30.0): - React/Core - React/RCTNetwork - - React/RCTNetwork (0.27.2): + - React/RCTNetwork (0.30.0): - React/Core - - React/RCTText (0.27.2): + - React/RCTText (0.30.0): - React/Core - - React/RCTWebSocket (0.27.2): + - React/RCTWebSocket (0.30.0): - React/Core - RSKImageCropper (1.5.1) - UIImage-Resize (1.0.1) @@ -36,8 +36,8 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: QBImagePickerController: d54cf93db6decf26baf6ed3472f336ef35cae022 - React: ed545be51aeb5c3988abb0b17bf174b87aac1a17 - react-native-image-crop-picker: 61a65301107d36401ff58b2e542c413e7a4b347d + React: ed499ad8bb72560821a80fefa59e15a18f3ec75c + react-native-image-crop-picker: 16f10164c90a0fde7807ec053609d7a0a241367c RSKImageCropper: edd65fedb3734332818deb139906d6b7f54b8a44 UIImage-Resize: fa776860f10e6900bbaf53a73e494bdceaaccc77 diff --git a/example/ios/example.xcodeproj/xcshareddata/xcschemes/example.xcscheme b/example/ios/example.xcodeproj/xcshareddata/xcschemes/example.xcscheme index 288dc5c56..79ba650c8 100644 --- a/example/ios/example.xcodeproj/xcshareddata/xcschemes/example.xcscheme +++ b/example/ios/example.xcodeproj/xcshareddata/xcschemes/example.xcscheme @@ -37,10 +37,10 @@ + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -62,15 +62,18 @@ ReferencedContainer = "container:example.xcodeproj"> + + @@ -86,10 +89,10 @@ diff --git a/ios/ImageCropPicker.h b/ios/ImageCropPicker.h index e689b18aa..7128fe59e 100644 --- a/ios/ImageCropPicker.h +++ b/ios/ImageCropPicker.h @@ -14,6 +14,7 @@ #import #import #import "UIImage+Resize.h" +#import @interface ImageCropPicker : NSObject< RCTBridgeModule, diff --git a/ios/ImageCropPicker.m b/ios/ImageCropPicker.m index 2ceeb770b..a261773bb 100644 --- a/ios/ImageCropPicker.m +++ b/ios/ImageCropPicker.m @@ -185,19 +185,11 @@ - (CGRect) scaleRect:(RSKImageCropViewController *)controller { CGFloat viewWidth = CGRectGetWidth(controller.view.frame); CGFloat viewHeight = CGRectGetHeight(controller.view.frame); - if (rect.size.width > viewWidth) { - float scaleFactor = viewWidth / rect.size.width; - rect.size.width *= scaleFactor; - rect.size.height *= scaleFactor; - rect.origin.x = 0; - rect.origin.y = viewHeight / 2 * 0.5f; - } else if (rect.size.height > viewHeight) { - float scaleFactor = viewHeight / rect.size.height; - rect.size.width *= scaleFactor; - rect.size.height *= scaleFactor; - rect.origin.x = viewWidth / 2 * 0.5f; - rect.origin.y = 0; - } + double scaleFactor = fmin(viewWidth / rect.size.width, viewHeight / rect.size.height); + rect.size.width *= scaleFactor; + rect.size.height *= scaleFactor; + rect.origin.x = (viewWidth - rect.size.width) / 2; + rect.origin.y = (viewHeight - rect.size.height) / 2; return rect; } diff --git a/package.json b/package.json index f3daed63f..f7e7b60c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-image-crop-picker", - "version": "0.5.0", + "version": "0.5.1", "description": "Select single or multiple images, with croping option", "main": "index.js", "scripts": {