|
| 1 | +# React Native Gifted Chat |
| 2 | + |
| 3 | +The most complete chat UI for React Native & Web. This is a TypeScript React Native component library with example applications demonstrating usage across React Native, React Native Web, and Expo platforms. |
| 4 | + |
| 5 | +Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here. |
| 6 | + |
| 7 | +## Working Effectively |
| 8 | + |
| 9 | +### Bootstrap and build the repository: |
| 10 | +- `yarn install` -- NEVER CANCEL: takes 58 seconds. Set timeout to 120+ seconds. |
| 11 | +- `yarn build` -- builds TypeScript library, takes 3 seconds. Set timeout to 30+ seconds. |
| 12 | +- `yarn lint` -- lints source code, takes 3 seconds. Currently has warnings but no errors. Set timeout to 30+ seconds. |
| 13 | +- `yarn test` -- NEVER CANCEL: runs Jest test suite, takes 9 seconds. Set timeout to 60+ seconds. |
| 14 | + |
| 15 | +### Full validation before publishing: |
| 16 | +- `yarn prepublishOnly` -- NEVER CANCEL: runs lint + build + test, takes 11 seconds total. Set timeout to 60+ seconds. |
| 17 | + |
| 18 | +### Known Issues: |
| 19 | +- If tests fail due to snapshot mismatches after fresh dependency install, run `yarn test -u` to update snapshots |
| 20 | +- Snapshot tests may need updates when React Native or dependency versions change |
| 21 | + |
| 22 | +### Example app development: |
| 23 | +- `cd example && yarn install` -- NEVER CANCEL: takes 38 seconds. Set timeout to 90+ seconds. |
| 24 | +- Install Expo CLI globally: `npm install -g @expo/cli` or use `npx expo` commands |
| 25 | +- Native development: `cd example && npx expo start` |
| 26 | +- Web development: `cd example && npx expo start --web` (requires additional dependencies) |
| 27 | +- The example app starts Metro bundler on http://localhost:8081 |
| 28 | +- Expect dependency version warnings in offline/CI mode - these are normal |
| 29 | + |
| 30 | +### Type checking and development: |
| 31 | +- `yarn tsc:watch` -- runs TypeScript compiler in watch mode for development |
| 32 | +- `yarn tsc:write` -- compiles TypeScript and writes output to /lib directory |
| 33 | + |
| 34 | +## Requirements and Setup |
| 35 | + |
| 36 | +### System Requirements: |
| 37 | +- Node.js >= 18 (tested with 20.19.4) |
| 38 | +- Yarn package manager 1.22.22+ (do NOT use npm for this project) |
| 39 | +- TypeScript compiler (included in devDependencies) |
| 40 | + |
| 41 | +### Dependencies are already installed if yarn.lock exists |
| 42 | +The repository includes both package-lock.json and yarn.lock but ALWAYS use yarn commands, never npm commands. |
| 43 | + |
| 44 | +## Validation |
| 45 | + |
| 46 | +### Always run full validation before completing changes: |
| 47 | +1. `yarn lint` -- check for code style issues (warnings are acceptable, errors are not) |
| 48 | +2. `yarn build` -- verify TypeScript compilation succeeds |
| 49 | +3. `yarn test` -- NEVER CANCEL: ensure all 19 test suites and 29 tests pass. Takes 31 seconds. |
| 50 | + |
| 51 | +### Manual validation scenarios: |
| 52 | +After making code changes, you should test basic functionality by: |
| 53 | +1. Building the library: `yarn build` |
| 54 | +2. Running the test suite: `yarn test` |
| 55 | +3. For UI changes: Start the example app with `cd example && npx expo start --web` (if web dependencies are installed) or `npx expo start` for native development |
| 56 | +4. ALWAYS test that the TypeScript declarations in /lib are correctly generated |
| 57 | + |
| 58 | +### Testing approach: |
| 59 | +- All tests are located in `src/__tests__/` directory |
| 60 | +- Tests use Jest with React Test Renderer |
| 61 | +- Test coverage can be viewed with `yarn test:coverage` |
| 62 | +- Snapshot tests are used extensively (27 snapshots) |
| 63 | + |
| 64 | +## Project Structure |
| 65 | + |
| 66 | +### Key directories: |
| 67 | +- `/src` -- main library source code (TypeScript) |
| 68 | +- `/lib` -- compiled JavaScript output (generated by `yarn build`, do not edit manually) |
| 69 | +- `/example` -- example React Native app demonstrating library usage |
| 70 | +- `/src/__tests__` -- Jest test files |
| 71 | +- `/.github/workflows/main.yml` -- CI/CD pipeline (tests Node 18 and 20) |
| 72 | + |
| 73 | +### Important files: |
| 74 | +- `package.json` -- main project configuration and scripts |
| 75 | +- `tsconfig.json` -- TypeScript compiler configuration |
| 76 | +- `jest.config.cjs` -- Jest test configuration |
| 77 | +- `.eslintrc.cjs` -- ESLint linting rules |
| 78 | +- `babel.config.cjs` -- Babel transformation configuration |
| 79 | +- `example/package.json` -- example app dependencies |
| 80 | + |
| 81 | +### Build output: |
| 82 | +The `yarn build` command generates JavaScript files and TypeScript declaration files in the `/lib` directory. This directory should not be edited manually and is ignored by git but included in npm package. |
| 83 | + |
| 84 | +## Common Tasks |
| 85 | + |
| 86 | +### Making code changes: |
| 87 | +1. Edit source files in `/src` directory |
| 88 | +2. Run `yarn lint` to check style |
| 89 | +3. Run `yarn build` to compile TypeScript |
| 90 | +4. Run `yarn test` to verify tests pass |
| 91 | +5. Test manually with example app if UI changes |
| 92 | + |
| 93 | +### Adding or modifying tests: |
| 94 | +- Tests are in `src/__tests__/` directory |
| 95 | +- Follow existing test patterns using React Test Renderer |
| 96 | +- Update snapshots if needed with `yarn test -u` |
| 97 | +- Ensure all tests pass with `yarn test` |
| 98 | + |
| 99 | +### Working with the example app: |
| 100 | +- Example app uses Expo and demonstrates library functionality |
| 101 | +- Install dependencies: `cd example && yarn install` |
| 102 | +- Start development server: `npx expo start` |
| 103 | +- For web: `npx expo start --web` (requires react-native-web and @expo/metro-runtime) |
| 104 | + |
| 105 | +## CI/CD Integration |
| 106 | + |
| 107 | +The repository uses GitHub Actions (`.github/workflows/main.yml`) that: |
| 108 | +- Tests on Node.js versions 18 and 20 |
| 109 | +- Runs `yarn install` and `yarn build` |
| 110 | +- Build typically takes 1-2 minutes on CI |
| 111 | + |
| 112 | +Always ensure your changes pass the full validation pipeline locally before pushing. |
| 113 | + |
| 114 | +## Common Command Reference |
| 115 | + |
| 116 | +### Root directory (library development): |
| 117 | +```bash |
| 118 | +yarn install # Install dependencies (58 seconds) |
| 119 | +yarn build # Build TypeScript library (3 seconds) |
| 120 | +yarn lint # Lint source code (3 seconds) |
| 121 | +yarn test # Run test suite (9 seconds) |
| 122 | +yarn prepublishOnly # Full validation pipeline (11 seconds) |
| 123 | +yarn tsc:watch # TypeScript watch mode |
| 124 | +``` |
| 125 | + |
| 126 | +### Example directory (app development): |
| 127 | +```bash |
| 128 | +cd example |
| 129 | +yarn install # Install example dependencies (38 seconds) |
| 130 | +npx expo start # Start native development server |
| 131 | +npx expo start --web # Start web development server |
| 132 | +``` |
| 133 | + |
| 134 | +### Time expectations (NEVER CANCEL these operations): |
| 135 | +- yarn install: 58 seconds (root), 41 seconds (example) |
| 136 | +- yarn build: 3 seconds |
| 137 | +- yarn lint: 3 seconds |
| 138 | +- yarn test: 9 seconds (after fresh install and snapshot updates) |
| 139 | +- yarn prepublishOnly: 11 seconds total |
| 140 | + |
| 141 | +Always set timeouts to at least double these times to account for system variations. |
0 commit comments