import { useContext } from "react";
import { AttachmentPickerContext } from "stream-chat-react-native";
const { openPicker, closePicker } = useContext(AttachmentPickerContext);AttachmentPickerContext
AttachmentPickerContext is provided by Channel. If you are not familiar with the React Context API, see the React docs.
Best Practices
- Use
useAttachmentPickerContextfor consistent access and typings. - Manage picker visibility through
openPicker/closePickerto keep state aligned. - Keep inset values (
topInset,bottomInset) consistent with your layout. - Avoid using the picker context outside
Channelto prevent undefined state. - Keep custom picker UI lightweight to preserve input performance.
Basic Usage
Consume AttachmentPickerContext in any child of Channel:
Alternatively, use the useAttachmentPickerContext hook.
import { useAttachmentPickerContext } from "stream-chat-react-native";
const { openPicker, closePicker } = useAttachmentPickerContext();Value
bottomSheetRef
Reference to the attachment picker bottom sheet.
bottomInset
Height of items located below the MessageInput when present. This inset determines the underlying shift to the MessageList when it is opened.
This can also be set via the setBottomInset function provided by the useAttachmentPickerContext hook.
| Type | Default |
|---|---|
| Number | 0 |
setBottomInset
Setter function for bottomInset
| Type |
|---|
(bottomInset: number) => void |
closePicker
Function to close the attachment picker bottom sheet.
| Type |
|---|
Function(() => void) |
openPicker
Function to open the attachment picker bottom sheet.
| Type |
|---|
Function(() => void) |
selectedPicker
Value is images (string), when image attachment picker is open else undefined.
| Type |
|---|
| 'images' | undefined |
setSelectedPicker
Setter function for selectedPicker
| Type |
|---|
(picker: 'images' | undefined) => void |
topInset
Distance from the top of the screen the attachment picker should open to when expanded. This is often set to the header height.
This can also be set via the setTopInset function provided by the useAttachmentPickerContext hook.
| Type | Default |
|---|---|
| Number | 0 |
setTopInset
Setter function for topInset
| Type |
|---|
(topInset: number) => void |
topInset
topInset is used to determine how high the scroll-able bottom-sheet can go when opened.
| Type | Default |
|---|---|
| number | topInset |