@trustchex/react-native-sdk 1.163.4 → 1.163.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,8 @@ import { useIsFocused } from '@react-navigation/native';
4
4
  import { useKeepAwake } from "../Libs/native-keep-awake.utils.js";
5
5
  import React, { useEffect, useState } from 'react';
6
6
  import { StyleSheet, Text, View, Platform, Linking, Dimensions } from 'react-native';
7
- import { useCameraDevice, useCameraPermission, Camera, useFrameProcessor, useCameraFormat, runAtTargetFps, useMicrophonePermission, runAsync } from 'react-native-vision-camera';
7
+ import { useCameraDevice, useCameraPermission, Camera, useFrameProcessor, useCameraFormat, runAtTargetFps, useMicrophonePermission } from 'react-native-vision-camera';
8
+ import { runAsync } from "../Libs/worklet.utils.js";
8
9
  import { useFaceDetector } from "../VisionCameraPlugins/FaceDetector/index.js";
9
10
  import { Worklets, useSharedValue } from 'react-native-worklets-core';
10
11
  import { crop } from "../VisionCameraPlugins/Cropper/index.js";
@@ -3,7 +3,8 @@
3
3
  /* eslint-disable react-native/no-inline-styles */
4
4
  import React, { useEffect, useState } from 'react';
5
5
  import { View, StyleSheet, Text as TextView, Platform, Vibration, TouchableOpacity, Text, Linking, Image } from 'react-native';
6
- import { Camera, runAsync, runAtTargetFps, useCameraDevice, useCameraFormat, useCameraPermission, useFrameProcessor } from 'react-native-vision-camera';
6
+ import { Camera, runAtTargetFps, useCameraDevice, useCameraFormat, useCameraPermission, useFrameProcessor } from 'react-native-vision-camera';
7
+ import { runAsync } from "../Libs/worklet.utils.js";
7
8
  import { useRunOnJS, useSharedValue } from 'react-native-worklets-core';
8
9
  import { useTextRecognition } from "../VisionCameraPlugins/TextRecognition/index.js";
9
10
  import { useFaceDetector } from "../VisionCameraPlugins/FaceDetector/index.js";
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ import { Worklets } from 'react-native-worklets-core';
4
+ let isAsyncContextBusy;
5
+ let runOnAsyncContext;
6
+ try {
7
+ isAsyncContextBusy = Worklets.createSharedValue(false);
8
+ const asyncContext = Worklets.defaultContext;
9
+ runOnAsyncContext = asyncContext.createRunAsync((frame, func) => {
10
+ 'worklet';
11
+
12
+ try {
13
+ // Call long-running function
14
+ func();
15
+ } catch (e) {
16
+ // Re-throw error on JS Thread
17
+ throw e;
18
+ } finally {
19
+ // Potentially delete Frame if we were the last ref
20
+ const internal = frame;
21
+ internal.decrementRefCount();
22
+
23
+ // free up async context again, new calls can be made
24
+ isAsyncContextBusy.value = false;
25
+ }
26
+ });
27
+ } catch (e) {
28
+ // react-native-worklets-core is not installed!
29
+ // Just use dummy implementations that will throw when the user tries to use Frame Processors.
30
+ isAsyncContextBusy = {
31
+ value: false
32
+ };
33
+ runOnAsyncContext = () => {
34
+ throw new Error('react-native-worklets-core is not installed! Please install it to use Frame Processors.');
35
+ };
36
+ }
37
+ export function runAsync(frame, func) {
38
+ 'worklet';
39
+
40
+ if (isAsyncContextBusy.value) {
41
+ // async context is currently busy, we cannot schedule new work in time.
42
+ // drop this frame/runAsync call.
43
+ return;
44
+ }
45
+
46
+ // Increment ref count by one
47
+ const internal = frame;
48
+ internal.incrementRefCount();
49
+ isAsyncContextBusy.value = true;
50
+
51
+ // Call in separate background context
52
+ runOnAsyncContext(frame, func);
53
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"FaceCamera.d.ts","sourceRoot":"","sources":["../../../../../src/Shared/Components/FaceCamera.tsx"],"names":[],"mappings":"AAWA,OAAO,EAGL,MAAM,EAOP,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,KAAK,IAAI,EAEV,MAAM,qCAAqC,CAAC;AAO7C,MAAM,MAAM,eAAe,GAAG;IAC5B,eAAe,EAAE,CACf,KAAK,EAAE,IAAI,EAAE,EACb,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,OAAO,KACnB,IAAI,CAAC;IACV,mBAAmB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/C,CAAC;AAQF,QAAA,MAAM,UAAU,GAAI,2CAGjB,eAAe,4CA2LjB,CAAC;AA6BF,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"FaceCamera.d.ts","sourceRoot":"","sources":["../../../../../src/Shared/Components/FaceCamera.tsx"],"names":[],"mappings":"AAWA,OAAO,EAGL,MAAM,EAKP,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EACL,KAAK,IAAI,EAEV,MAAM,qCAAqC,CAAC;AAO7C,MAAM,MAAM,eAAe,GAAG;IAC5B,eAAe,EAAE,CACf,KAAK,EAAE,IAAI,EAAE,EACb,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,OAAO,KACnB,IAAI,CAAC;IACV,mBAAmB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/C,CAAC;AAQF,QAAA,MAAM,UAAU,GAAI,2CAGjB,eAAe,4CA2LjB,CAAC;AA6BF,eAAe,UAAU,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Frame } from 'react-native-vision-camera';
2
+ export declare function runAsync(frame: Frame, func: () => void): void;
3
+ //# sourceMappingURL=worklet.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worklet.utils.d.ts","sourceRoot":"","sources":["../../../../../src/Shared/Libs/worklet.utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAiB,MAAM,4BAA4B,CAAC;AAwCvE,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,GAAG,IAAI,CAiB7D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trustchex/react-native-sdk",
3
- "version": "1.163.4",
3
+ "version": "1.163.6",
4
4
  "description": "Trustchex mobile app react native SDK for android or ios devices",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -16,10 +16,10 @@ import {
16
16
  useFrameProcessor,
17
17
  useCameraFormat,
18
18
  runAtTargetFps,
19
- type Frame,
20
19
  useMicrophonePermission,
21
- runAsync,
22
20
  } from 'react-native-vision-camera';
