d48cda4081
CI / Test (ubuntu-latest, Node 18.x, bun) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, npm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, pnpm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, yarn) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 20.x, bun) (push) Failing after 17m13s
CI / Test (ubuntu-latest, Node 20.x, npm) (push) Failing after 18m42s
CI / Test (ubuntu-latest, Node 20.x, pnpm) (push) Failing after 15m0s
CI / Test (ubuntu-latest, Node 20.x, yarn) (push) Failing after 49m44s
CI / Test (ubuntu-latest, Node 22.x, bun) (push) Failing after 51m55s
CI / Test (ubuntu-latest, Node 22.x, pnpm) (push) Failing after 21m57s
CI / Test (ubuntu-latest, Node 22.x, npm) (push) Failing after 37m39s
CI / Test (ubuntu-latest, Node 22.x, yarn) (push) Failing after 34m7s
CI / Validate Components (push) Failing after 37m15s
CI / Python Tests (push) Failing after 10m1s
CI / Security Scan (push) Failing after 10m1s
CI / Lint (push) Failing after 17m12s
CI / Coverage (push) Failing after 20m19s
CI / Test (macos-latest, Node 18.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, yarn) (push) Has been cancelled
72 lines
2.7 KiB
Markdown
72 lines
2.7 KiB
Markdown
---
|
|
paths:
|
|
- "**/*.ts"
|
|
- "**/*.tsx"
|
|
---
|
|
# React Native / Expo Coding Style
|
|
|
|
> This file extends [common/coding-style.md](../common/coding-style.md) with React Native / Expo specific content.
|
|
|
|
## Components
|
|
|
|
- Define props with a named `interface` or `type`; do not use `React.FC`.
|
|
- Keep screens thin: a screen composes hooks + presentational components, it does not hold heavy logic.
|
|
- One component per file for anything reusable; co-locate small private subcomponents.
|
|
- Prefer function components and hooks. No class components.
|
|
|
|
```tsx
|
|
interface AvatarProps {
|
|
uri: string
|
|
size?: number
|
|
onPress?: () => void
|
|
}
|
|
|
|
export function Avatar({ uri, size = 40, onPress }: AvatarProps) {
|
|
return (
|
|
<Pressable onPress={onPress}>
|
|
<Image source={{ uri }} style={{ width: size, height: size, borderRadius: size / 2 }} />
|
|
</Pressable>
|
|
)
|
|
}
|
|
```
|
|
|
|
## Styling
|
|
|
|
Pick ONE styling system per project and stay consistent. `StyleSheet.create()` is the framework-native option; utility-class libraries (e.g. NativeWind) are a common alternative. This rule is library-agnostic — what matters is consistency and avoiding inline allocations.
|
|
|
|
- StyleSheet: define styles with `StyleSheet.create()` at module scope — never build style objects inline inside `render`/JSX on hot paths (it allocates on every render).
|
|
- Utility-class approach: extract repeated class strings into shared constants or a variant helper.
|
|
- Never hardcode raw colors, spacing, or font sizes scattered across files. Centralize design tokens (theme file or config).
|
|
|
|
```tsx
|
|
// WRONG: inline style object recreated every render
|
|
<View style={{ padding: 16, backgroundColor: '#fff' }} />
|
|
|
|
// CORRECT (StyleSheet)
|
|
const styles = StyleSheet.create({ card: { padding: 16, backgroundColor: '#fff' } })
|
|
<View style={styles.card} />
|
|
|
|
// CORRECT (NativeWind)
|
|
<View className="p-4 bg-white" />
|
|
```
|
|
|
|
## Platform Differences
|
|
|
|
- Use platform-specific files (`Component.ios.tsx`, `Component.android.tsx`) for substantial divergence.
|
|
- Use `Platform.select()` / `Platform.OS` for small differences only.
|
|
- Account for safe areas with `react-native-safe-area-context`; do not hardcode status bar / notch offsets.
|
|
|
|
## Imports & Project Layout
|
|
|
|
- Use the Expo/TS path alias (e.g. `@/components/...`) instead of long relative chains.
|
|
- Organize by feature/domain, not by type. Keep files focused (200-400 lines typical, 800 max).
|
|
|
|
## Logging
|
|
|
|
- No `console.log` in shipped code. Use a logger and strip logs in production builds.
|
|
- Surface user-facing errors through UI state, not console.
|
|
|
|
## TypeScript
|
|
|
|
All TypeScript rules from `rules/typescript/` apply (explicit types on public APIs, avoid `any`, Zod for validation, immutable updates). This file only adds RN-specific guidance on top.
|