React Native Multiple Image Picker

repository·main·Indexed 20 days ago

https://github.com/nitrogenzlab/react-native-multiple-image-picker

A library for picking images and videos from multiple smart albums on iOS and Android, built upon HXPhotoPicker and PictureSelector. It provides functionality to open a media picker via openPicker, capture photos and videos using openCamera, and crop images with openCropper. Supports custom UI themes, selection limits, media type filtering, and multiple interface languages.

Tokens
12.6K
Snippets
38
Records
58
Agent score
71%

What's inside @baronha/react-native-multiple-image-picker

  1. Overview of React Native Multiple Image Picker

    main

    React Native Multiple Image Picker (RNMIP) is a library that enables applications to pick both images and videos from multiple smart albums on both iOS and Android.

    It is built upon two native libraries:

    • HXPhotoPicker (for iOS)
    • PictureSelector (for Android)

    It is designed for high performance and supports advanced features like iCloud Photo Library on iOS and smart album selection (camera roll, selfies, favorites, etc.) on both platforms.

  2. Key features of React Native Multiple Image Picker

    main

    The library provides a comprehensive suite of media picking features:

    • Media Selection: Choose multiple images and videos; supports smart albums like camera roll, selfies, panoramas, favorites, and videos.
    • Editing & Preview: Includes image cropping (single/multiple) and media previewing.
    • Capture: Includes a camera module for capturing photos and recording videos.
    • UI Customization: Customize the picker appearance using options like numberOfColumn, spacing, and primaryColor. Supports both Dark Mode and Light Mode.
    • UX Enhancements:
      • Keep previous selections.
      • Maintain selected order index.
      • Display video duration.
      • High scrolling performance.
    • Platform Specifics: Supports iCloud Photo Library on iOS.
  3. Configure iOS permissions in Info.plist

    main

    For React Native CLI projects, you must add usage descriptions to your Info.plist inside the outermost <dict> tag to request access to the photo library, camera, and microphone.

    <key>NSPhotoLibraryAddUsageDescription</key>
    <string>$(PRODUCT_NAME) needs photo library permissions</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>$(PRODUCT_NAME) needs photo library permissions</string>
    <!--  if you allow camera, you need to add this:-->
    <key>NSCameraUsageDescription</key>
    <string>$(PRODUCT_NAME) needs to access your Camera</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>$(PRODUCT_NAME) needs to access your microphone so that you can record audio.</string>
  4. Configure Camera permissions for iOS and Android

    main

    To use the camera module, you must add the following permissions to your native configuration files.

    iOS

    Add these keys to your Info.plist:

    <key>NSCameraUsageDescription</key>
    <string>Camera access is required to take photos and videos</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>Microphone access is required to record videos</string>

    Android

    Add these permissions to your AndroidManifest.xml:

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <key>NSCameraUsageDescription</key>
    <string>Camera access is required to take photos and videos</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>Microphone access is required to record videos</string>
  5. Configure iOS permissions in Managed Expo

    main

    For Managed Expo projects, add the permission keys to the ios.infoPlist section of your app.json, app.config.json, or app.config.js. After updating the config, run npx expo prebuild and build a new binary using EAS.

    {
      "name": "my app",
      "ios": {
        "infoPlist": {
          "NSPhotoLibraryAddUsageDescription": "$(PRODUCT_NAME) needs photo library permissions",
          "NSPhotoLibraryUsageDescription": "$(PRODUCT_NAME) needs photo library permissions",
          "NSCameraUsageDescription": "$(PRODUCT_NAME) needs to access your Camera",
          "NSMicrophoneUsageDescription": "$(PRODUCT_NAME) needs to access your microphone so that you can record audio"
        }
      }
    }
    npx expo prebuild
    eas build
  6. Use the Multiple Image Picker with openPicker()

    main

    To launch the image picker interface, import openPicker and a Config type from @baronha/react-native-multiple-image-picker. Pass a configuration object to openPicker(), which returns a Promise that resolves with the selected media. Use a try/catch block to handle potential errors during the picking process.

    import { openPicker, Config } from '@baronha/react-native-multiple-image-picker'
    
    const config: Config = {
      maxSelect: 10,
      maxVideo: 10,
      primaryColor: '#F6B35D',
      backgroundDark: '#2f2f2f',
      numberOfColumn: 4,
      mediaType: 'all',
      selectBoxStyle: 'number',
      selectMode: 'multiple',
      language: 'vi',
      theme: 'dark',
      isHiddenOriginalButton: false,
    }
    
    const onPicker = async () => {
      try {
        const response = await openPicker(config)
        // response contains the selected images/videos
        setImages(response)
      } catch (e) {
        // catch error for multiple image picker
      }
    }
  7. Install @baronha/react-native-multiple-image-picker

    main

    Before installing the picker, you must ensure react-native-nitro-modules is installed. Choose the command set corresponding to your environment (React Native CLI or Expo).

    ### React Native CLI
    ```bash
    yarn add @baronha/react-native-multiple-image-picker
    yarn add -D react-native-nitro-modules
    cd ios && pod install

    Expo

    npx expo install @baronha/react-native-multiple-image-picker 
    npx expo install react-native-nitro-modules -- --dev
    npx expo prebuild
  8. Localize the Picker interface

    main

    You can change the language of the interface or provide custom text for specific buttons.

    Custom Text Labels (text object):

    • finish: Text for the finish/done button.
    • original: Text for the original button.
    • preview: Text for the preview button.
    • edit: Text for the edit button.

    Interface Language (language string): Supported values: system (default), zh-Hans, zh-Hant, ja, ko, en, vi, ru, de, fr, ar.

    iOS Only support: id (Indonesian), th (Thai).

  9. Customize Picker UI Theme and Layout

    main

    You can customize the visual appearance of the picker using the following keys:

    • theme: The color mode. Options: light, dark, system (default).
    • primaryColor: The color for primary UI elements (default: #2979ff).
    • backgroundDark: The background color for dark mode (default: #1A1A1A).
    • selectBoxStyle: How the selection indicator appears. Options: number (shows numbers, default), tick (shows checkmark).
    • spacing: Grid item spacing (default: 2).
    • numberOfColumn: Number of columns in the grid (default: 4).
    • presentation: (iOS only) Modal style. Options: fullScreenModal (default), formSheet.