$ yarn add github:Radweb/react-native-crop-image
$ react-native link react-native-crop-image
- In XCode, in the project navigator, right click
Libraries➜Add Files to [your project's name] - Go to
node_modules➜react-native-crop-imageand addRNCropImage.xcodeproj - In XCode, in the project navigator, select your project. Add
libRNCropImage.ato your project'sBuild Phases➜Link Binary With Libraries - Run your project (
Cmd+R)<
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.radweb.cropimage.RNCropImagePackage;to the imports at the top of the file - Add
new RNCropImagePackage()to the list returned by thegetPackages()method
- Append the following lines to
android/settings.gradle:include ':react-native-crop-image' project(':react-native-crop-image').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-crop-image/android') - Insert the following lines inside the dependencies block in
android/app/build.gradle:compile project(':react-native-crop-image')
import crop from 'react-native-crop-image';
await crop(diskPathToImage, {
width: 100, // Desired width to crop to
height: 100, // Desired height to crop to
left: 50, // Offset from the left of the image
top: 50, // Offset from the top of the image
})-
path- The native path to the file (so no leadingfile://, no image store path, etc) -
cropData- Defines the crop area within the coordinate space of the image.widthandheightare required,leftandtopdefault to 0 -
Returns - Path to cropped image, usable as the uri in
Imagecomponent sources. Located in a temp directory on ios