This repository contains a basic example on how to use DOT SDK (iOS/Android) in React Native (typescript).
Note: Make sure you have completed the React Native - Environment Setup instructions till "Creating a new application" step, before proceeding. This project was developed and tested using Node.js v22.2.0.
To obtain a license file, please contact [email protected]
.
- Copy the license file to
android/app/src/main/res/raw/dot_license.lic
.
- Copy the license file to
ios/Assets/dot_license.lic
. - Run
pod install --repo-update
fromios
directory. - Open
DotReactNativeSamples.xcworkspace
and update app signing configuration using your certificates and profiles.
You will need to start Metro, the JavaScript bundler that ships with React Native. First, make sure you have all dependencies. Run:
npm install
To start Metro, run the following command from the root of your this repository:
# using npm
npm start
# OR using Yarn
yarn start
Let Metro Bundler run in its own terminal. Open a new terminal from the root of this repository. Run the following command to start your Android or iOS app:
# using npm
npm run android
# OR using Yarn
yarn android
# using npm
npm run ios
# OR using Yarn
yarn ios
If everything is set up correctly, you should see DOT SDK React Native Samples App running in your Android Emulator or iOS Simulator shortly provided you have set up your emulator/simulator correctly.
This is one way to run your app — you can also run it directly from within Android Studio and Xcode respectively.
Code responsible for bridge between the Kotlin and Typescript code can be found in:
DotSdkReactModule.kt
- A native module is a Kotlin class that extends the ReactContextBaseJavaModule class and implements the functionality required by the TypeScript. Most methods (annotated by@ReactModule
) are callable from TypeScript and are responsible for starting activities and retrieving data from them.DotSdkReactPackage.kt
- Apps package that extendsReactPackage
and usescreateNativeModules
to register a native module.MainApplication.kt
- We have to provide the package togetPackages
method of theMainApplication
- this is pre-existing file/class created by react-native
More information about native modules here: https://facebook.github.io/react-native/docs/native-modules-android.
Code responsible for bridge between the Swift and Typescript code can be found in:
DotSdkReactModuleBridge.m
- A native module bridge which registers required information with React Native.DotSdkReactModule.swift
- A native module Swift class which implements the functionality required by the TypeScript.
More information about native modules here: https://reactnative.dev/docs/native-modules-ios.
We can use DotSdk
class found in NativeModules
exported from react-native
. It will call native code for the corresponding platform (iOS/Android).
Code can be found in App.tsx
(root of the repo).
Example:
import { NativeModules } from 'react-native';
const dotSdk = NativeModules.DotSdk
// Initialize DOT SDK
dotSdk.initialize()
.then(...)
.catch(...);
...
...
// Start Document Auto Capture component
dotSdk.startDocumentAutoCapture(null)
.then(...)
.catch(...);