Skip to content

Commit 5633a99

Browse files
ivan-magdaivpusic
authored andcommitted
Return cropped image rectangle (ivpusic#458)
* android: Update ucrop version ivpusic#457 Use latest uCrop version. * Return cropped image rectangle ivpusic#457 * Update README.md ivpusic#457 Update Android installation instructions.
1 parent 1476fd8 commit 5633a99

File tree

5 files changed

+133
-83
lines changed

5 files changed

+133
-83
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,16 @@ buildscript {
202202
}
203203
```
204204

205+
- Add the following to your `build.gradle`'s repositories section. (project build.gradle)
206+
```gradle
207+
allprojects {
208+
repositories {
209+
jcenter()
210+
maven { url "https://jitpack.io" }
211+
}
212+
}
213+
```
214+
205215
- Add `useSupportLibrary` (app build.gradle)
206216

207217
```gradle

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ android {
1616

1717
dependencies {
1818
compile 'com.facebook.react:react-native:+'
19-
compile 'com.yalantis:ucrop:2.2.0-native'
19+
compile 'com.github.yalantis:ucrop:2.2.1-native'
2020
compile 'id.zelory:compressor:2.1.0'
2121
}

android/src/main/java/com/reactnative/ivpusic/imagepicker/PickerModule.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,11 @@ private void croppingResult(Activity activity, final int requestCode, final int
678678
final Uri resultUri = UCrop.getOutput(data);
679679
if (resultUri != null) {
680680
try {
681+
WritableMap result = getSelection(activity, resultUri, false);
682+
result.putMap("cropRect", PickerModule.getCroppedRectMap(data));
683+
681684
resultCollector.setWaitCount(1);
682-
resultCollector.notifySuccess(getSelection(activity, resultUri, false));
685+
resultCollector.notifySuccess(result);
683686
} catch (Exception ex) {
684687
resultCollector.notifyProblem(E_NO_IMAGE_DATA_FOUND, ex.getMessage());
685688
}
@@ -729,4 +732,16 @@ private File createImageFile() throws IOException {
729732
return image;
730733

731734
}
735+
736+
private static WritableMap getCroppedRectMap(Intent data) {
737+
final int DEFAULT_VALUE = -1;
738+
final WritableMap map = new WritableNativeMap();
739+
740+
map.putInt("x", data.getIntExtra(UCrop.EXTRA_OUTPUT_OFFSET_X, DEFAULT_VALUE));
741+
map.putInt("y", data.getIntExtra(UCrop.EXTRA_OUTPUT_OFFSET_Y, DEFAULT_VALUE));
742+
map.putInt("width", data.getIntExtra(UCrop.EXTRA_OUTPUT_IMAGE_WIDTH, DEFAULT_VALUE));
743+
map.putInt("height", data.getIntExtra(UCrop.EXTRA_OUTPUT_IMAGE_HEIGHT, DEFAULT_VALUE));
744+
745+
return map;
746+
}
732747
}

index.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ declare module "react-native-image-crop-picker" {
3333
height: number;
3434
mime: string;
3535
exif: null | object;
36+
cropRect: null | CropRect
37+
}
38+
39+
export interface CropRect {
40+
x: number;
41+
y: number;
42+
width: number;
43+
height: number;
3644
}
3745

3846
export function openPicker(options: Options): Promise<Image | Image[]>;

0 commit comments

Comments
 (0)