import { StreamChat } from "stream-chat";
import { ChannelList, Chat, OverlayProvider } from "stream-chat-react-native";
const client = StreamChat.getInstance("api_key");
export const App = () => (
<OverlayProvider>
<Chat client={client}>
<ChannelList />
</Chat>
</OverlayProvider>
);OverlayProvider
OverlayProvider is the top-level Stream Chat React Native component. It wraps all other SDK components and enables long-press message actions and the full-screen image viewer.
Best Practices
- Wrap your entire app, and if you use React Navigation place
OverlayProvideraboveNavigationContainer, to avoid context mismatches. - Keep
OverlayProviderstable; avoid re-mounting it on screen changes. - Use the provided hooks instead of prop drilling for overlay contexts.
- Customize image gallery subcomponents via
WithComponentsoverrides (ImageGalleryHeader,ImageGalleryFooter,ImageGalleryGrid,ImageGalleryVideoControls) rather than replacing the full image viewer. - Pass theming via
value.styleto keep UI consistent across screens.
General Usage
Wrap all Stream Chat components with OverlayProvider (usually the whole app).
Note: For navigation details, see the Navigation guide.
Context Providers
OverlayProvider provides the following contexts, accessible via their hooks:
ImageGalleryContextviauseImageGalleryContextOverlayContextviauseOverlayContextThemeContextviauseThemeTranslationContextviauseTranslationContext
Props
| Prop | Description | Type |
|---|---|---|
autoPlayVideo | Enable or disable autoplay for overlay videos. Defaults to false. | boolean |
giphyVersion | Giphy image rendition to use in the Image Gallery. See the Image Object keys for options. Defaults to 'fixed_height'. | string |
i18nInstance | Streami18n instance used for internationalization. See the translations docs for setup and customization. | Streami18n |
numberOfImageGalleryGridColumns | Number of columns to render within the image gallery grid. Defaults to 3. | number |
| value | Partially overrides the value provided to the OverlayContext. Can be used to set the theme via the style key. | object |
Customizing Overlay Components
Image gallery subcomponents and the message overlay background are overridden via WithComponents:
<WithComponents
overrides={{
ImageGalleryHeader: MyGalleryHeader,
ImageGalleryFooter: MyGalleryFooter,
ImageGalleryGrid: MyGalleryGrid,
ImageGalleryVideoControls: MyVideoControls,
MessageOverlayBackground: MyOverlayBackground,
}}
>
<OverlayProvider>...</OverlayProvider>
</WithComponents>Custom Message Actions Overlay
The MessageActions override replaces the entire message overlay action block (top, message, and bottom hosts) rendered by MessageOverlayHostLayer. When provided, it receives animated layout styles:
const CustomMessageActions = ({
topItemStyle,
hostStyle,
bottomItemStyle,
portalHostStyle,
}) => (
<Animated.View style={hostStyle}>
{/* Your custom overlay content */}
</Animated.View>
);
<WithComponents overrides={{ MessageActions: CustomMessageActions }}>
<OverlayProvider>...</OverlayProvider>
</WithComponents>;| Prop | Type | Description |
|---|---|---|
topItemStyle | StyleProp<ViewStyle> | Animated style for the top action host. |
hostStyle | StyleProp<ViewStyle> | Animated style for the message host. |
bottomItemStyle | StyleProp<ViewStyle> | Animated style for the bottom action host. |
portalHostStyle | StyleProp<ViewStyle> | Animated style for the portal host wrapper. |
Examples
Customizing value with a theme
const theme = {
messageItemView: {
file: {
container: {
backgroundColor: "red",
},
},
},
};
<OverlayProvider value={{ style: theme }}>...</OverlayProvider>;