react-native-rs-lib
v2.0.0
Published
A comprehensive React Native library with native modules for date picker, image picker, document picker, device info, location, encryption, and media processing
Maintainers
Readme
React Native RS Lib
A comprehensive React Native library with native modules for date picker, image picker, document picker, device info, location, encryption, and media processing.
Features
- 📅 Date Picker - Native date/time picker with customizable options
- 🖼️ Image Picker - Pick images from gallery or camera with editing options
- 📹 Video Picker - Pick videos from gallery with quality options
- 📄 Document Picker - Pick documents from device storage
- 📱 Device Info - Get comprehensive device information
- 📍 Location Services - Get current location with high accuracy
- 🔐 Encryption/Decryption - AES encryption with various algorithms
- 📄 Base64 Conversion - Convert files, images, and videos to base64
- 🗜️ Compression - Compress images and videos
- 🖼️ Photo Merging - Merge two photos with blend modes
- 🎛️ Present Controller - Present custom controllers
- ✅ Permission Management - Handle all required permissions
Installation
npm install react-native-rs-lib
# or
yarn add react-native-rs-libAuto-Linking Setup
This library supports React Native auto-linking (0.60+). No manual configuration is required!
Prerequisites
- React Native 0.80 or higher
- iOS 12.0 or higher
- Android API level 21 or higher
@react-native-community/cli(for auto-linking)
Required Dependencies
Before installing this library, ensure you have the required CLI:
# Install React Native CLI (if not already installed)
npm install -g @react-native-community/cli
# Or add as dev dependency to your project
yarn add -D @react-native-community/cliiOS Setup
The library will automatically link with your iOS project. Just run:
cd ios
pod install
cd ..
npx react-native run-iosRequired Permissions - Add to ios/YourApp/Info.plist:
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs access to location when open.</string>
<key>NSCameraUsageDescription</key>
<string>This app needs access to camera to take photos.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs access to photo library to select images.</string>
<key>NSMicrophoneUsageDescription</key>
<string>This app needs access to microphone to record videos.</string>Android Setup
The library will automatically link with your Android project. Just run:
npx react-native run-androidRequired Permissions - Add to android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<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" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />Troubleshooting
Common Issues
1. CocoaPods Auto-linking Error:
[!] The command: 'node -e process.argv=['', '', 'config'];require('@react-native-community/cli').run()' returned a status code of 1Solution:
# Install the required CLI
yarn add -D @react-native-community/cli
# Clean and reinstall pods
cd ios
rm -rf Pods Podfile.lock
pod install
cd ..2. Auto-linking not working:
- Check React Native version (0.60+)
- Ensure
@react-native-community/cliis installed - Clean Metro cache:
npx react-native start --reset-cache
Manual Setup (if auto-linking fails)
If auto-linking doesn't work, see MANUAL_INSTALLATION.md for step-by-step manual setup instructions.
Pod Installation Issues
If you're having trouble with pod install, see our comprehensive POD_INSTALLATION_TROUBLESHOOTING.md guide.
CLI Dependency Issues
If you're getting CLI dependency errors, see our SIMPLE_INSTALLATION.md for the simplified approach that matches popular libraries like react-native-device-info.
Quick Fix for Auto-linking Issues:
# Install required CLI
yarn add -D @react-native-community/cli
# Clean and reinstall
cd ios
rm -rf Pods Podfile.lock
pod install
cd ..Usage
Date Picker
import RsLib from 'react-native-rs-lib';
// Show date picker
const result = await RsLib.showDatePicker({
mode: 'date', // 'date', 'time', 'datetime'
title: 'Select Date',
confirmText: 'Confirm',
cancelText: 'Cancel',
minimumDate: new Date('2020-01-01'),
maximumDate: new Date('2030-12-31')
});
if (result.success) {
console.log('Selected date:', result.data);
} else {
console.error('Error:', result.error);
}Image Picker
// Pick image from gallery
const result = await RsLib.pickImage({
mediaType: 'photo',
quality: 0.8,
maxWidth: 1024,
maxHeight: 1024,
allowsEditing: true
});
if (result.success) {
console.log('Selected image:', result.data.uri);
} else {
console.error('Error:', result.error);
}
// Pick video
const videoResult = await RsLib.pickVideo({
videoQuality: 'high',
durationLimit: 60
});Document Picker
const result = await RsLib.pickDocument({
type: ['public.item', 'public.pdf', 'public.text'],
copyTo: 'cachesDirectory',
readContent: true
});
if (result.success) {
console.log('Selected document:', result.data);
} else {
console.error('Error:', result.error);
}Device Info
const result = await RsLib.getDeviceInfo();
if (result.success) {
const deviceInfo = result.data;
console.log('Device:', deviceInfo.brand, deviceInfo.model);
console.log('OS:', deviceInfo.systemName, deviceInfo.systemVersion);
console.log('Screen:', deviceInfo.screenWidth, 'x', deviceInfo.screenHeight);
console.log('Memory:', deviceInfo.totalMemory, 'bytes');
} else {
console.error('Error:', result.error);
}Location Services
// Request location permission first
const permissionResult = await RsLib.requestLocationPermission();
if (permissionResult.success && permissionResult.data) {
const locationResult = await RsLib.getCurrentLocation({
enableHighAccuracy: true,
timeout: 10000,
maximumAge: 60000
});
if (locationResult.success) {
const location = locationResult.data;
console.log('Latitude:', location.latitude);
console.log('Longitude:', location.longitude);
console.log('Accuracy:', location.accuracy);
}
}Encryption/Decryption
// Encrypt text
const encryptResult = await RsLib.encrypt('Hello World', 'myPassword', {
algorithm: 'AES',
keySize: 256,
mode: 'CBC'
});
if (encryptResult.success) {
console.log('Encrypted:', encryptResult.data.encrypted);
// Decrypt text
const decryptResult = await RsLib.decrypt(
encryptResult.data.encrypted,
'myPassword',
{ iv: encryptResult.data.iv }
);
if (decryptResult.success) {
console.log('Decrypted:', decryptResult.data);
}
}Base64 Conversion
// Convert image to base64
const result = await RsLib.imageToBase64('/path/to/image.jpg', {
quality: 0.8,
maxWidth: 1024,
maxHeight: 1024
});
if (result.success) {
console.log('Base64:', result.data.base64);
console.log('MIME type:', result.data.mimeType);
console.log('Size:', result.data.size);
}
// Convert file to base64
const fileResult = await RsLib.fileToBase64('/path/to/file.pdf');Image Compression
const result = await RsLib.compressImage('/path/to/image.jpg', {
quality: 0.7,
maxWidth: 800,
maxHeight: 600,
format: 'JPEG'
});
if (result.success) {
console.log('Compressed image:', result.data.uri);
console.log('Original size:', result.data.originalSize);
console.log('Compressed size:', result.data.size);
console.log('Compression ratio:', result.data.compressionRatio);
}Photo Merging
const result = await RsLib.mergePhotos('/path/to/photo1.jpg', '/path/to/photo2.jpg', {
blendMode: 'normal',
opacity: 0.5,
position: { x: 0, y: 0 },
scale: 1.0
});
if (result.success) {
console.log('Merged photo:', result.data.uri);
console.log('Dimensions:', result.data.width, 'x', result.data.height);
}Permission Management
// Check permission
const hasPermission = await RsLib.checkPermission('camera');
// Request permission
const granted = await RsLib.requestPermission('location');API Reference
Types
interface DatePickerOptions {
mode?: 'date' | 'time' | 'datetime';
minimumDate?: Date;
maximumDate?: Date;
title?: string;
confirmText?: string;
cancelText?: string;
locale?: string;
}
interface ImagePickerOptions {
mediaType?: 'photo' | 'video' | 'mixed';
quality?: number;
maxWidth?: number;
maxHeight?: number;
allowsEditing?: boolean;
aspect?: [number, number];
videoQuality?: 'low' | 'medium' | 'high';
durationLimit?: number;
cameraType?: 'front' | 'back';
}
interface DeviceInfo {
brand: string;
model: string;
systemName: string;
systemVersion: string;
appVersion: string;
buildNumber: string;
bundleId: string;
deviceId: string;
isTablet: boolean;
hasNotch: boolean;
screenWidth: number;
screenHeight: number;
screenScale: number;
fontScale: number;
totalMemory: number;
usedMemory: number;
freeMemory: number;
batteryLevel: number;
isCharging: boolean;
isLocationEnabled: boolean;
isBluetoothEnabled: boolean;
isWifiEnabled: boolean;
carrierName?: string;
timezone: string;
locale: string;
country: string;
}
// ... and many more typesRequirements
- React Native >= 0.80.0
- iOS >= 11.0
- Android API Level >= 21
Contributing
- 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.
Support
If you encounter any issues or have questions, please file an issue on the GitHub repository.
