First, navigate to the React Native docs to add the required dependencies for running React Native.
Only the Installing Dependencies section of the documentation is required for getting started with the Example App.
Follow the docs for adding the required dependencies making sure the React Native CLI Quickstart tab is selected. Click on macOS as the Development Environment, and select either Android or iOS as the target OS with the following caveat:
If using an M1 Macbook and getting started with iOS, in the install CocoaPods
step, rather than installing ffi
, install CocoaPods
via brew
:
arch -arm64 brew install cocoapods
the Example App assumes usage with macOS and has not been tested for Windows or Linux development.
Only required for fresh installs.
From the monorepo root run the following commands:
- Install dependencies and build packages:
yarn && yarn build
- Install CocoaPod dependencies:
yarn react-native-example ios:pod-install
- Build and install the Example App:
yarn react-native-example ios
- Install dependencies and build packages:
yarn && yarn build
- Build and install the Example App:
yarn react-native-example android
When developing locally, always run any dependency dev
commands for the dependency packages before starting the React Native dev server.
This prevents the Metro bundler from encountering a module resolution error while watching the dist direectory of the dependency during its recreation at the onset of a dev
command, when the dist directory is initially rebuilt.
All of the below commands should be run from the monorepo root.
- To optionally develop against
@aws-amplify/ui-react-native
:
yarn react-native dev
- To optionally develop against
@aws-amplify/ui
:
yarn ui dev
- Run:
yarn react-native-example dev
- Open the app on the iOS simulator or Android emulator.
Will serve a web interface that allows switching between components (stories) and controlling multiple simulators/emulators.
First boot Storybook Server:
# terminal 1
yarn run react-native-example storybook
From a second terminal run iOS simulator, Android emulator or both (requires app to be installed):
# terminal 2
yarn run react-native-example dev
Refresh the Storybook web interface to load all the stories.
yarn run react-native-example dev
In the Storybook app switch between Navigator
and Preview
tabs to select components/stories.
To include an Amplify UI package as a dependency add it to the dependencies
field of the Example App's package.json using the package name for the key and *
as the version (informs Metro bundler to treat as an internal dependency):
"dependencies": {
"@aws-amplify/ui": "*",
...
},
Only internal packages within the packages directory are resolved in metro.config.js
Adding Dependencies with Native Modules or direct React usage required by @aws-amplify/ui-react-native
Metro needs to be informed of the location of dependencies with native modules and dependencies that use React directly. Any new dependency added to @aws-amplify/ui-react-native
with native modules or a dependency on React will need to be added to the config.resolver.extraNodeModules
field of the metro.config.js with the path to resolve, example:
config.resolver.extraNodeModules = {
'react-native': path.resolve(__dirname, 'node_modules/react-native'),
}
Add a local .env file, then copy/paste the contents of .env.sample inside, updating the values as needed:
# .env
GREETING='Hello World!'
Add your variable name to .env (and .env.sample if committing) and to ./types/env.d.ts to appease typescript:
# .env
GREETING='Hello World!'
MY_ENV_VARIABLE=FOO
// ./types/env.d.ts
declare module '@env' {
export const GREETING: string;
export const MY_ENV_VARIABLE: string;
}
To use your newly added env variable:
// *.tsx
import { MY_ENV_VARIABLE } from '@env';
If the example app is not picking up changes to the values in .env close Metro and reset the cache (see troubleshooting section).
yarn react-native-example dev --reset-cache