react-native-image-text-cropper
Image cropper for react native made with Animated API (with rotation possibility) - for iOS & android
This component depend on react-native-image-rotate
library. It needs to be installed and linked to your project before.
STEPS TO INSTALL:
npm install --save react-native-image-rotate
react-native link react-native-image-rotate
npm install --save react-native-image-text-cropper
Properties
Prop | Type | Description |
---|---|---|
onDone | function |
A function which accepts 1 argument croppedImageUri . Called when user press the 'DONE' button |
onCancel | function |
A function without arguments. Called when user press the 'CANCEL' button |
imageUri | string |
The uri of the image you want to crop or rotate |
imageWidth | number |
The width (in pixels) of the image you passed in imageUri |
imageHeight | number |
The height (in pixels) of the image you passed in imageUri |
initialRotation | number |
Number which set the default rotation of the image when cropper is initialized. Default is 0 |
footerComponent | component |
Custom component for footer. Default is <DefaultFooter doneText='DONE' rotateText='ROTATE' cancelText='CANCEL' /> |
NOT_SELECTED_AREA_OPACITY | number |
The opacity of the area which is not selected by the cropper. Should be a value between 0 and 1 . Default is 0.5 |
BORDER_WIDTH | number |
The border width (see image). Default is 50 |
Usage example 1 (using the default footer)
;;;;; { console; if PlatformOS === 'ios' ImageStore; else // send image to server // navigate to the next page of your application Actions; } { // navigate back Actions; } { return <AmazingCropper onDone=thisonDone onCancel=thisonCancel imageUri='https://www.lifeofpix.com/wp-content/uploads/2018/09/manhattan_-11-1600x2396.jpg' imageWidth=1600 imageHeight=2396 NOT_SELECTED_AREA_OPACITY=03 BORDER_WIDTH=20 /> ; }
Usage example 2 (using the default footer with custom text)
;;;; { console; if PlatformOS === 'ios' ImageStore; else // send image to server // navigate to the next page of your application Actions; } { // navigate back Actions; } { return <AmazingCropper // Pass custom text to the default footer footerComponent=<DefaultFooter doneText='OK' rotateText='ROT' cancelText='BACK' /> onDone=thisonDone onCancel=thisonCancel imageUri='https://www.lifeofpix.com/wp-content/uploads/2018/09/manhattan_-11-1600x2396.jpg' imageWidth=1600 imageHeight=2396 /> ; }
Usage example 3 (using own fully customized footer)
Write your custom footer component.
Don't forget to call the props.onDone, props.onRotate and props.onCancel methods inside it (the Cropper will pass them automatically to your footer component). Example of custom footer component:
;;;; const CustomCropperFooter = <View style=stylesbuttonsContainer> <TouchableOpacity onPress=propsonCancel style=stylestouchable> <Text style=stylestext>CANCEL</Text> </TouchableOpacity> <TouchableOpacity onPress=propsonRotate style=stylestouchable> <MaterialCommunityIcon name='format-rotate-90' style=stylesrotateIcon /> </TouchableOpacity> <TouchableOpacity onPress=propsonDone style=stylestouchable> <Text style=stylestext>DONE</Text> </TouchableOpacity> </View> ; CustomCropperFooterpropTypes = onDone: PropTypesfunc onRotate: PropTypesfunc onCancel: PropTypesfunc const styles = StyleSheet
Now just pass your footer component to the Cropper like here:
;;;;; { console; if PlatformOS === 'ios' ImageStore; else // send image to server // navigate to the next page of your application Actions; } { // navigate back Actions; } { return <AmazingCropper // Use your custom footer component // Do NOT pass onDone, onRotate and onCancel to the footer component, the Cropper will do it for you footerComponent=<CustomCropperFooter /> onDone=thisonDone onCancel=thisonCancel imageUri='https://www.lifeofpix.com/wp-content/uploads/2018/09/manhattan_-11-1600x2396.jpg' imageWidth=1600 imageHeight=2396 /> ; }