react-native-image-crop-picker
repository·master·Indexed 27 days ago
https://github.com/ivpusic/react-native-image-crop-pickerA React Native library for iOS and Android that provides access to the device's camera and photo gallery. It allows users to select single or multiple images and videos, with support for configurable compression, image cropping, and EXIF data extraction. Key functions include openPicker, openCamera, and openCropper, with utilities to clean up temporary files.
What's inside react-native-image-crop-picker
- react-native-image-crop-picker is an iOS and Android image picker library for React Native. It supports selecting images and videos from the camera or gallery, configurable compression, multiple image selection, and image cropping.
Build and run the iOS app
masterTo run the iOS application, you must first ensure CocoaPods dependencies are installed.
If this is your first time setting up the project, install CocoaPods using Ruby bundler:
bundle installEvery time you update native dependencies, run:
bundle exec pod installOnce dependencies are installed, run the app using:
# Using npm npm run ios # OR using Yarn yarn iosInstall react-native-image-crop-picker
masterTo install the package, run the following npm command in your project root:
npm i react-native-image-crop-picker --saveConfigure iOS permissions and setup
masterAfter installing the package, follow these steps for iOS:
- Install Pods: Navigate to the
iosdirectory and runpod install. - Configure Info.plist: Open
Info.plistin Xcode and add the following keys with descriptive values explaining why your app requires access:NSPhotoLibraryUsageDescription: Required for accessing the photo library.NSCameraUsageDescription: Required if you use the camera feature.NSMicrophoneUsageDescription: Required if you use the microphone feature.
Optional: Localize UI text To localize the camera, gallery, or cropper text buttons:
- Open your Xcode project.
- Select your project in the Navigation pane.
- Go to the Info tab.
- Under Localizations, click the
+button to add the desired language. - Rebuild your app.
cd ios pod install- Install Pods: Navigate to the
Reload the application
masterIf you need to perform a full reload to reset the app state, use the following methods:
- Android: Press the <kbd>R</kbd> key twice or open the Dev Menu via <kbd>Ctrl</kbd> + <kbd>M</kbd> (Windows/Linux) or <kbd>Cmd ⌘</kbd> + <kbd>M</kbd> (macOS) and select "Reload".
- iOS: Press <kbd>R</kbd> in the iOS Simulator.
Build and run the Android app
masterWith the Metro server running, use one of the following commands to build and launch your application on an Android emulator or connected device.
# Using npm npm run android # OR using Yarn yarn androidImport react-native-image-crop-picker
masterTo use the library, import the default export as
ImagePicker.import ImagePicker from "react-native-image-crop-picker";Configure Android permissions
masterFor Android, you may need to add permissions to
app/src/main/AndroidManifest.xml:Camera Access (Optional): If you want to use the camera picker, add:
<uses-permission android:name="android.permission.CAMERA"/>Front Camera Support (Optional): If you want to use the front camera, add:
<uses-feature android:name="android.hardware.camera" android:required="false" /><uses-feature android:name="android.hardware.camera.front" android:required="false" />
<uses-permission android:name="android.permission.CAMERA"/> <uses-feature android:name="android.hardware.camera" android:required="false" /> <uses-feature android:name="android.hardware.camera.front" android:required="false" />Start the Metro bundler
masterBefore running your application, you must start the Metro JavaScript build tool. Run the following command from the root of your project:
# Using npm npm start # OR using Yarn yarn startCompatibility with React Native New Architecture
masterIf you are using the React Native new architecture, you must usereact-native-image-crop-pickerversion0.50.0or higher.Crop an existing image
masterUse
ImagePicker.openCropper(options)to open the cropping interface for an image already stored on the device. You must provide thepathto the image.ImagePicker.openCropper({ path: "my-file-path.jpg", width: 300, height: 400, }).then((image) => { console.log(image); });Clean up temporary files
masterThe module creates temporary images. To manually force cleanup of these files, use
ImagePicker.clean()to remove all temporary files orImagePicker.cleanSingle(path)to remove a specific file.ImagePicker.clean() .then(() => { console.log("removed all tmp images from tmp directory"); }) .catch((e) => { alert(e); });