|
| 1 | +# React Native/Expo Project |
| 2 | + |
| 3 | +You are an expert in TypeScript, React Native, Expo, and Mobile UI development with Nativewind. |
| 4 | + |
| 5 | +Every time you choose to apply a rule(s), explicitly state the rule(s) in the output. You can abbreviate the rule description to a single word or phrase. |
| 6 | + |
| 7 | +## Project Context |
| 8 | + |
| 9 | +## Code Style and Structure |
| 10 | + |
| 11 | +- Write concise, technical TypeScript code with accurate examples |
| 12 | +- Use functional and declarative programming patterns; avoid classes |
| 13 | +- Prefer iteration and modularization over code duplication |
| 14 | +- Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError) |
| 15 | +- Ensure components are modular, reusable, and maintainable. |
| 16 | +- Component Modularity: Break down components into smaller, reusable pieces. Keep components focused on a single responsibility and shouldn't be more than 80 lines of code. |
| 17 | +- To install new packages use `npx expo install <package-name>` |
| 18 | +- Structure repository files as follows: |
| 19 | + |
| 20 | +``` |
| 21 | +src |
| 22 | + ├── api ## API related code, mainly using axios and react query |
| 23 | + ├── app ## the main entry point for expo router(file-based routing), when you can find screens and navigation setup |
| 24 | + ├── components ## shared components |
| 25 | + │ ├── card.tsx |
| 26 | + │ └── ui ## core ui components. buttons, inputs, etc |
| 27 | + ├── lib ## shared libraries, auth, env, hooks, i18n, storage, test-utils, utils |
| 28 | + ├── translations ## translations files for the app |
| 29 | + ├── types ## shared types |
| 30 | + |
| 31 | +``` |
| 32 | + |
| 33 | +## Tech Stack |
| 34 | + |
| 35 | +- Expo |
| 36 | +- React Native |
| 37 | +- TypeScript |
| 38 | +- Nativewind ( Tailwind CSS for React Native ) |
| 39 | +- Expo Router |
| 40 | +- React Query with React Query Kit |
| 41 | +- Zustand |
| 42 | +- React Native Keyboard Controller |
| 43 | +- React Native SVG |
| 44 | +- React Native MMKV |
| 45 | + |
| 46 | +## Naming Conventions |
| 47 | + |
| 48 | +- Favor named exports for components and utilities |
| 49 | +- Use kebabCase for all files names and directories (e.g., visa-form.tsx) |
| 50 | + |
| 51 | +## TypeScript Usage |
| 52 | + |
| 53 | +- Use TypeScript for all code; prefer types over interfaces |
| 54 | +- Avoid enums; use const objects with 'as const' assertion |
| 55 | +- Use functional components with TypeScript interfaces |
| 56 | +- Define strict types for message passing between different parts of the extension |
| 57 | +- Use absolute imports for all files @/... |
| 58 | +- Avoid try/catch blocks unless there's good reason to translate or handle error in that abstraction |
| 59 | +- Use explicit return types for all functions |
| 60 | + |
| 61 | +## State Management |
| 62 | + |
| 63 | +- Use React Zustand for global state management |
| 64 | +- Implement proper cleanup in useEffect hooks |
| 65 | + |
| 66 | +## Syntax and Formatting |
| 67 | + |
| 68 | +- Use "function" keyword for pure functions |
| 69 | +- Avoid unnecessary curly braces in conditionals |
| 70 | +- Use declarative JSX |
| 71 | +- Implement proper TypeScript discriminated unions for message types |
| 72 | + |
| 73 | +## UI and Styling |
| 74 | + |
| 75 | +- Use Nativewind for styling and components |
| 76 | +- Use built-in ui components such as Button, Input from `@components/ui` |
| 77 | +- Ensure high accessibility (a11y) standards using ARIA roles and native accessibility props. |
| 78 | +- Leverage react-native-reanimated and react-native-gesture-handler for performant animations and gestures. |
| 79 | +- Avoid unnecessary re-renders by memoizing components and using useMemo and useCallback hooks appropriately. |
| 80 | +- Make sure to use defined colors and fonts in the tailwind config file. |
| 81 | + |
| 82 | +Here is a simple example of how a component should be written using : |
| 83 | + |
| 84 | +```tsx |
| 85 | +import * as React from 'react'; |
| 86 | + |
| 87 | +import { Text, View, Image, SavaAreaView } from '@/components/ui'; |
| 88 | + |
| 89 | +// Props should be defined in the top of the component |
| 90 | +type Props = { |
| 91 | + text: string; |
| 92 | +}; |
| 93 | + |
| 94 | +export function Title({ text }: Props) { |
| 95 | + return ( |
| 96 | + <View className="flex-row items-center justify-center py-4 pb-2"> |
| 97 | + <Text className="pr-2 text-2xl">{text}</Text> |
| 98 | + <View className="h-[2px] flex-1 bg-neutral-300" /> |
| 99 | + |
| 100 | + <Image |
| 101 | + source={require('@assets/images/demo.png')} |
| 102 | + style={{ width: 24, height: 24 }} |
| 103 | + contentFit="contain" |
| 104 | + /> |
| 105 | + </View> |
| 106 | + ); |
| 107 | +} |
| 108 | +``` |
| 109 | + |
| 110 | +## Error Handling |
| 111 | + |
| 112 | +- Log errors appropriately for debugging |
| 113 | +- Provide user-friendly error messages |
| 114 | + |
| 115 | +## Testing |
| 116 | + |
| 117 | +- Write unit tests using Jest and React Native Testing Library. |
| 118 | +- Write unit tests for utilities and complex components |
| 119 | +- The test file should be named like the component file but with the .test.tsx extension (e.g., component-name.test.tsx) |
| 120 | +- Do not write unit tests for simple components that only show data |
| 121 | + |
| 122 | +## Git Usage |
| 123 | + |
| 124 | +Commit Message Prefixes: |
| 125 | + |
| 126 | +- "fix:" for bug fixes |
| 127 | +- "feat:" for new features |
| 128 | +- "perf:" for performance improvements |
| 129 | +- "docs:" for documentation changes |
| 130 | +- "style:" for formatting changes |
| 131 | +- "refactor:" for code refactoring |
| 132 | +- "test:" for adding missing tests |
| 133 | +- "chore:" for maintenance tasks |
| 134 | + |
| 135 | +Rules: |
| 136 | + |
| 137 | +- Use lowercase for commit messages |
| 138 | +- Keep the summary line concise with a maximum of 100 characters |
| 139 | +- Reference issue numbers when applicable |
| 140 | + |
| 141 | +## Documentation |
| 142 | + |
| 143 | +- Maintain clear README with the following sections: |
| 144 | + - Setup ( how to install and run the project ) |
| 145 | + - Usage ( listing all the commands and how to use them ) |
| 146 | + - Stack ( the tech stack used in the project ) |
| 147 | + - Folder Structure ( the folder structure of the project only the important ones inside src ) |
0 commit comments