forked from ivpusic/react-native-image-crop-picker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCropView.js
52 lines (44 loc) · 1.23 KB
/
CropView.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React, { createRef } from "react";
import {
findNodeHandle,
requireNativeComponent,
UIManager,
} from "react-native";
const RCTCropView = requireNativeComponent("RCTCropView");
class CropView extends React.PureComponent {
static defaultProps = {
keepAspectRatio: false,
};
viewRef = createRef();
saveImage = (preserveTransparency = true, quality = 90) => {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.viewRef.current),
UIManager.getViewManagerConfig("RCTCropView").Commands.saveImage,
[preserveTransparency, quality]
);
};
rotateImage = (clockwise = true) => {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.viewRef.current),
UIManager.getViewManagerConfig("RCTCropView").Commands.rotateImage,
[clockwise]
);
};
render() {
const { sourceUrl, style, onImageCrop, keepAspectRatio, aspectRatio } =
this.props;
return (
<RCTCropView
ref={this.viewRef}
sourceUrl={sourceUrl}
style={style}
onImageSaved={(event) => {
onImageCrop(event.nativeEvent);
}}
keepAspectRatio={keepAspectRatio}
cropAspectRatio={aspectRatio}
/>
);
}
}
export default CropView;