Skip to content

Refactor and Finalize useMediaPicker Hook for Unified Media Handling #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

HarwinderSingh15
Copy link
Collaborator

🔄 Pull Request: Refactor and Finalize useMediaPicker Hook for Unified Media Handling

📌 Summary

This PR finalizes and cleans up the implementation of the useMediaPicker custom React hook. It enables streamlined handling of images, videos, and documents from the device's library, camera, or file system, while also managing permissions, thumbnails, and media state.


✅ Features & Improvements

  • Supports picking from:

    • Media Library (chooseImageFromLibrary)
    • Camera (pickImageWithCamera)
    • Files/Documents (pickDocument)
  • Handles permissions (media and camera) automatically

  • Supports both single and multiple media selections

  • Generates video thumbnails (with expo-video-thumbnails)

  • Unified structure for MediaAsset and DocumentAsset

  • State management:

    • media: single selected asset
    • multipleMedia: multiple selected assets
    • thumbnail: generated preview for video
    • loading: boolean indicating async operations in progress
  • Utility function: resetMedia() to clear selections


🧠 Hook Usage

const {
  media,
  thumbnail,
  loading,
  multipleMedia,
  chooseImageFromLibrary,
  pickImageWithCamera,
  pickDocument,
  resetMedia,
} = useMediaPicker(mediaType, options);
  • mediaType: Accepts MediaType.Images, MediaType.Videos, or both
  • options: Optional ImagePickerOptions (e.g., editing, multiple selection)

🧪 Example Use Cases

  • Profile image or video uploads
  • Chat media attachments
  • Document uploads in forms
  • Custom camera integrations

🧹 Cleaned Up

  • Removed duplicate state and effect declarations
  • Ensured consistent return structure
  • Removed redundant function definitions and permission logic
  • Ensured proper dependency handling in hooks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant