1.0.3 • Published 5 months ago
@reo-tech/reo-expo-file-picker v1.0.3
ReoExpoFilePicker
ReoExpoFilePicker is a versatile React Native component designed for Expo applications, enabling seamless file and image selection with customizable options and intuitive user interactions.
Features
- Dual File Picking Modes:
- Tap (Single Press): Opens the camera to capture a new image or record a video.
- Long Press: Opens the device's media library (for images/videos) or document picker (for other file types like PDFs), based on the
documentTypeprop.
- Permission Handling: Automatically requests necessary permissions for camera, media library, or documents before attempting to access them.
- Haptic Feedback: Provides haptic feedback (vibration) on long press for an enhanced user experience.
- Customizable UI:
- Allows specifying custom text and styles for the picker button.
- Supports custom icons (e.g., from
MaterialCommunityIcons) for the button.
- File Type Specificity: The
documentTypeprop dictates whether to open the image gallery or the document picker on long press. - Callback for Selection: The
onFilesSelectedprop provides a callback function that receives an array of selected file URIs. - TypeScript Support: Written in TypeScript for better type safety and developer experience.
Installation
npm install reo-expo-file-picker
# or
yarn add reo-expo-file-pickerEnsure you have expo-image-picker, expo-document-picker, and react-native-vector-icons (if using custom icons) installed and configured in your Expo project.
expo install expo-image-picker expo-document-picker
# If using MaterialCommunityIcons or other icon sets
npm install react-native-vector-icons
# or
yarn add react-native-vector-iconsUsage
import React, { useState } from 'react';
import { View, Text, Image, StyleSheet } from 'react-native';
import ReoExpoFilePicker from 'reo-expo-file-picker';
export default function App() {
const [selectedFiles, setSelectedFiles] = useState<string[]>([]);
const handlePickSuccess = (files: PickedFileInfo[]) => {
console.log('Files selected:', files);
};
const handlePickError = (error: FileError) => {
console.error('Picking error:', error.message, error.details);
};
return (
<View style={styles.container}>
<Text style={styles.title}>ReoExpoFilePicker Demo</Text>
<ReoExpoFilePicker
onPickSuccess={handlePickSuccess}
onPickError={handlePickError}
documentType="image" // or "pdf"
buttonShape="rectangle" // or "rectangle"
customstyle={{
idleColor: '#3498db',
successColor: '#2ecc71',
errorColor: '#e74c3c',
}}
buttonContent={<Text style={{ color: 'white', fontSize: 16 }}>Choose image</Text>}
/>
</View>
);
}Props
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
documentType | string | Yes | - | The type of document to pick on long press ("image" or "pdf"). Determines picker behavior. |
buttonStyle | StyleProp<ViewStyle> | No | { backgroundColor: 'blue', padding: 10 } | Custom styles for the button container. |
maxFileSize | number | No | undefined | (For Image Picker) Maximum file size in bytes for selected images. |
How it Works
- Single Tap:
- Requests camera permissions (
ImagePicker.requestCameraPermissionsAsync). - If granted, launches the device camera (
ImagePicker.launchCameraAsync). - Selected media URI is passed to
onFilesSelected.
- Requests camera permissions (
- Long Press:
- Checks
documentType:- If
documentTypeindicates images (e.g., "image/*", "image/jpeg"), it requests media library permissions (ImagePicker.requestMediaLibraryPermissionsAsync). - Otherwise, it requests document picker permissions (implicitly handled by
DocumentPicker.getDocumentAsync).
- If
- If permissions are granted, vibrates the device (
Vibration.vibrate()). - Launches the appropriate picker:
ImagePicker.launchImageLibraryAsyncfor images.DocumentPicker.getDocumentAsyncfor other document types.
- Selected file URI(s) are passed to
onFilesSelected.
- Checks
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository.
- Create your feature branch (
git checkout -b feature/AmazingFeature). - Commit your changes (
git commit -m 'Add some AmazingFeature'). - Push to the branch (
git push origin feature/AmazingFeature). - Open a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details (if available, otherwise assume MIT).