Giter VIP home page Giter VIP logo

jonz94 / capacitor-image-picker Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 1.0 1005 KB

⚡️ Capacitor plugin for multiple image selection.

Home Page: https://www.npmjs.com/package/@jonz94/capacitor-image-picker

License: BSD Zero Clause License

Ruby 6.72% Java 37.86% Swift 30.68% Objective-C 4.00% JavaScript 5.54% TypeScript 15.20%
android ios capacitor capacitor-android capacitor-ios capacitor-plugin image-picker

capacitor-image-picker's Introduction


Image Picker

@jonz94/capacitor-image-picker

Capacitor plugin for multiple image selection.

Install

npm install @jonz94/capacitor-image-picker
npx cap sync

iOS

Native Dependencies Setup

This plugin uses a forked version of YPImagePicker under the hood.

In order to use this plugin, you need to manually modified ios/App/Podfile as following:

target 'App' do
  capacitor_pods
  # Add your Pods here
+  pod 'YPImagePicker', :git => 'https://github.com/jonz94/YPImagePicker.git', :tag => '5.2.2.0'
end

After modified ios/App/Podfile, make sure to run pod update command to sync up the iOS project.

Permissions

iOS requires the following usage description be added and filled out for your app in Info.plist:

  • NSPhotoLibraryUsageDescription (Privacy - Photo Library Usage Description)

Read about Configuring Info.plist in the iOS Guide for more information on setting iOS permissions in Xcode.

Android

Native Dependencies Setup

This plugin uses a forked version of TedImagePicker under the hood.

Setup JitPack Repository

Add following line to your android/build.gradle:

allprojects {
    repositories {
        google()
        mavenCentral()
+        maven { url "https://jitpack.io" }
    }
}

Enable Data Binding

Add following lines to your android/app/build.gradle:

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    defaultConfig {
        // ...
    }
    buildTypes {
        // ...
    }
+    dataBinding {
+        enabled true
+    }
}

Sync Project

After modified android/build.gradle and android/app/build.gradle, make sure to run Sync Project with Gradle Files in Android Studio.

Permissions

This plugin requires the following permissions be added to your AndroidManifest.xml:

<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />

The storage permissions are for reading photo files.

Read about Setting Permissions in the Android Guide for more information on setting Android permissions.

Configuration

No configuration required for this plugin.

Usage

import { ImagePicker } from '@jonz94/capacitor-image-picker';

const pickSingleImage = async () => {
  const { images } = await ImagePicker.present();

  // console.log(images[0]);

  return images[0];
}

const pickMultipleImages = async () => {
  const { images } = await ImagePicker.present({ limit: 10 });

  // console.log(images);

  return images;
}

const pickMultipleImagesWithCustomText = async () => {
  const { images } = await ImagePicker.present({
    limit: 10,
    surpassLimitMessage: 'You cannot select more than %d images.',
    titleText: 'Pick a image',
    albumsTitleText: 'Chose an album',
    libraryTitleText: 'Click here to change library',
    cancelText: 'Go Back',
    doneText: 'OK',
  });

  // console.log(images);

  return images;
}

API

present(...)

present(options?: PresentOptions | undefined) => Promise<Images>
Param Type
options PresentOptions

Returns: Promise<Images>


Interfaces

Images

Prop Type Description Since
images Image[] Array of all the picked images. 1.0.0

Image

Prop Type Description Since
path string The file path of the image. 1.0.0
webPath string webPath returns a path that can be used to set the src attribute of an image for efficient loading and rendering. 1.0.0
mimeType string The mime type of the image. 1.0.0

PresentOptions

Prop Type Description Default Since
limit number Maximum number of images the user will be able to choose. Note: If this is set to 1, upon selection of a single image. 1 1.0.0
surpassLimitMessage string The message when user select more than maximum number of pictures. This message will not occur when limit is 1. Note: The message MUST INCLUDE ONE AND ONLY ONE %d as a placeholder for showing the value of limit. "You can only select %d images." 1.0.0
titleText string Android only: The title of the image picker. "Select Image" 1.0.0
albumAllText string Android only: name of the all photos album. "All" 1.2.0
libraryTitleText string iOS only: The title of the library. "Library" 1.0.0
albumsTitleText string iOS only: The title of the albums. "Albums" 1.0.0
cancelText string iOS only: The text to display on the cancel button. Note: on Android, the cancel button is shown as icon-only back button with no text. "Cancel" 1.0.0
doneText string The text to display on the done button. "Done" 1.0.0

Changelog

See CHANGELOG.md.

License

See LICENSE.

Credits

capacitor-image-picker's People

Contributors

jonz94 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

missile71

capacitor-image-picker's Issues

This plugin cause `@capacitor/camera` plugin to malfunction

When using this plugin along side with @capacitor/camera plugin, the image picker works fine, but the camera won't work.

Related error message in Android Studio's console:

D/Capacitor: Sending plugin error: {"save":false,"callbackId":"41879053","pluginId":"Camera","methodName":"requestPermissions","success":false,"error":{"message":"Missing the following permissions in AndroidManifest.xml:\nandroid.permission.WRITE_EXTERNAL_STORAGE\n"}}

...

E/Capacitor/Console: File: http://localhost/main.bf4669fd4a781b3b.js - Line 1 - Msg: ERROR Error: Uncaught (in promise): Error: Missing the following permissions in AndroidManifest.xml:
    android.permission.WRITE_EXTERNAL_STORAGE
    
    Error: Missing the following permissions in AndroidManifest.xml:
    android.permission.WRITE_EXTERNAL_STORAGE
    
        at returnResult (http://localhost/:741:32)
        at Object.win.androidBridge.onmessage (http://localhost/:716:21)

The strange thing is that even we have already setup the corresponding permissions in AndroidManifest.xml as following:

<?xml version="1.0" encoding="utf-8" ?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="dev.jonz94.demo">

    <!-- Network -->
    <uses-permission android:name="android.permission.INTERNET" />

    <!-- Camera -->
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <!-- ... -->

</manifest>

the same error message described above still showing up.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.