Info:
This is documentation for Stream Chat React Native SDK v5, which is no longer actively maintained. For up-to-date documentation, see the latest version (v9).

Native Image Picker

Note:

This guide can help you to comply with the new Google Play's android policy for photo and video permissions.

To enable the native image picker, you need to do the following steps and that would provide a native image picker for both iOS and Android.

Step 1: Uninstall the media library

Uninstall the media library by running the following command(if you have already installed it) else choose not to install it at all as it is a optional dependency.

Terminal
yarn remove @react-native-camera-roll/camera-roll
Note:

Make sure you remove the unnecessary permissions from both iOS(Info.plist) and Android(AndroidManifest.xml).

<key>NSPhotoLibraryUsageDescription</key>
<string>$(PRODUCT_NAME) would like access to your photo gallery to share image in a message.</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>$(PRODUCT_NAME) would like to save photos to your photo gallery after downloading from a message.<string>

Step 2: Install the native image picker

Install the native image picker by running the following command:

Terminal
yarn add react-native-image-picker
Note:

Add the following permission to the Info.plist of the app in the ios folder.

<key>NSPhotoLibraryUsageDescription</key>
<string>$(PRODUCT_NAME) would like access to your photo gallery to share image in a message.</string>

This shall give you a UI to select images from the gallery using native image picker or take a picture from the camera or alternatively select a file.

Note:

Please follow the post installation steps as mentioned in the react-native-image-picker.

Step 3: Add customization(if necessary)

You can customize what happens on clicking the AttachButton by passing your own onPress function to the handleAttachButtonPress of the Channel component.

import { useCallback } from "react";
import { Channel } from "stream-chat-react-native";

const App = () => {
  const handleAttachButtonPress = useCallback(async () => {
    // Your custom logic here
  }, []);

  return (
    <Channel
      channel={channel}
      handleAttachButtonPress={handleAttachButtonPress}
    />
  );
};

The other alternative is customizing the AttachButton component itself.

import { AttachButton } from "stream-chat-react-native";

const CustomAttachButton = (props) => {
  const { onPress } = props;

  const handlePress = async () => {
    // Your custom logic here
  };

  return <AttachButton onPress={handlePress} />;
};

const App = () => {
  return <Channel channel={channel} AttachButton={CustomAttachButton} />;
};
Add Chat to my app: getstream.io/SKILL.md

The fastest way to build with Stream. Start a new project or improve an existing one. Full CLI and documentation integration out of the box.


Ask your agent:

/stream Build me a Social App with Feeds and Moderation.
/stream Any livestream calls running?
/stream Chat React Native v5: <Your Question>