How faridsafi/react-native-gifted-chat works
Project Type & Purpose
• This is an open-source React Native & Web UI component library (“react-native-gifted-chat”).
• Its sole purpose is to provide a comprehensive, customizable chat interface (message list, bubbles, composer, quick replies, typing indicator, etc.).
• It ships as a single NPM package with an example/demo Expo app under example/.
High-Level File Structure
– Root
• Config & metadata: .eslintrc.cjs, babel.config.cjs, jest.config.cjs, tsconfig.json, CI/workflow files, README.md, LICENSE
– src/
• Entry: index.ts exports GiftedChat, subcomponents & hooks
• Components folder-style:
– GiftedChat/, MessageContainer/, Bubble/, Day/, TypingIndicator/
– Leaf components: Avatar.tsx, Composer.tsx, InputToolbar.tsx, Send.tsx, QuickReplies.tsx, etc.
• Shared logic: hooks/, utils.ts, logging.ts, styles.ts, types.ts
• Tests under src/__tests__
– example/
• A full Expo demo app illustrating default & custom UIs
• Sub-examples: “example-expo”, “example-gifted-chat”, “example-slack-message”
Core Architectural Patterns
• React component composition – GiftedChat is a wrapper that orchestrates child components
• Context API (GiftedChatContext) to share theme, settings, layout info
• Hooks for lifecycle & layout (useUpdateLayoutEffect)
• FlatList for virtualization in MessageContainer
• Pure UI – no built-in backend; consumers wire up onSend to their chat server
Main System Components & Relationships
[Host App]
• Renders <GiftedChat …/>
• Passes in messages[], user object, onSend() callback
• Optionally handles onLoadEarlier, onQuickReply to drive business logic / API calls
↓ data flow
[GiftedChat Module]
• Wraps:
– MessageContainer
– InputToolbar
– Footer / TypingIndicator
– QuickReplies (if enabled)
– Custom View slots (e.g. renderBubble, renderFooter)
• Manages layout via onLayout events & Context
↕ composition
┌─────────────────────────────────────────────────┐
│ MessageContainer (FlatList) │
│ ├─ Day / DayAnimated │
│ ├─ MessageItem → Bubble → (Text, Image, Video) │
│ └─ SystemMessage │
└─────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────┐
│ InputToolbar │
│ ├─ Composer (TextInput) │
│ ├─ Actions (attach buttons) │
│ ├─ Send (button) │
│ └─ AccessoryBar (optional) │
└─────────────────────────────────────────────────┘
↕ context/hooks
[Shared Utils & Hooks]
• useUpdateLayoutEffect
• message ID generation (uuid)
• logging
• styles & constants
↓ external integration
[External Chat API / Server]
• e.g. GetStream.io, Firebase, custom WebSocket
• Host App’s onSend / onLoadEarlier calls out here
• New messages fed back into messages[] prop
• Host App → GiftedChat → (MessageContainer + InputToolbar + Footer) → External Chat API
• Detail all subcomponents, context providers, hooks, and utility modules
• Related components visually and call out extensibility slots