This example demonstrates how to connect to a robot using a React Native app. For a summary of changes required to use the TypeScript SDK with React Native, view the Configuration section.
- Run
npm install
- Open
App.tsx
and update thehost
and APIcredentials
. - Run
npm run {ios|android}
- If running on iOS, you may have to install dependencies:
cd ios && pod install && popd
- If running on Android, you may have to export Android tool locations:
export ANDROID_HOME=$HOME/Library/Android/sdk export PATH=$PATH:$ANDROID_HOME/emulator export PATH=$PATH:$ANDROID_HOME/platform-tools
- If running on iOS, you may have to install dependencies:
Using Viam's TypeScript SDK with React Native requires some configurations. They are outlined below:
The following direct dependencies are required:
react-native-webrtc
react-native-url-polyfill
@improbable-eng/grpc-web-react-native-transport
The index.js
file was updated to include the following polyfills and updates:
-
URL polyfill:
import 'react-native-url-polyfill/auto';
-
React Native WebRTC globals:
import {registerGlobals} from 'react-native-webrtc'; registerGlobals();
-
GRPC connection configuration
import {ReactNativeTransport} from '@improbable-eng/grpc-web-react-native-transport'; global.VIAM = { GRPC_TRANSPORT_FACTORY: ReactNativeTransport, };
The metro.config.js
file was also updated. react-native
and react-native-webrtc
require conflicting versions of the library event-target-shim
. By updating the metro.config.js
file, the Metro Bundler knows how to package this library properly.
The ACCESS_NETWORK_STATE
permission was added to the AndroidManifest.xml
:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />