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

Return cropped image rectangle #458

Merged
merged 5 commits into from
Dec 7, 2017
Merged
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@ buildscript {
}
```

- Add the following to your `build.gradle`'s repositories section. (project build.gradle)
```gradle
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
```

- Add `useSupportLibrary` (app build.gradle)

```gradle
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ android {

dependencies {
compile 'com.facebook.react:react-native:+'
compile 'com.yalantis:ucrop:2.2.0-native'
compile 'com.github.yalantis:ucrop:2.2.1-native'
compile 'id.zelory:compressor:2.1.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,11 @@ private void croppingResult(Activity activity, final int requestCode, final int
final Uri resultUri = UCrop.getOutput(data);
if (resultUri != null) {
try {
WritableMap result = getSelection(activity, resultUri, false);
result.putMap("cropRect", PickerModule.getCroppedRectMap(data));

resultCollector.setWaitCount(1);
resultCollector.notifySuccess(getSelection(activity, resultUri, false));
resultCollector.notifySuccess(result);
} catch (Exception ex) {
resultCollector.notifyProblem(E_NO_IMAGE_DATA_FOUND, ex.getMessage());
}
Expand Down Expand Up @@ -729,4 +732,16 @@ private File createImageFile() throws IOException {
return image;

}

private static WritableMap getCroppedRectMap(Intent data) {
final int DEFAULT_VALUE = -1;
final WritableMap map = new WritableNativeMap();

map.putInt("x", data.getIntExtra(UCrop.EXTRA_OUTPUT_OFFSET_X, DEFAULT_VALUE));
map.putInt("y", data.getIntExtra(UCrop.EXTRA_OUTPUT_OFFSET_Y, DEFAULT_VALUE));
map.putInt("width", data.getIntExtra(UCrop.EXTRA_OUTPUT_IMAGE_WIDTH, DEFAULT_VALUE));
map.putInt("height", data.getIntExtra(UCrop.EXTRA_OUTPUT_IMAGE_HEIGHT, DEFAULT_VALUE));

return map;
}
}
8 changes: 8 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ declare module "react-native-image-crop-picker" {
height: number;
mime: string;
exif: null | object;
cropRect: null | CropRect
}

export interface CropRect {
x: number;
y: number;
width: number;
height: number;
}

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