Skip to content

Commit

Permalink
Add information about exported shared components and usage (#596)
Browse files Browse the repository at this point in the history
Co-authored-by: Krzysztof Magiera <[email protected]>
  • Loading branch information
jakub-gonet and kmagiera authored Oct 9, 2024
1 parent eeac72c commit f972a6d
Showing 1 changed file with 40 additions and 9 deletions.
49 changes: 40 additions & 9 deletions packages/docs/docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,43 @@ Unfortunately debugging isn't available for the frontend code, however you can u

## Shared app template

In `test-apps/` directory there is `shared/` directory with the common UI code for
apps. To use this code in the app, use `copy.sh` script. It should use minimal
set of dependencies, ideally nothing except react-native.
If app uses expo-router, we additionally copy `shared/navigation/` directory
which uses expo-router and `@expo/vector-icons`.

If app wants to use this shared code, it should add an entry to .gitignore for
shared directory under its own `src/` and run copy script. If shared code is
updated, every app using it should rerun the copy script.
We provide few shared components with common code across tests apps in `shared/`
directory.
They only depend on `react-native`. Components in `shared/navigation` additionally
depend on `expo-router` and `expo-icons`.

To use them in the app:
1. Add npm command in test app package.json
- for expo-router apps: `"copy-shared": "../shared/copy.sh expo-router ./shared"`.
- for RN apps: `"copy-shared": "../shared/copy.sh bare ./shared"`.
2. Run it: `npm run copy-shared`. This copies shared components to `./shared`.
3. For RN apps, replace `App.tsx` with the `./shared/MainScreen.tsx` component.
```ts
import {MainScreen} from './shared/MainScreen';

export default MainScreen;
```
4. For apps with expo router, replace `app/(tabs)/_layout.tsx` and
`app/(tabs)/index.tsx` files.
```ts
// contents of `app/(tabs)/_layout.ts`
import { TabLayout } from "@/shared/navigation/TabLayout";
export default TabLayout;
```

```ts
// contents of `app/(tabs)/index.ts`
import { MainScreen } from "@/shared/MainScreen";
export default MainScreen;
```

You can also use other components in `shared` (e.g. `Text`, `Button`,
`useScheme`) to theme the app.

After updating shared components you need to copy them again by running
`npm run copy-shared` in every test app.

`shared/copy.sh bare|expo-router DEST` script works by copying shared directory to `DEST`
and removing `navigation` directory if `bare` argument is used.

0 comments on commit f972a6d

Please sign in to comment.