Stream Chat React Native SDK

repository·develop·Indexed 22 days ago

https://github.com/getstream/stream-chat-react-native

The official React Native and Expo SDK for Stream Chat, providing pre-built components and logic to build high-performance chat applications. The SDK includes support for TypeScript and Expo, and provides several example apps including ExpoMessaging, TypeScriptMessaging, and a fully featured SampleApp. It also includes performance profiling tools for Hermes CPU profiles and Android heap/frame data analysis.

Tokens
19.2K
Snippets
43
Records
76
Agent score
77%

What's inside stream-chat-react-native

  1. Important considerations for using the SDK

    develop

    When building with the Stream Chat React Native SDK, keep the following in mind:

    1. Navigation: The SDK provides chat components, but it does not manage application navigation. You are responsible for implementing the navigation logic between different components (e.g., moving from a channel list to a specific chat channel). Refer to the provided example apps for implementation patterns.
    2. Upgrading: Minor releases may occasionally include breaking changes. Always review the Release Notes before upgrading to a new minor version.
  2. Update audio recording semantics in v9

    develop

    In v9, the property asyncMessagesMultiSendEnabled has been replaced by audioRecordingSendOnComplete.

    Warning: The boolean semantics are inverted and the default behavior has changed.

    Featurev8 (asyncMessagesMultiSendEnabled)v9 (audioRecordingSendOnComplete)
    Immediate Sendtruefalse
    Stay in Composerfalsetrue
    Default Behaviortrue (stays in composer)true (sends immediately)

    Migration Rule

    To preserve the v8 user experience (where recordings stayed in the composer by default), you must explicitly set: audioRecordingSendOnComplete={false}

    This applies to the Channel component, MessageComposer component, and any direct calls to useMessageInputContext(). It also applies to direct uploadVoiceRecording(sendOnComplete) calls.

    // To preserve v8 behavior (recordings stay in composer after upload):
    <MessageComposer audioRecordingSendOnComplete={false} />
  3. Prerequisites for v9 Migration

    develop

    The following requirements are hard blockers for upgrading to v9:

    1. React Native New Architecture: You must be using RN 0.76+ or an Expo SDK that defaults to the new architecture. If you are on the old architecture, you must migrate the architecture before upgrading the SDK.
    2. Peer Dependency: Install react-native-teleport (minimum version 0.5.4).
    3. Keyboard Handling Cleanup: Remove v8 workarounds before upgrading:
      • Remove negative keyboardVerticalOffset values on screens rendering MessageComposer. Use the navigation header height instead.
      • Remove SafeAreaView wrappers placed around MessageComposer for bottom spacing; MessageComposer handles its own safe-area in v9.
      • Remove manual Android IME padding hacks used to push the composer above the keyboard.
    yarn add react-native-teleport
  4. Run the TypeScript Chat Messaging example app

    develop

    The TypeScriptMessaging example is a bare-minimum Chat application built using the Stream Chat SDK and the React Native CLI. To run this specific example, you must first set up your Native CLI development environment following the official React Native guide.

    ### Clone the project
    
    ```bash
    git clone https://github.com/GetStream/stream-chat-react-native.git

    Install dependencies

    1. In the root install the dependencies:
    yarn install
    1. Move to the package directory and install the dependencies:
    cd package && yarn install
    1. Move to the native-package directory and install the dependencies:
    cd native-package && yarn install
    1. Finally, Move to the app directory and install the dependencies:
    cd ../../examples/TypeScriptMessaging && yarn install

    Install Pods for iOS

    cd ios && pod install

    Run

    To run the application for different platforms, use the following commands:

    yarn start
    • For iOS
    yarn ios
    • For android
    yarn android
  5. Configure Metro to resolve local SDK dependencies

    develop

    When linking a local SDK, Metro will encounter dependency collision errors because shared packages (like react or react-native) exist in both your app's node_modules and the SDK's node_modules.

    To fix this, you must configure your metro.config.js to:

    1. Use resolveUniqueModule (from @rnx-kit/metro-config) to deduplicate shared packages.
    2. Add the SDK source directories to Metro's watchFolders so changes in the SDK are reflected in your app.

    For a reference implementation, see examples/SampleApp/metro.config.js within this repository.

    After updating your config, perform a clean installation:

    rm -rf node_modules
    rm yarn.lock
    yarn install
    watchman watch-del-all
    yarn start --reset-cache
  6. Migrate Components from v8 to v9

    develop

    Several core UI components have been renamed in v9. When migrating, replace the old component names with the new ones listed below:

    • MessageSimple $\rightarrow$ MessageItemView
    • MessageAvatar $\rightarrow$ MessageAuthor
    • MessageInput $\rightarrow$ MessageComposer
    • ChannelListMessenger $\rightarrow$ ChannelListView
    • ChannelPreviewMessenger $\rightarrow$ ChannelPreviewView
    • Card $\rightarrow$ UrlPreview (uses URLPreviewProps)
    • GroupAvatar $\rightarrow$ AvatarGroup or AvatarStack
    • CameraSelectorIcon, FileSelectorIcon, ImageSelectorIcon, and VideoRecorderSelectorIcon $\rightarrow$ AttachmentTypePickerButton

    Note on AudioAttachment: The component name and ComponentOverrides key remain AudioAttachment. Only the internal source folder moved from Attachment/AudioAttachment/ to Attachment/Audio/. Do not rename imports or override keys.

    // Example of component renames
    // Old (v8)
    <MessageSimple />
    <MessageInput />
    
    // New (v9)
    <MessageItemView />
    <MessageComposer />
  7. Replace Card components with UrlPreview

    develop

    The Card, CardCover, CardFooter, and CardHeader components are replaced by UrlPreview and URLPreviewCompact.

    • The old CardProps type is now URLPreviewProps.
    • Select the rendering style via the urlPreviewType prop on the Channel component:
      • 'full' (default)
      • 'compact'
    • Customize via <WithComponents overrides={{ UrlPreview, URLPreviewCompact }}>.
  8. Detect required v8 to v9 migration changes

    develop

    Before editing your codebase, run these ripgrep commands to identify which parts of the migration guide apply to your project. Replace src/ with your actual source directory.

    Target AreaCommand
    WithComponentsrg '<(Channel|ChannelList|Chat|Thread)\s[^>]*\b([A-Z]\w+)=\{' src/
    Component Renamesrg '\b(MessageSimple|MessageAvatar|ChannelListMessenger|ChannelPreviewMessenger)\b' src/
    MessageInputrg '\bMessageInput\b' src/ | rg -v 'MessageInputContext|MessageInputHeaderView|MessageInputFooterView|MessageInputLeadingView|MessageInputTrailingView|useMessageInputContext|MessageInputContextValue'
    Audio Semanticsrg '\basyncMessagesMultiSendEnabled\b' src/
    Hook Renamesrg '\buseAudioController\b' src/
    Removed Componentsrg '\b(AttachmentActions|AttachmentUploadProgressIndicator|Card|CardCover|CardFooter|CardHeader|ImageReloadIndicator|MessagePreview|imageGalleryCustomComponents)\b' src/
    Behavior Changesrg '\b(latestMessagePreview|deletedMessagesVisibilityType|messageContentWidth|setMessageContentWidth|legacyImageViewerSwipeBehaviour)\b' src/
    # Example: Detect if WithComponents migration is needed
    rg '<(Channel|ChannelList|Chat|Thread)\s[^>]*\b([A-Z]\w+)=\{' src/
  9. Verify stream-chat-react-native v8 to v9 migration

    develop

    After performing the migration from v8 to v9, you must follow a strict verification workflow to ensure no legacy symbols remain and that the new architecture is correctly implemented.

    1. Symbol Detection

    Run the following rg (ripgrep) commands to ensure no v8-specific symbols are left in your src/ directory. If any return hits, they must be migrated or manually verified as legitimate (e.g., comments or test strings).

    • Legacy Components: rg '\b(MessageSimple|MessageAvatar|ChannelPreviewMessenger|ChannelListMessenger)\b' src/
    • Audio Controller: rg '\buseAudioController\b' src/
    • Muted Users (Scope-split): rg '\buseMutedUsers\b' src/ (Note: Chat-level usage is a bug; ChannelList-level usage is fine).
    • Multi-send: rg '\basyncMessagesMultiSendEnabled\b' src/
    • Message/Preview Props: rg '\b(latestMessagePreview|deletedMessagesVisibilityType|messageContentWidth|setMessageContentWidth|legacyImageViewerSwipeBehaviour)\b' src/
    • Attachment/Card Components: rg '\b(AttachmentActions|AttachmentUploadProgressIndicator|Card|CardCover|CardFooter|CardHeader|ImageReloadIndicator|MessagePreview)\b' src/
    • Selector Icons: rg '\b(CameraSelectorIcon|FileSelectorIcon|ImageSelectorIcon|VideoRecorderSelectorIcon)\b' src/
    • Theme/Surface Keys: rg '\b(backgroundCoreSurface|badgeTextInverse|textInverse|backgroundCoreElevation4)\b' src/

    2. Component Override Check

    Ensure component override props are no longer passed to Channel, ChannelList, Chat, or Thread. This regex should return 0 hits: rg '<(Channel|ChannelList|Chat|Thread)\s[^>]*\b([A-Z]\w+)=\{' src/

    3. MessageInput Component Check

    MessageInput has been renamed to MessageComposer. However, the context, hooks, and helper views were NOT renamed. Use this command to find remaining component references while ignoring valid context/hook names: rg '\bMessageInput\b' src/ | rg -v 'MessageInputContext|MessageInputHeaderView|MessageInputFooterView|MessageInputLeadingView|MessageInputTrailingView|useMessageInputContext|MessageInputContextValue'

    4. Dependency and Type Check

    • Peer Dependency: Verify "react-native-teleport" is present in package.json using rg '"react-native-teleport"' package.json.
    • TypeScript: Run yarn tsc --noEmit or npx tsc --noEmit.
    • Lint/Tests: Run yarn lint and yarn test if applicable.

    5. Manual Smoke Test

    Verify the following runtime behaviors:

    • Render the hierarchy: <Chat><Channel><MessageList> + <MessageComposer>.
    • Send a text message and long-press to confirm reactions/actions appear via the new overlay.
    • Swipe a message right to confirm the reply preview appears (the entire MessageItemView row is now the hit area).
    • Attach an image and confirm upload indicators render.
    • Start an audio recording and confirm send behavior.
    • Open the image gallery from a message with media.

    Note on Theming: If components render incorrectly, check for stale theme keys by diffing against contexts/themeContext/utils/theme.ts.

    # Example: Checking for legacy MessageInput component usage while ignoring valid context/hooks
    rg '\bMessageInput\b' src/ | rg -v 'MessageInputContext|MessageInputHeaderView|MessageInputFooterView|MessageInputLeadingView|MessageInputTrailingView|useMessageInputContext|MessageInputContextValue'
  10. Enable accessibility (a11y) in stream-chat-react-native

    develop

    Accessibility features are off by default to ensure no impact on existing integrations. To enable the accessibility layer (which provides VoiceOver/TalkBack support, automated announcements for messages/typing, and focus-trapping for modals), you must opt-in via the OverlayProvider using the accessibility prop.

    import { Chat, OverlayProvider } from 'stream-chat-react-native';
    
    <OverlayProvider accessibility={{ enabled: true }}>
      <Chat client={client}>
        {/* ... */}
      </Chat>
    </OverlayProvider>
  11. Migrate from stream-chat-react-native v8 to v9

    develop

    This guide provides a machine-oriented migration reference for upgrading the stream-chat-react-native SDK from version 8 to version 9.

    Key Migration Steps

    1. Prerequisites: Ensure React Native New Architecture is enabled (RN 0.76+ or compatible Expo SDK) and install react-native-teleport (min version 0.5.4).
    2. Structural Changes: Move component override props from Channel, ChannelList, Chat, and Thread into a new <WithComponents> wrapper.
    3. Renames: Update several core component names (e.g., MessageSimple to MessageItemView).
    4. Behavioral Changes: Note the inverted semantics for audio recording sending behavior.

    Important Package Note

    The actual SDK source is located in node_modules/stream-chat-react-native-core/src/. The packages stream-chat-react-native and stream-chat-expo are wrappers that depend on the core package.

    # Example: Install required peer dependency
    yarn add react-native-teleport
  12. Replace AttachmentUploadProgressIndicator with Granular Indicators

    develop

    The single AttachmentUploadProgressIndicator component has been split into six granular indicators. Choose the one that matches your specific upload type and state:

    • FileUploadInProgressIndicator
    • FileUploadRetryIndicator
    • FileUploadNotSupportedIndicator
    • ImageUploadInProgressIndicator
    • ImageUploadRetryIndicator
    • ImageUploadNotSupportedIndicator

    Provide custom versions using <WithComponents> overrides with the matching key.