21
+ import type { Frame } from 'react-native-vision-camera';
22
+ import { runAsync } from '../Libs/worklet.utils';
23
23
  import {
24
24
  type Face,
25
25
  useFaceDetector,
@@ -14,14 +14,14 @@ import {
14
14
  } from 'react-native';
15
15
  import {
16
16
  Camera,
17
- type Frame,
18
- runAsync,
19
17
  runAtTargetFps,
20
18
  useCameraDevice,
21
19
  useCameraFormat,
22
20
  useCameraPermission,
23
21
  useFrameProcessor,
24
22
  } from 'react-native-vision-camera';
23
+ import type { Frame } from 'react-native-vision-camera';
24
+ import { runAsync } from '../Libs/worklet.utils';
25
25
  import { useRunOnJS, useSharedValue } from 'react-native-worklets-core';
26
26
  import { useTextRecognition } from '../VisionCameraPlugins/TextRecognition';
27
27
  import type { FieldRecords } from 'mrz';
@@ -0,0 +1,58 @@
1
+ import type { Frame, FrameInternal } from 'react-native-vision-camera';
2
+ import { Worklets } from 'react-native-worklets-core';
3
+
4
+ let isAsyncContextBusy: { value: boolean };
5
+ let runOnAsyncContext: (frame: Frame, func: () => void) => void;
6
+
7
+ try {
8
+ isAsyncContextBusy = Worklets.createSharedValue(false);
9
+
10
+ const asyncContext = Worklets.defaultContext;
11
+ runOnAsyncContext = asyncContext.createRunAsync(
12
+ (frame: Frame, func: () => void) => {
13
+ 'worklet';
14
+ try {
15
+ // Call long-running function
16
+ func();
17
+ } catch (e) {
18
+ // Re-throw error on JS Thread
19
+ throw e;
20
+ } finally {
21
+ // Potentially delete Frame if we were the last ref
22
+ const internal = frame as FrameInternal;
23
+ internal.decrementRefCount();
24
+
25
+ // free up async context again, new calls can be made
26
+ isAsyncContextBusy.value = false;
27
+ }
28
+ }
29
+ );
30
+ } catch (e) {
31
+ // react-native-worklets-core is not installed!
32
+ // Just use dummy implementations that will throw when the user tries to use Frame Processors.
33
+ isAsyncContextBusy = { value: false };
34
+ runOnAsyncContext = () => {
35
+ throw new Error(
36
+ 'react-native-worklets-core is not installed! Please install it to use Frame Processors.'
37
+ );
38
+ };
39
+ }
40
+
41
+ export function runAsync(frame: Frame, func: () => void): void {
42
+ 'worklet';
43
+
44
+ if (isAsyncContextBusy.value) {
45
+ // async context is currently busy, we cannot schedule new work in time.
46
+ // drop this frame/runAsync call.
47
+ return;
48
+ }
49
+
50
+ // Increment ref count by one
51
+ const internal = frame as FrameInternal;
52
+ internal.incrementRefCount();
53
+
54
+ isAsyncContextBusy.value = true;
55
+
56
+ // Call in separate background context
57
+ runOnAsyncContext(frame, func);
58
+ }