Commit 9d97b218 authored by Javokhir's avatar Javokhir
Browse files

chore: replace demo app with react-native library scaffold

Repo becomes the myid-sdk npm package: library at root, RN 0.86.2 vanilla
example app in example/, Turbo Module codegen enabled, yarn 4 workspace.

The previous demo app targeted MyID SDK 2.x (clientId, withPassportData,
MyIdBuildMode), an API that no longer exists in 3.x, so it is removed rather
than migrated. Recoverable via the pre-rewrite tag.
parent 6511c69e
This is a new [**React Native**](https://reactnative.dev) project, bootstrapped using [`@react-native-community/cli`](https://github.com/react-native-community/cli). # myid-sdk
# Getting Started React Native wrapper for the MyID identity verification SDK
>**Note**: Make sure you have completed the [React Native - Environment Setup](https://reactnative.dev/docs/environment-setup) instructions till "Creating a new application" step, before proceeding. ## Installation
## Step 1: Start the Metro Server
First, you will need to start **Metro**, the JavaScript _bundler_ that ships _with_ React Native. ```sh
npm install myid-sdk
To start Metro, run the following command from the _root_ of your React Native project:
```bash
# using npm
npm start
# OR using Yarn
yarn start
``` ```
## Step 2: Start your Application
Let Metro Bundler run in its _own_ terminal. Open a _new_ terminal from the _root_ of your React Native project. Run the following command to start your _Android_ or _iOS_ app: ## Usage
### For Android
```bash ```js
# using npm import { multiply } from 'myid-sdk';
npm run android
# OR using Yarn // ...
yarn android
```
### For iOS const result = multiply(3, 7);
```bash
# using npm
npm run ios
# OR using Yarn
yarn ios
``` ```
If everything is set up _correctly_, you should see your new 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.
## Step 3: Modifying your App
Now that you have successfully run the app, let's modify it.
1. Open `App.tsx` in your text editor of choice and edit some lines.
2. For **Android**: Press the <kbd>R</kbd> key twice or select **"Reload"** from the **Developer Menu** (<kbd>Ctrl</kbd> + <kbd>M</kbd> (on Window and Linux) or <kbd>Cmd ⌘</kbd> + <kbd>M</kbd> (on macOS)) to see your changes!
For **iOS**: Hit <kbd>Cmd ⌘</kbd> + <kbd>R</kbd> in your iOS Simulator to reload the app and see your changes!
## Congratulations! :tada:
You've successfully run and modified your React Native App. :partying_face:
### Now what?
- If you want to add this new React Native code to an existing application, check out the [Integration guide](https://reactnative.dev/docs/integration-with-existing-apps). ## Contributing
- If you're curious to learn more about React Native, check out the [Introduction to React Native](https://reactnative.dev/docs/getting-started).
# Troubleshooting - [Development workflow](CONTRIBUTING.md#development-workflow)
- [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
- [Code of conduct](CODE_OF_CONDUCT.md)
If you can't get this to work, see the [Troubleshooting](https://reactnative.dev/docs/troubleshooting) page. ## License
# Learn More MIT
To learn more about React Native, take a look at the following resources: ---
- [React Native Website](https://reactnative.dev) - learn more about React Native. Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
- [Getting Started](https://reactnative.dev/docs/environment-setup) - an **overview** of React Native and how setup your environment.
- [Learn the Basics](https://reactnative.dev/docs/getting-started) - a **guided tour** of the React Native **basics**.
- [Blog](https://reactnative.dev/blog) - read the latest official React Native **Blog** posts.
- [`@facebook/react-native`](https://github.com/facebook/react-native) - the Open Source; GitHub **repository** for React Native.
/**
* @format
*/
import 'react-native';
import React from 'react';
import App from '../App';
// Note: import explicitly to use the types shipped with jest.
import {it} from '@jest/globals';
// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';
it('renders correctly', () => {
renderer.create(<App />);
});
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:usesCleartextTraffic="true"
tools:targetApi="28"
tools:ignore="GoogleAppIndexingWarning"/>
</manifest>
package com.myid
import android.app.Application
import com.facebook.react.PackageList
import com.facebook.react.ReactApplication
import com.facebook.react.ReactHost
import com.facebook.react.ReactNativeHost
import com.facebook.react.ReactPackage
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
import com.facebook.react.defaults.DefaultReactNativeHost
import com.facebook.soloader.SoLoader
class MainApplication : Application(), ReactApplication {
override val reactNativeHost: ReactNativeHost =
object : DefaultReactNativeHost(this) {
override fun getPackages(): List<ReactPackage> =
PackageList(this).packages.apply {
// Packages that cannot be autolinked yet can be added manually here, for example:
// add(MyReactNativePackage())
add(ReactPackage())
}
override fun getJSMainModuleName(): String = "index"
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
}
override val reactHost: ReactHost
get() = getDefaultReactHost(applicationContext, reactNativeHost)
override fun onCreate() {
super.onCreate()
SoLoader.init(this, false)
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// If you opted-in for the New Architecture, we load the native entry point for this app.
load()
}
}
}
package com.myid
import android.app.Activity
import android.content.Intent
import android.graphics.Bitmap
import android.util.Base64
import android.util.Log
import com.facebook.react.bridge.*
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter
import uz.myid.android.sdk.capture.MyIdClient
import uz.myid.android.sdk.capture.MyIdConfig
import uz.myid.android.sdk.capture.MyIdException
import uz.myid.android.sdk.capture.MyIdResult
import uz.myid.android.sdk.capture.MyIdResultListener
import uz.myid.android.sdk.capture.model.MyIdBuildMode
import uz.myid.android.sdk.capture.model.MyIdCameraShape
import uz.myid.android.sdk.capture.model.MyIdEntryType
import uz.myid.android.sdk.capture.model.MyIdGraphicFieldType
import java.io.ByteArrayOutputStream
import java.util.*
class MyIdModule(private val reactContext: ReactApplicationContext) :
ReactContextBaseJavaModule(reactContext), MyIdResultListener, ActivityEventListener {
private val client = MyIdClient()
init {
reactContext.addActivityEventListener(this)
}
override fun getName(): String = "MyIdModule"
@ReactMethod
fun addListener(eventName: String?) {
// Method to add listeners (placeholder for actual implementation if needed)
}
@ReactMethod
fun removeListeners(count: Int?) {
// Method to remove listeners (placeholder for actual implementation if needed)
}
@ReactMethod
fun startMyId(clientId: String, clientHash: String, clientHashId: String, passportData: String, dateOfBirth: String, buildMode: String) {
Log.d("MyIdModule", "startMyId called with clientId: $clientId")
val mode = if (buildMode == "PRODUCTION") MyIdBuildMode.PRODUCTION else MyIdBuildMode.DEBUG
val config = MyIdConfig.Builder(clientId)
.withClientHash(clientHash, clientHashId)
.withPassportData(passportData)
.withBirthDate(dateOfBirth)
.withBuildMode(mode)
.build()
reactContext.currentActivity?.let {
val intent = client.createIntent(it, config)
it.startActivityForResult(intent, MY_ID_REQUEST_CODE)
} ?: Log.e("MyIdModule", "Current activity is null.")
}
override fun onActivityResult(activity: Activity?, requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == MY_ID_REQUEST_CODE) {
Log.d("onActivity",data.toString())
client.handleActivityResult(resultCode, this)
}
}
override fun onNewIntent(p0: Intent?) {
TODO("Not yet implemented")
}
override fun onSuccess(result: MyIdResult) {
Log.d("MyIdModule", "onSuccess called")
val bitmap = result.getGraphicFieldImageByType(MyIdGraphicFieldType.FACE_PORTRAIT)
val base64Image = bitmap?.let { encodeToBase64(it) }
Log.d("base64Image",base64Image!!)
val params = Arguments.createMap().apply {
putString("code", result.code)
putDouble("comparison", result.comparison.toDouble())
putString("image", base64Image)
}
sendEvent("onSuccess", params)
}
override fun onError(e: MyIdException) {
Log.d("MyIdModule", "onError called")
val params = Arguments.createMap().apply {
putString("message", e.message)
putInt("code", e.code)
}
sendEvent("onError", params)
}
override fun onUserExited() {
Log.d("MyIdModule", "onUserExited called")
val params = Arguments.createMap().apply {
putString("message", "User exited SDK")
}
sendEvent("onUserExited", params)
}
private fun sendEvent(eventName: String, params: WritableMap) {
Log.d("MyIdModule", "sending event $eventName")
reactContext.getJSModule(RCTDeviceEventEmitter::class.java).emit(eventName, params)
}
private fun encodeToBase64(bitmap: Bitmap): String {
val outputStream = ByteArrayOutputStream()
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream)
return Base64.encodeToString(outputStream.toByteArray(), Base64.DEFAULT)
}
companion object {
private const val MY_ID_REQUEST_CODE = 1
}
}
package com.myid
import android.view.View
import com.facebook.react.ReactPackage
import com.facebook.react.bridge.NativeModule
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.uimanager.ReactShadowNode
import com.facebook.react.uimanager.ViewManager
class ReactPackage : ReactPackage {
override fun createViewManagers(
reactContext: ReactApplicationContext
): MutableList<ViewManager<View, ReactShadowNode<*>>> = mutableListOf()
override fun createNativeModules(
reactContext: ReactApplicationContext
): MutableList<NativeModule> = listOf(MyIdModule(reactContext)).toMutableList()
}
\ No newline at end of file
buildscript { buildscript {
ext { ext.MyidSdk = [
buildToolsVersion = "34.0.0" kotlinVersion: "2.0.21",
minSdkVersion = 23 minSdkVersion: 24,
compileSdkVersion = 34 compileSdkVersion: 36
targetSdkVersion = 34 ]
ndkVersion = "26.1.10909125"
kotlinVersion = "1.9.22" ext.getExtOrDefault = { prop ->
} if (rootProject.ext.has(prop)) {
repositories { return rootProject.ext.get(prop)
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
} }
return MyidSdk[prop]
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:8.7.2"
// noinspection DifferentKotlinGradleVersion
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
}
} }
apply plugin: "com.facebook.react.rootproject"
apply plugin: "com.android.library"
if (project.extensions.findByName("kotlin") == null) {
apply plugin: "kotlin-android"
}
apply plugin: "com.facebook.react"
android {
namespace "com.myidsdk"
compileSdkVersion getExtOrDefault("compileSdkVersion")
defaultConfig {
minSdkVersion getExtOrDefault("minSdkVersion")
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}
dependencies {
implementation "com.facebook.react:react-android"
}
rootProject.name = 'MyID'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
includeBuild('../node_modules/@react-native/gradle-plugin')
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>
package com.myidsdk
import com.facebook.react.bridge.ReactApplicationContext
class MyidSdkModule(reactContext: ReactApplicationContext) :
NativeMyidSdkSpec(reactContext) {
override fun multiply(a: Double, b: Double): Double {
return a * b
}
companion object {
const val NAME = NativeMyidSdkSpec.NAME
}
}
package com.myidsdk
import com.facebook.react.BaseReactPackage
import com.facebook.react.bridge.NativeModule
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.module.model.ReactModuleInfo
import com.facebook.react.module.model.ReactModuleInfoProvider
import java.util.HashMap
class MyidSdkPackage : BaseReactPackage() {
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
return if (name == MyidSdkModule.NAME) {
MyidSdkModule(reactContext)
} else {
null
}
}
override fun getReactModuleInfoProvider() = ReactModuleInfoProvider {
mapOf(
MyidSdkModule.NAME to ReactModuleInfo(
name = MyidSdkModule.NAME,
className = MyidSdkModule.NAME,
canOverrideExistingModule = false,
needsEagerInit = false,
isCxxModule = false,
isTurboModule = true
)
)
}
}
{
"name": "MyID",
"displayName": "MyID"
}
module.exports = { module.exports = {
presets: ['module:@react-native/babel-preset'], overrides: [
{
exclude: /\/node_modules\//,
presets: ['module:react-native-builder-bob/babel-preset'],
},
{
include: /\/node_modules\//,
presets: ['module:@react-native/babel-preset'],
},
],
}; };
import { fixupConfigRules } from '@eslint/compat';
import { FlatCompat } from '@eslint/eslintrc';
import js from '@eslint/js';
import prettier from 'eslint-plugin-prettier';
import { defineConfig } from 'eslint/config';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});
export default defineConfig([
{
extends: fixupConfigRules(compat.extends('@react-native', 'prettier')),
plugins: { prettier },
rules: {
'react/react-in-jsx-scope': 'off',
'prettier/prettier': 'error',
},
},
{
ignores: ['node_modules/', 'lib/'],
},
]);
source 'https://rubygems.org'
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
ruby ">= 2.6.10"
# Exclude problematic versions of cocoapods and activesupport that causes build failures.
gem 'cocoapods', '>= 1.13', '!= 1.15.0', '!= 1.15.1'
gem 'activesupport', '>= 6.1.7.5', '!= 7.1.0'
gem 'xcodeproj', '< 1.26.0'
gem 'concurrent-ruby', '< 1.3.4'
# Ruby 3.4.0 has removed some libraries from the standard library.
gem 'bigdecimal'
gem 'logger'
gem 'benchmark'
gem 'mutex_m'
gem 'nkf'
This is a new [**React Native**](https://reactnative.dev) project, bootstrapped using [`@react-native-community/cli`](https://github.com/react-native-community/cli).
# Getting Started
> **Note**: Make sure you have completed the [Set Up Your Environment](https://reactnative.dev/docs/set-up-your-environment) guide before proceeding.
## Step 1: Start Metro
First, you will need to run **Metro**, the JavaScript build tool for React Native.
To start the Metro dev server, run the following command from the root of your React Native project:
```sh
# Using npm
npm start
# OR using Yarn
yarn start
```
## Step 2: Build and run your app
With Metro running, open a new terminal window/pane from the root of your React Native project, and use one of the following commands to build and run your Android or iOS app:
### Android
```sh
# Using npm
npm run android
# OR using Yarn
yarn android
```
### iOS
For iOS, remember to install CocoaPods dependencies (this only needs to be run on first clone or after updating native deps).
The first time you create a new project, run the Ruby bundler to install CocoaPods itself:
```sh
bundle install
```
Then, and every time you update your native dependencies, run:
```sh
bundle exec pod install
```
For more information, please visit [CocoaPods Getting Started guide](https://guides.cocoapods.org/using/getting-started.html).
```sh
# Using npm
npm run ios
# OR using Yarn
yarn ios
```
If everything is set up correctly, you should see your new app running in the Android Emulator, iOS Simulator, or your connected device.
This is one way to run your app — you can also build it directly from Android Studio or Xcode.
## Step 3: Modify your app
Now that you have successfully run the app, let's make changes!
Open `App.tsx` in your text editor of choice and make some changes. When you save, your app will automatically update and reflect these changes — this is powered by [Fast Refresh](https://reactnative.dev/docs/fast-refresh).
When you want to forcefully reload, for example to reset the state of your app, you can perform a full reload:
- **Android**: Press the <kbd>R</kbd> key twice or select **"Reload"** from the **Dev Menu**, accessed via <kbd>Ctrl</kbd> + <kbd>M</kbd> (Windows/Linux) or <kbd>Cmd ⌘</kbd> + <kbd>M</kbd> (macOS).
- **iOS**: Press <kbd>R</kbd> in iOS Simulator.
## Congratulations! :tada:
You've successfully run and modified your React Native App. :partying_face:
### Now what?
- If you want to add this new React Native code to an existing application, check out the [Integration guide](https://reactnative.dev/docs/integration-with-existing-apps).
- If you're curious to learn more about React Native, check out the [docs](https://reactnative.dev/docs/getting-started).
# Troubleshooting
If you're having issues getting the above steps to work, see the [Troubleshooting](https://reactnative.dev/docs/troubleshooting) page.
# Learn More
To learn more about React Native, take a look at the following resources:
- [React Native Website](https://reactnative.dev) - learn more about React Native.
- [Getting Started](https://reactnative.dev/docs/environment-setup) - an **overview** of React Native and how setup your environment.
- [Learn the Basics](https://reactnative.dev/docs/getting-started) - a **guided tour** of the React Native **basics**.
- [Blog](https://reactnative.dev/blog) - read the latest official React Native **Blog** posts.
- [`@facebook/react-native`](https://github.com/facebook/react-native) - the Open Source; GitHub **repository** for React Native.
...@@ -8,20 +8,20 @@ apply plugin: "com.facebook.react" ...@@ -8,20 +8,20 @@ apply plugin: "com.facebook.react"
*/ */
react { react {
/* Folders */ /* Folders */
// The root of your project, i.e. where "package.json" lives. Default is '..' // The root of your project, i.e. where "package.json" lives. Default is '../..'
// root = file("../") // root = file("../../")
// The folder where the react-native NPM package is. Default is ../node_modules/react-native // The folder where the react-native NPM package is. Default is ../../node_modules/react-native
// reactNativeDir = file("../node_modules/react-native") // reactNativeDir = file("../../node_modules/react-native")
// The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen // The folder where the react-native Codegen package is. Default is ../../node_modules/@react-native/codegen
// codegenDir = file("../node_modules/@react-native/codegen") // codegenDir = file("../../node_modules/@react-native/codegen")
// The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js // The cli.js file which is the React Native CLI entrypoint. Default is ../../node_modules/react-native/cli.js
// cliFile = file("../node_modules/react-native/cli.js") // cliFile = file("../../node_modules/react-native/cli.js")
/* Variants */ /* Variants */
// The list of variants to that are debuggable. For those we're going to // The list of variants to that are debuggable. For those we're going to
// skip the bundling of the JS bundle and the assets. By default is just 'debug'. // skip the bundling of the JS bundle and the assets. Default is "debug", "debugOptimized".
// If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants. // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
// debuggableVariants = ["liteDebug", "prodDebug"] // debuggableVariants = ["liteDebug", "liteDebugOptimized", "prodDebug", "prodDebugOptimized"]
/* Bundling */ /* Bundling */
// A list containing the node command and its flags. Default is just 'node'. // A list containing the node command and its flags. Default is just 'node'.
...@@ -49,6 +49,9 @@ react { ...@@ -49,6 +49,9 @@ react {
// //
// The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map" // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
// hermesFlags = ["-O", "-output-source-map"] // hermesFlags = ["-O", "-output-source-map"]
/* Autolinking */
autolinkLibrariesWithApp()
} }
/** /**
...@@ -60,23 +63,23 @@ def enableProguardInReleaseBuilds = false ...@@ -60,23 +63,23 @@ def enableProguardInReleaseBuilds = false
* The preferred build flavor of JavaScriptCore (JSC) * The preferred build flavor of JavaScriptCore (JSC)
* *
* For example, to use the international variant, you can use: * For example, to use the international variant, you can use:
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'` * `def jscFlavor = io.github.react-native-community:jsc-android-intl:2026004.+`
* *
* The international variant includes ICU i18n library and necessary data * The international variant includes ICU i18n library and necessary data
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
* give correct results when using with locales other than en-US. Note that * give correct results when using with locales other than en-US. Note that
* this variant is about 6MiB larger per architecture than default. * this variant is about 6MiB larger per architecture than default.
*/ */
def jscFlavor = 'org.webkit:android-jsc:+' def jscFlavor = 'io.github.react-native-community:jsc-android:2026004.+'
android { android {
ndkVersion rootProject.ext.ndkVersion ndkVersion rootProject.ext.ndkVersion
buildToolsVersion rootProject.ext.buildToolsVersion buildToolsVersion rootProject.ext.buildToolsVersion
compileSdk rootProject.ext.compileSdkVersion compileSdk rootProject.ext.compileSdkVersion
namespace "com.myid" namespace "myidsdk.example"
defaultConfig { defaultConfig {
applicationId "com.myid" applicationId "myidsdk.example"
minSdkVersion rootProject.ext.minSdkVersion minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1 versionCode 1
...@@ -104,12 +107,6 @@ android { ...@@ -104,12 +107,6 @@ android {
} }
} }
repositories {
google()
mavenCentral()
maven { url "https://artifactory.aigroup.uz:443/artifactory/myid" }
}
dependencies { dependencies {
// The version of react-native is set by the React Native Gradle Plugin // The version of react-native is set by the React Native Gradle Plugin
implementation("com.facebook.react:react-android") implementation("com.facebook.react:react-android")
...@@ -119,9 +116,4 @@ dependencies { ...@@ -119,9 +116,4 @@ dependencies {
} else { } else {
implementation jscFlavor implementation jscFlavor
} }
//MyId
implementation("uz.myid.sdk.capture:myid-capture-sdk:2.3.4")
} }
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment