Skip to content

Commit

Permalink
[iOS] Fix cropping mask on ios
Browse files Browse the repository at this point in the history
  • Loading branch information
ivpusic committed Jul 27, 2016
1 parent 11ebebd commit c84c392
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 31 deletions.
5 changes: 2 additions & 3 deletions example/app.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -64,9 +64,8 @@ export default class App extends Component {

render() {
return <View style={styles.container}>

<ScrollView>
{this.state.image ? <Image style={{width: this.state.image.width, height: this.state.image.height}} source={this.state.image} /> : null}
{this.state.image ? <Image style={{width: 300, height: 300, resizeMode: 'contain'}} source={this.state.image} /> : null}
{this.state.images ? this.state.images.map(i => <Image key={i.uri} style={{width: 300, height: this.scaledHeight(i.width, i.height, 300)}} source={i} />) : null}
</ScrollView>

Expand Down
20 changes: 10 additions & 10 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -62,15 +62,18 @@
ReferencedContainer = "container:example.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand All @@ -86,10 +89,10 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand Down
1 change: 1 addition & 0 deletions ios/ImageCropPicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#import <QBImagePickerController/QBImagePickerController.h>
#import <RSKImageCropper/RSKImageCropper.h>
#import "UIImage+Resize.h"
#import <math.h>

@interface ImageCropPicker : NSObject<
RCTBridgeModule,
Expand Down
18 changes: 5 additions & 13 deletions ios/ImageCropPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit c84c392

Please sign in to comment.