Skip to content

umituz/react-native-sharing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@umituz/react-native-sharing

System share sheet functionality for React Native apps using expo-sharing with automatic MIME type detection.

Installation

npm install @umituz/react-native-sharing

Peer Dependencies

  • react >= 18.2.0
  • react-native >= 0.74.0
  • expo-sharing ~6.0.3

Features

  • ✅ Share files via system share sheet
  • ✅ Automatic MIME type detection
  • ✅ Platform-specific options (UTI for iOS, dialogTitle for Android)
  • ✅ Share availability check
  • ✅ Multiple file sharing (sequential)
  • ✅ Type-safe share operations

Usage

Basic Sharing

import { useSharing } from '@umituz/react-native-sharing';

const { share, isAvailable, isSharing } = useSharing();

if (!isAvailable) {
  return <Text>Sharing not available</Text>;
}

const handleShare = async () => {
  const success = await share('file:///path/to/file.jpg', {
    dialogTitle: 'Share Photo',
    mimeType: 'image/jpeg',
  });

  if (success) {
    console.log('Shared successfully');
  }
};

Auto-Detect MIME Type

import { useSharing } from '@umituz/react-native-sharing';

const { shareWithAutoType } = useSharing();

// MIME type auto-detected from .pdf extension
await shareWithAutoType(
  'file:///path/to/document.pdf',
  'document.pdf',
  'Share Document'
);

Share Multiple Files

import { useSharing } from '@umituz/react-native-sharing';

const { shareMultiple } = useSharing();

const handleShareMultiple = async () => {
  const uris = [
    'file:///path/to/file1.jpg',
    'file:///path/to/file2.jpg',
    'file:///path/to/file3.jpg',
  ];

  await shareMultiple(uris, {
    dialogTitle: 'Share Photos',
    mimeType: 'image/jpeg',
  });
};

MIME Type Utilities

import { SharingUtils, MIME_TYPES } from '@umituz/react-native-sharing';

// Get MIME type from extension
const mimeType = SharingUtils.getMimeTypeFromExtension('document.pdf');
// Returns: 'application/pdf'

// Get UTI for iOS
const uti = SharingUtils.getUTIFromExtension('photo.jpg');
// Returns: 'public.jpeg'

API

Hooks

  • useSharing(): Main hook for sharing functionality

Services

  • SharingService: Direct service access for sharing operations

Utilities

  • SharingUtils: Utility functions for MIME type detection and options preparation
  • MIME_TYPES: Predefined MIME type constants
  • UTI_TYPES: iOS UTI type constants

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published