Skip to content

[🐛] expo: opening camera fails on iOS when not having mic permissions #3379

@mieszko4

Description

@mieszko4

Issue

I use expo-stream-chat with expo-image-picker.
My app does not need mic permissions so in app.json I explicitly set "microphonePermission": false for expo-image-picker.
I can see the photo icon on msg input. However, when I press on it, it freezes and camera never shows.

The issue is that mediaType is always hardcoded to mixed when calling takeAndUploadImage on iOS:

takeAndUploadImage(Platform.OS === 'android' ? 'image' : 'mixed');

And then used as both 'images', 'videos' in takePhoto:

const mediaTypeMap = {
     image: 'images',
     mixed: ['images', 'videos'],  // Maps to array for expo-image-picker
     video: 'videos',
   };

   const result = await ImagePicker.launchCameraAsync({
     mediaTypes: mediaTypeMap[mediaType],  // ['images', 'videos'] when mixed
     quality: Math.min(Math.max(0, compressImageQuality), 1),
   });

Workaround is to override takePhoto:

const takePhotoModule = require("stream-chat-expo/src/optionalDependencies/takePhoto");
const originalTakePhoto = takePhotoModule.takePhoto;

registerNativeHandlers({
  takePhoto: originalTakePhoto
    ? async (options) => originalTakePhoto?.({ ...options, mediaType: "image" })
    : undefined,
});

but that's more of a hack since internals of the lib are imported (and require is needed)

Potential solutions:

  1. Expose mediaType as setting on expo-stream-chat
  2. Read microphonePermission from expo-image-picker and if it is false then pass image instead of mixed
  3. Especially if (2) is not possible. Then filter out video inside of expo-image-picker

Note that expo-image-picker supports microphonePermission: false (it was added in expo/expo#29749)

Steps to reproduce

Steps to reproduce the behavior:

  1. On iOS, go to Chat
  2. On msg input, click on actions then click on photo icon

Expected behavior

Camera app opens

Project Related Information

Customization

Click To Expand

# N/A

Offline support

  • I have enabled offline support.
  • The feature I'm having does not occur when offline support is disabled. (stripe out if not applicable)

Environment

Click To Expand

package.json:

# N/A

react-native info output:

# N/A
  • Platform that you're experiencing the issue on:
    • iOS
    • Android
    • iOS but have not tested behavior on Android
    • Android but have not tested behavior on iOS
    • Both
  • stream-chat-react-native version you're using that has this issue:
    • 8.12.2
  • Device/Emulator info:
    • I am using a physical device
    • OS version: 16.7.10
    • Device: iPhone 8

Additional context

Screenshots

Click To Expand


Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions