Initial Setup
Quickly create a new project using the React Native Reusables CLI.
Usage
Run the following command in your terminal, answer the prompts, and you’re good to go!
Features
File structure
Directoryapps
- _layout.tsx
- +not-found.tsx
- index.tsx
Directoryassets
Directoryimages
- adaptive-icon.png
- favicon.png
- icon.png
- splash.png
Directorycomponents
Directoryui
- avatar.tsx
- button.tsx
- card.tsx
- progress.tsx
- text.tsx
- tooltip.tsx
- ToggleTheme.tsx
Directorylib
Directoryicons
- iconWithClassName.ts
- Info.tsx
- MoonStar.tsx
- Sun.tsx
- android-navigation-bar.tsx
- constants.ts
- useColorScheme.tsx
- utils.ts
- .gitignore
- app.json
- babel.config.js
- global.css
- index.js
- metro.config.js
- nativewind-env.d.ts
- package.json
- README.md
- tailwind.config.js
- tsconfig.json
Options
Option | Description | Default |
---|---|---|
-c, --cwd <path> | The working directory | Current directory |
-o, --overwrite | Overwrite existing files (for existing projects) | false |
- Follow the installation guide for NativeWind from the official documentation
- Install the following packages:
Platforms: Web, iOS, and Android
Platforms: iOS and Android
- Configure path aliases
We use the ~
alias. This is how you can configure it in your tsconfig.json
file:
- Add a cn helper
Add the following code to the ~/lib/utils.ts
file:
- Add the useColorScheme hook
Add the following code to the ~/lib/useColorScheme.tsx
file:
- Add the following css variables to
~/global.css
file.
- Add the following code in the
~/lib/constants.ts
file for the navigation theme colors:
If you changed the colors in the ~/global.css
file, update the ~/lib/constants.ts
file with the new colors.
Each color has a commented css variable name next to it.
- Use the CSS variables in your tailwind.config.js file.
Platforms: Web, iOS, and Android
Platforms: iOS and Android
- Configure React Navigation Theme
In your root component (ex: the root _layout.tsx
if you’re using expo-router), add the following code
to load the selected theme, prevent the flash of the default theme,
and store the selected theme in the async storage.
- Add the
<ToggleTheme/>
icons
Follow the next step and add the <Sun/>
and <MoonStar/>
icons from the examples.