npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-universal-attach-picker

v1.0.3

Published

Universal attach wrapper to pick documents, files, photos, and video from gallery

Downloads

7

Readme

react-native-universal-attach-picker

Hello. That module is wrapper for react-native-image-picker and react-native-document-picker | ios | android | |--|--|

Tested with

"react": "17.0.2",

"react-native": "0.66.4",

Install

yarn add react-native-universal-attach-picker

or

npm install react-native-universal-attach-picker

Install dependencies (Check instructions of these packages in their repositories)

yarn add react-native-image-picker react-native-document-picker

or

npm install react-native-image-picker react-native-document-picker

Then for iOS

npx pod-install

or

cd ios && pod install

Then s Add the appropriate keys to your Info.plist

<key>NSPhotoLibraryUsageDescription</key>
<string>description</string>
<key>NSCameraUsageDescription</key>
<string>description</string>
<key>NSMicrophoneUsageDescription</key>
<string>description</string>

Usage

import  React, {useState} from  'react';
import {Text, View, Button, StyleSheet} from  'react-native';

// import
import {
    AttachmentPicker,
    PickInModal,
    } from  'react-native-universal-attach-picker';
	
// define options for pickers
// Options for launchImageLibrary of 'react-native-image-picker'
let  galeryOptions = { 
    selectionLimit:  2,
    mediaType:  'mixed',
};

// Options for launchCamera of 'react-native-image-picker'
let  VideoOptions = {
    mediaType:  'video',
};

// Options for launchCamera of 'react-native-image-picker'
let  PhotoOptions = {
    mediaType:  'photo',
};

// Options for DocumentPicker of 'react-native-document-picker'
let  filesOptions = {
    presentationStyle:  'fullScreen',
    allowMultiSelection:  true,
};

// init object
const  attachmentPicker = new  AttachmentPicker(
    filesOptions,
    galeryOptions,
    VideoOptions,
    PhotoOptions,
);

// create functional component
const  PickAttaches = () => {
    return (
	    <View>
		    <Button
			    style={{marginTop:  5}}
			    title="Galery"
			    onPress={async () => {
				    const  response = await  attachmentPicker.pickGalery();
				    console.log(response);
			    }}
		    />
		    <View  style={{marginTop:  5}}>
			    <Button
				    title="Files"
				    onPress={async () => {
					    const  response = await  attachmentPicker.pickFiles();
					    console.log(response);
					}}
			    />
			</View>
		    <View  style={{marginTop:  5}}>
			    <Button
				    title="MakePhoto"
				    onPress={async () => {
					    const  response = await  attachmentPicker.makePhoto();
					    console.log(response);
				    }}
			    />
			</View>
	    
		    <View  style={{marginTop:  5}}>
			    <Button
				    title="Make Video"
				    onPress={async () => {
				    const  response = await  attachmentPicker.makeVideo();
				    console.log(response);
				    }}
				 />
			</View>
		    
		    <View  style={{marginTop:  5}}>
			    <PickInModal
				    buttonText="Show modal menu"
				    openButtonStyle={{}}
				    openButtonTextStyle={{}}
				    asButton={true}
				    buttonCancelText="CANCEL"
				    buttons={[
						{
						    label:  'Select from galery',
						    onPress:  async () => {
							    const  response = await  attachmentPicker.pickGalery();
							    console.log(response);
							},
						},
						{
							label:  'Select from files',
							onPress:  async () => {
								const  response = await  attachmentPicker.pickFiles();
								console.log(response);
							},
						},
						{
							label:  'Make photo',
							onPress:  async () => {
								const  response = await  attachmentPicker.makePhoto();
								console.log(response);
							},
						},
			    
					    {
						    label:  'Make video',
						    onPress:  async () => {
							    const  response = await  attachmentPicker.makeVideo();
							    console.log(response);
							},
						},
					]}
				/>
		    </View>
	    </View>
	);
};
export  default  PickAttaches;

Init options

On create object receive 4 params

const  attachmentPicker = new  AttachmentPicker(
    DocumentPickerOptions,
    GaleryPickerOptions,
    VideoPickerOptions,
    PhotoPickerOptions,
);

| № | Name |Description |Default| |--|--|--|--| | 1 | DocumentPickerOptions | Options for react-native-document-picker | { presentationStyle: 'fullScreen', copyTo: 'cachesDirectory',allowMultiSelection: true }; | | 2 | GaleryPickerOptions | Options for launchCamera of react-native-image-picker | { }; | | 2 | VideoPickerOptions | Options for launchImageLibrary of react-native-image-picker | { mediaType: 'video' }; | | 2 | PhotoPickerOptions | Options for launchImageLibrary of react-native-image-picker | { mediaType: 'photo' }; |

Result

All methods return JSON

{
    // arrays of objects
    files: [
	    {
		    uri: 'file:/// path to file',
		    filename: 'filename.jpg',
		    type: 'image/jpeg'
	    }
    ],
    original: [ /* original JSON Object which was returned react-native-document-picker or react-native-image-picker */ ]
}

UI components

For convenience, a component PickInModal has been created that opens a list of buttons (which can be styled) in a modal window for selection

PickInModal Props

| Name | Description | Type | Default | Required | |--|--|--|--|--| | buttonText | String |Text for open modal button | Pick the files | No | | openButtonStyle | style Object | Style for TouchableOpacity of open modal button | {} | No | | openButtonTextStyle | style Object | Style for text of open modal button | {} | No | | asButton | bool | Render button as RN Button component. Color props will get from openButtonStyle backgroundColor properties | false | No | | modalContainerStyle |style Object | Style for main View in Modal component (Fullscreen, transparent) | {} | No | | modalContentStyle |Style Object | Style for in content View in container (Centerd, not transparent)| {} | No | | buttons |Array of Objects | List of buttons for render in modal | { label: 'Label for button', onPress: async () => {// OnPress functon for button}}| No | | pickButtonStyle |style Object | Style for TouchableOpacity for pick button | {} | No | | pickButtonTextStyle |style Object | Style for text in pick button | {} | No | | buttonCancelText | string | Text for the last button to close modal | Cancel | No |