@ankhorage/expo-runtime 6.0.3 → 7.0.1
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.
- package/CHANGELOG.md +12 -0
- package/README.md +1 -1
- package/dist/ExpoBarcodeScannerAdapter.d.ts +6 -1
- package/dist/ExpoBarcodeScannerAdapter.d.ts.map +1 -1
- package/dist/ExpoBarcodeScannerAdapter.js +3 -8
- package/dist/ExpoBarcodeScannerAdapter.js.map +1 -1
- package/dist/ExpoZoraIconFontProvider.web.d.ts +1 -1
- package/dist/ExpoZoraIconFontProvider.web.d.ts.map +1 -1
- package/dist/ExpoZoraIconFontProvider.web.js +1 -4
- package/dist/ExpoZoraIconFontProvider.web.js.map +1 -1
- package/dist/barcodeScanRuntime.d.ts +2 -14
- package/dist/barcodeScanRuntime.d.ts.map +1 -1
- package/dist/barcodeScanRuntime.js +1 -33
- package/dist/barcodeScanRuntime.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/src/ExpoBarcodeScannerAdapter.test.tsx +13 -84
- package/src/ExpoBarcodeScannerAdapter.tsx +8 -21
- package/src/ExpoZoraIconFontProvider.web.test.tsx +32 -8
- package/src/ExpoZoraIconFontProvider.web.tsx +1 -5
- package/src/barcodeScanRuntime.ts +2 -67
- package/src/iconFonts.test.ts +12 -0
- package/src/index.ts +4 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ankhorage/expo-runtime
|
|
2
2
|
|
|
3
|
+
## 7.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3e25084: Keep icon-font provider children mounted while web fonts load so static Expo web exports hydrate safely.
|
|
8
|
+
|
|
9
|
+
## 7.0.0
|
|
10
|
+
|
|
11
|
+
### Major Changes
|
|
12
|
+
|
|
13
|
+
- a930f62: Align the barcode scanner adapter with ZORA 25 and forward scan callbacks directly to Expo Camera.
|
|
14
|
+
|
|
3
15
|
## 6.0.3
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
# EXPO-RUNTIME
|
|
5
5
|
|
|
6
|
-
         
|
|
7
7
|
|
|
8
8
|
Declarative runtime integration for Expo apps: maps app capabilities to permissions, packages, config plugins, providers, and adapters
|
|
9
9
|
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { type BarcodeScannerViewProps } from '@ankhorage/zora';
|
|
2
|
+
import { type CameraViewProps } from 'expo-camera';
|
|
2
3
|
import React from 'react';
|
|
3
|
-
export
|
|
4
|
+
export interface ExpoBarcodeScannerAdapterProps extends BarcodeScannerViewProps {
|
|
5
|
+
readonly onBarcodeScanned?: CameraViewProps['onBarcodeScanned'];
|
|
6
|
+
}
|
|
7
|
+
/*** Renders the ZORA scanner surface with Expo Camera and its native scan callback. */
|
|
8
|
+
export declare function ExpoBarcodeScannerAdapter(props: ExpoBarcodeScannerAdapterProps): React.JSX.Element;
|
|
4
9
|
//# sourceMappingURL=ExpoBarcodeScannerAdapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoBarcodeScannerAdapter.d.ts","sourceRoot":"","sources":["../src/ExpoBarcodeScannerAdapter.tsx"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"ExpoBarcodeScannerAdapter.d.ts","sourceRoot":"","sources":["../src/ExpoBarcodeScannerAdapter.tsx"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,EAAgC,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,KAAK,MAAM,OAAO,CAAC;AAU1B,MAAM,WAAW,8BAA+B,SAAQ,uBAAuB;IAC7E,QAAQ,CAAC,gBAAgB,CAAC,EAAE,eAAe,CAAC,kBAAkB,CAAC,CAAC;CACjE;AAED,uFAAuF;AACvF,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,8BAA8B,qBAqC9E"}
|
|
@@ -3,13 +3,13 @@ import { BarcodeScannerView } from '@ankhorage/zora';
|
|
|
3
3
|
import { CameraView } from 'expo-camera';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { StyleSheet } from 'react-native';
|
|
6
|
-
import { BARCODE_SCANNER_TYPES,
|
|
6
|
+
import { BARCODE_SCANNER_TYPES, mapPermissionStatusToCameraPermissionStatus, } from './barcodeScanRuntime';
|
|
7
7
|
const CAMERA_BARCODE_TYPES = [...BARCODE_SCANNER_TYPES];
|
|
8
|
+
/*** Renders the ZORA scanner surface with Expo Camera and its native scan callback. */
|
|
8
9
|
export function ExpoBarcodeScannerAdapter(props) {
|
|
9
10
|
const { onBarcodeScanned, onRequestPermission, ...viewProps } = props;
|
|
10
11
|
const cameraPermission = usePermission(Permission.Camera);
|
|
11
12
|
const [isRequestingPermission, setIsRequestingPermission] = React.useState(false);
|
|
12
|
-
const lastScanRef = React.useRef(null);
|
|
13
13
|
const permissionStatus = mapPermissionStatusToCameraPermissionStatus(cameraPermission.status, isRequestingPermission);
|
|
14
14
|
const handleRequestPermission = React.useCallback(async () => {
|
|
15
15
|
setIsRequestingPermission(true);
|
|
@@ -21,12 +21,7 @@ export function ExpoBarcodeScannerAdapter(props) {
|
|
|
21
21
|
setIsRequestingPermission(false);
|
|
22
22
|
}
|
|
23
23
|
}, [cameraPermission, onRequestPermission]);
|
|
24
|
-
const
|
|
25
|
-
void dispatchExpoBarcodeScan(result, lastScanRef.current, Date.now(), onBarcodeScanned, (record) => {
|
|
26
|
-
lastScanRef.current = record;
|
|
27
|
-
});
|
|
28
|
-
}, [onBarcodeScanned]);
|
|
29
|
-
const camera = permissionStatus === 'granted' ? (<CameraView barcodeScannerSettings={{ barcodeTypes: CAMERA_BARCODE_TYPES }} onBarcodeScanned={handleBarcodeScanned} style={styles.camera}/>) : undefined;
|
|
24
|
+
const camera = permissionStatus === 'granted' ? (<CameraView barcodeScannerSettings={{ barcodeTypes: CAMERA_BARCODE_TYPES }} onBarcodeScanned={onBarcodeScanned} style={styles.camera}/>) : undefined;
|
|
30
25
|
return (<BarcodeScannerView {...viewProps} camera={camera} onRequestPermission={handleRequestPermission} permissionStatus={permissionStatus}/>);
|
|
31
26
|
}
|
|
32
27
|
const styles = StyleSheet.create({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoBarcodeScannerAdapter.js","sourceRoot":"","sources":["../src/ExpoBarcodeScannerAdapter.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAgC,MAAM,iBAAiB,CAAC;AACnF,OAAO,
|
|
1
|
+
{"version":3,"file":"ExpoBarcodeScannerAdapter.js","sourceRoot":"","sources":["../src/ExpoBarcodeScannerAdapter.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAgC,MAAM,iBAAiB,CAAC;AACnF,OAAO,EAAoB,UAAU,EAAwB,MAAM,aAAa,CAAC;AACjF,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EACL,qBAAqB,EACrB,2CAA2C,GAC5C,MAAM,sBAAsB,CAAC;AAE9B,MAAM,oBAAoB,GAAkB,CAAC,GAAG,qBAAqB,CAAC,CAAC;AAMvE,uFAAuF;AACvF,MAAM,UAAU,yBAAyB,CAAC,KAAqC;IAC7E,MAAM,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAC;IACtE,MAAM,gBAAgB,GAAG,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAC1D,MAAM,CAAC,sBAAsB,EAAE,yBAAyB,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAElF,MAAM,gBAAgB,GAAG,2CAA2C,CAClE,gBAAgB,CAAC,MAAM,EACvB,sBAAsB,CACvB,CAAC;IAEF,MAAM,uBAAuB,GAAG,KAAK,CAAC,WAAW,CAAC,KAAK,IAAI,EAAE;QAC3D,yBAAyB,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,CAAC;YACH,MAAM,gBAAgB,CAAC,OAAO,EAAE,CAAC;YACjC,MAAM,mBAAmB,EAAE,EAAE,CAAC;QAChC,CAAC;gBAAS,CAAC;YACT,yBAAyB,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC;IACH,CAAC,EAAE,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAE5C,MAAM,MAAM,GACV,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,CAC/B,CAAC,UAAU,CACT,sBAAsB,CAAC,CAAC,EAAE,YAAY,EAAE,oBAAoB,EAAE,CAAC,CAC/D,gBAAgB,CAAC,CAAC,gBAAgB,CAAC,CACnC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EACrB,CACH,CAAC,CAAC,CAAC,SAAS,CAAC;IAEhB,OAAO,CACL,CAAC,kBAAkB,CACjB,IAAI,SAAS,CAAC,CACd,MAAM,CAAC,CAAC,MAAM,CAAC,CACf,mBAAmB,CAAC,CAAC,uBAAuB,CAAC,CAC7C,gBAAgB,CAAC,CAAC,gBAAgB,CAAC,EACnC,CACH,CAAC;AACJ,CAAC;AAED,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/B,MAAM,EAAE;QACN,IAAI,EAAE,CAAC;KACR;CACF,CAAC,CAAC","sourcesContent":["import { Permission, usePermission } from '@ankhorage/permissions';\nimport { BarcodeScannerView, type BarcodeScannerViewProps } from '@ankhorage/zora';\nimport { type BarcodeType, CameraView, type CameraViewProps } from 'expo-camera';\nimport React from 'react';\nimport { StyleSheet } from 'react-native';\n\nimport {\n BARCODE_SCANNER_TYPES,\n mapPermissionStatusToCameraPermissionStatus,\n} from './barcodeScanRuntime';\n\nconst CAMERA_BARCODE_TYPES: BarcodeType[] = [...BARCODE_SCANNER_TYPES];\n\nexport interface ExpoBarcodeScannerAdapterProps extends BarcodeScannerViewProps {\n readonly onBarcodeScanned?: CameraViewProps['onBarcodeScanned'];\n}\n\n/*** Renders the ZORA scanner surface with Expo Camera and its native scan callback. */\nexport function ExpoBarcodeScannerAdapter(props: ExpoBarcodeScannerAdapterProps) {\n const { onBarcodeScanned, onRequestPermission, ...viewProps } = props;\n const cameraPermission = usePermission(Permission.Camera);\n const [isRequestingPermission, setIsRequestingPermission] = React.useState(false);\n\n const permissionStatus = mapPermissionStatusToCameraPermissionStatus(\n cameraPermission.status,\n isRequestingPermission,\n );\n\n const handleRequestPermission = React.useCallback(async () => {\n setIsRequestingPermission(true);\n try {\n await cameraPermission.request();\n await onRequestPermission?.();\n } finally {\n setIsRequestingPermission(false);\n }\n }, [cameraPermission, onRequestPermission]);\n\n const camera =\n permissionStatus === 'granted' ? (\n <CameraView\n barcodeScannerSettings={{ barcodeTypes: CAMERA_BARCODE_TYPES }}\n onBarcodeScanned={onBarcodeScanned}\n style={styles.camera}\n />\n ) : undefined;\n\n return (\n <BarcodeScannerView\n {...viewProps}\n camera={camera}\n onRequestPermission={handleRequestPermission}\n permissionStatus={permissionStatus}\n />\n );\n}\n\nconst styles = StyleSheet.create({\n camera: {\n flex: 1,\n },\n});\n"]}
|
|
@@ -2,5 +2,5 @@ import React from 'react';
|
|
|
2
2
|
export interface ExpoZoraIconFontProviderProps {
|
|
3
3
|
readonly children: React.ReactNode;
|
|
4
4
|
}
|
|
5
|
-
export declare function ExpoZoraIconFontProvider(props: ExpoZoraIconFontProviderProps): React.JSX.Element
|
|
5
|
+
export declare function ExpoZoraIconFontProvider(props: ExpoZoraIconFontProviderProps): React.JSX.Element;
|
|
6
6
|
//# sourceMappingURL=ExpoZoraIconFontProvider.web.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoZoraIconFontProvider.web.d.ts","sourceRoot":"","sources":["../src/ExpoZoraIconFontProvider.web.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,MAAM,OAAO,CAAC;AAc1B,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CACpC;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,6BAA6B,
|
|
1
|
+
{"version":3,"file":"ExpoZoraIconFontProvider.web.d.ts","sourceRoot":"","sources":["../src/ExpoZoraIconFontProvider.web.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,MAAM,OAAO,CAAC;AAc1B,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CACpC;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,6BAA6B,qBAQ5E"}
|
|
@@ -21,13 +21,10 @@ const ZORA_ICON_FONTS = {
|
|
|
21
21
|
MaterialDesignIcons: materialDesignIcons,
|
|
22
22
|
};
|
|
23
23
|
export function ExpoZoraIconFontProvider(props) {
|
|
24
|
-
const [
|
|
24
|
+
const [, error] = useFonts(ZORA_ICON_FONTS);
|
|
25
25
|
if (error) {
|
|
26
26
|
throw error;
|
|
27
27
|
}
|
|
28
|
-
if (!loaded) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
28
|
return <>{props.children}</>;
|
|
32
29
|
}
|
|
33
30
|
//# sourceMappingURL=ExpoZoraIconFontProvider.web.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoZoraIconFontProvider.web.js","sourceRoot":"","sources":["../src/ExpoZoraIconFontProvider.web.tsx"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,8DAA8D,CAAC;AACvF,OAAO,kBAAkB,MAAM,uEAAuE,CAAC;AACvG,OAAO,mBAAmB,MAAM,wEAAwE,CAAC;AACzG,OAAO,iBAAiB,MAAM,sEAAsE,CAAC;AACrG,OAAO,kBAAkB,MAAM,uEAAuE,CAAC;AACvG,OAAO,mBAAmB,MAAM,wEAAwE,CAAC;AACzG,OAAO,iBAAiB,MAAM,sEAAsE,CAAC;AACrG,OAAO,QAAQ,MAAM,wDAAwD,CAAC;AAC9E,OAAO,mBAAmB,MAAM,gFAAgF,CAAC;AACjH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,eAAe,GAAG;IACtB,WAAW,EAAE,WAAW;IACxB,4BAA4B,EAAE,kBAAkB;IAChD,0BAA0B,EAAE,mBAAmB;IAC/C,wBAAwB,EAAE,iBAAiB;IAC3C,4BAA4B,EAAE,kBAAkB;IAChD,0BAA0B,EAAE,mBAAmB;IAC/C,wBAAwB,EAAE,iBAAiB;IAC3C,QAAQ,EAAE,QAAQ;IAClB,mBAAmB,EAAE,mBAAmB;CAChC,CAAC;AAMX,MAAM,UAAU,wBAAwB,CAAC,KAAoC;IAC3E,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"ExpoZoraIconFontProvider.web.js","sourceRoot":"","sources":["../src/ExpoZoraIconFontProvider.web.tsx"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,8DAA8D,CAAC;AACvF,OAAO,kBAAkB,MAAM,uEAAuE,CAAC;AACvG,OAAO,mBAAmB,MAAM,wEAAwE,CAAC;AACzG,OAAO,iBAAiB,MAAM,sEAAsE,CAAC;AACrG,OAAO,kBAAkB,MAAM,uEAAuE,CAAC;AACvG,OAAO,mBAAmB,MAAM,wEAAwE,CAAC;AACzG,OAAO,iBAAiB,MAAM,sEAAsE,CAAC;AACrG,OAAO,QAAQ,MAAM,wDAAwD,CAAC;AAC9E,OAAO,mBAAmB,MAAM,gFAAgF,CAAC;AACjH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,eAAe,GAAG;IACtB,WAAW,EAAE,WAAW;IACxB,4BAA4B,EAAE,kBAAkB;IAChD,0BAA0B,EAAE,mBAAmB;IAC/C,wBAAwB,EAAE,iBAAiB;IAC3C,4BAA4B,EAAE,kBAAkB;IAChD,0BAA0B,EAAE,mBAAmB;IAC/C,wBAAwB,EAAE,iBAAiB;IAC3C,QAAQ,EAAE,QAAQ;IAClB,mBAAmB,EAAE,mBAAmB;CAChC,CAAC;AAMX,MAAM,UAAU,wBAAwB,CAAC,KAAoC;IAC3E,MAAM,CAAC,EAAE,KAAK,CAAC,GAAG,QAAQ,CAAC,eAAe,CAAC,CAAC;IAE5C,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,KAAK,CAAC;IACd,CAAC;IAED,OAAO,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;AAC/B,CAAC","sourcesContent":["import fontAwesome from '@react-native-vector-icons/fontawesome/fonts/FontAwesome.ttf';\nimport fontAwesome5Brands from '@react-native-vector-icons/fontawesome5/fonts/FontAwesome5_Brands.ttf';\nimport fontAwesome5Regular from '@react-native-vector-icons/fontawesome5/fonts/FontAwesome5_Regular.ttf';\nimport fontAwesome5Solid from '@react-native-vector-icons/fontawesome5/fonts/FontAwesome5_Solid.ttf';\nimport fontAwesome6Brands from '@react-native-vector-icons/fontawesome6/fonts/FontAwesome6_Brands.ttf';\nimport fontAwesome6Regular from '@react-native-vector-icons/fontawesome6/fonts/FontAwesome6_Regular.ttf';\nimport fontAwesome6Solid from '@react-native-vector-icons/fontawesome6/fonts/FontAwesome6_Solid.ttf';\nimport ionicons from '@react-native-vector-icons/ionicons/fonts/Ionicons.ttf';\nimport materialDesignIcons from '@react-native-vector-icons/material-design-icons/fonts/MaterialDesignIcons.ttf';\nimport { useFonts } from 'expo-font';\nimport React from 'react';\n\nconst ZORA_ICON_FONTS = {\n FontAwesome: fontAwesome,\n 'FontAwesome5Brands-Regular': fontAwesome5Brands,\n 'FontAwesome5Free-Regular': fontAwesome5Regular,\n 'FontAwesome5Free-Solid': fontAwesome5Solid,\n 'FontAwesome6Brands-Regular': fontAwesome6Brands,\n 'FontAwesome6Free-Regular': fontAwesome6Regular,\n 'FontAwesome6Free-Solid': fontAwesome6Solid,\n Ionicons: ionicons,\n MaterialDesignIcons: materialDesignIcons,\n} as const;\n\nexport interface ExpoZoraIconFontProviderProps {\n readonly children: React.ReactNode;\n}\n\nexport function ExpoZoraIconFontProvider(props: ExpoZoraIconFontProviderProps) {\n const [, error] = useFonts(ZORA_ICON_FONTS);\n\n if (error) {\n throw error;\n }\n\n return <>{props.children}</>;\n}\n"]}
|
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
import type { PermissionStatus } from '@ankhorage/permissions';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const BARCODE_SCAN_DEDUPE_WINDOW_MS = 1500;
|
|
2
|
+
import type { CameraPermissionStatus } from '@ankhorage/zora';
|
|
4
3
|
export declare const BARCODE_SCANNER_TYPES: readonly ["aztec", "codabar", "code39", "code93", "code128", "datamatrix", "ean13", "ean8", "itf14", "pdf417", "qr", "upc_a", "upc_e"];
|
|
5
|
-
|
|
6
|
-
readonly timestamp: number;
|
|
7
|
-
}
|
|
8
|
-
export interface ExpoBarcodeScanResultLike {
|
|
9
|
-
readonly data: string;
|
|
10
|
-
readonly type?: string;
|
|
11
|
-
}
|
|
12
|
-
type ExpoBarcodeScanCallback = (result: BarcodeScanResult) => Promise<void> | void;
|
|
4
|
+
/*** Maps the Permissions owner status to ZORA's documented camera UI status. */
|
|
13
5
|
export declare function mapPermissionStatusToCameraPermissionStatus(status: PermissionStatus, isRequestingPermission: boolean): CameraPermissionStatus;
|
|
14
|
-
export declare function normalizeExpoBarcodeScanResult(result: ExpoBarcodeScanResultLike): BarcodeScanResult | null;
|
|
15
|
-
export declare function shouldIgnoreBarcodeScan(previous: BarcodeScanRecord | null, next: BarcodeScanResult, now: number): boolean;
|
|
16
|
-
export declare function dispatchExpoBarcodeScan(result: ExpoBarcodeScanResultLike, previous: BarcodeScanRecord | null, now: number, onBarcodeScanned: ExpoBarcodeScanCallback | undefined, onAccepted: (record: BarcodeScanRecord) => void): Promise<boolean>;
|
|
17
|
-
export {};
|
|
18
6
|
//# sourceMappingURL=barcodeScanRuntime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"barcodeScanRuntime.d.ts","sourceRoot":"","sources":["../src/barcodeScanRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"barcodeScanRuntime.d.ts","sourceRoot":"","sources":["../src/barcodeScanRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAG9D,eAAO,MAAM,qBAAqB,wIAcS,CAAC;AAE5C,gFAAgF;AAChF,wBAAgB,2CAA2C,CACzD,MAAM,EAAE,gBAAgB,EACxB,sBAAsB,EAAE,OAAO,GAC9B,sBAAsB,CAaxB"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export const BARCODE_SCAN_DEDUPE_WINDOW_MS = 1500;
|
|
2
1
|
export const BARCODE_SCANNER_TYPES = [
|
|
3
2
|
'aztec',
|
|
4
3
|
'codabar',
|
|
@@ -14,6 +13,7 @@ export const BARCODE_SCANNER_TYPES = [
|
|
|
14
13
|
'upc_a',
|
|
15
14
|
'upc_e',
|
|
16
15
|
];
|
|
16
|
+
/*** Maps the Permissions owner status to ZORA's documented camera UI status. */
|
|
17
17
|
export function mapPermissionStatusToCameraPermissionStatus(status, isRequestingPermission) {
|
|
18
18
|
if (isRequestingPermission) {
|
|
19
19
|
return 'requesting';
|
|
@@ -27,36 +27,4 @@ export function mapPermissionStatusToCameraPermissionStatus(status, isRequesting
|
|
|
27
27
|
return 'denied';
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
export function normalizeExpoBarcodeScanResult(result) {
|
|
31
|
-
const value = result.data.trim();
|
|
32
|
-
if (value.length === 0) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
const type = typeof result.type === 'string' && result.type.length > 0 ? result.type : undefined;
|
|
36
|
-
return {
|
|
37
|
-
value,
|
|
38
|
-
type,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
export function shouldIgnoreBarcodeScan(previous, next, now) {
|
|
42
|
-
if (previous === null) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
return (previous.value === next.value &&
|
|
46
|
-
previous.type === next.type &&
|
|
47
|
-
now - previous.timestamp < BARCODE_SCAN_DEDUPE_WINDOW_MS);
|
|
48
|
-
}
|
|
49
|
-
export async function dispatchExpoBarcodeScan(result, previous, now, onBarcodeScanned, onAccepted) {
|
|
50
|
-
const normalizedResult = normalizeExpoBarcodeScanResult(result);
|
|
51
|
-
if (normalizedResult === null || shouldIgnoreBarcodeScan(previous, normalizedResult, now)) {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
const record = {
|
|
55
|
-
...normalizedResult,
|
|
56
|
-
timestamp: now,
|
|
57
|
-
};
|
|
58
|
-
onAccepted(record);
|
|
59
|
-
await onBarcodeScanned?.(normalizedResult);
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
30
|
//# sourceMappingURL=barcodeScanRuntime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"barcodeScanRuntime.js","sourceRoot":"","sources":["../src/barcodeScanRuntime.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"barcodeScanRuntime.js","sourceRoot":"","sources":["../src/barcodeScanRuntime.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,OAAO;IACP,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,YAAY;IACZ,OAAO;IACP,MAAM;IACN,OAAO;IACP,QAAQ;IACR,IAAI;IACJ,OAAO;IACP,OAAO;CACkC,CAAC;AAE5C,gFAAgF;AAChF,MAAM,UAAU,2CAA2C,CACzD,MAAwB,EACxB,sBAA+B;IAE/B,IAAI,sBAAsB,EAAE,CAAC;QAC3B,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC;QACnB,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC;QACnB;YACE,OAAO,QAAQ,CAAC;IACpB,CAAC;AACH,CAAC","sourcesContent":["import type { PermissionStatus } from '@ankhorage/permissions';\nimport type { CameraPermissionStatus } from '@ankhorage/zora';\nimport type { BarcodeType } from 'expo-camera';\n\nexport const BARCODE_SCANNER_TYPES = [\n 'aztec',\n 'codabar',\n 'code39',\n 'code93',\n 'code128',\n 'datamatrix',\n 'ean13',\n 'ean8',\n 'itf14',\n 'pdf417',\n 'qr',\n 'upc_a',\n 'upc_e',\n] as const satisfies readonly BarcodeType[];\n\n/*** Maps the Permissions owner status to ZORA's documented camera UI status. */\nexport function mapPermissionStatusToCameraPermissionStatus(\n status: PermissionStatus,\n isRequestingPermission: boolean,\n): CameraPermissionStatus {\n if (isRequestingPermission) {\n return 'requesting';\n }\n\n switch (status) {\n case 'granted':\n return 'granted';\n case 'unknown':\n return 'unknown';\n default:\n return 'denied';\n }\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { BARCODE_SCANNER_TYPES, mapPermissionStatusToCameraPermissionStatus, } from './barcodeScanRuntime';
|
|
2
2
|
export { type ExpoBundledMediaRegistrySourceEntry, getExpoBundledMediaRegistrySource, } from './bundledMediaRegistrySource';
|
|
3
3
|
export { createExpoBundledMediaResolver, type ExpoBundledMediaRegistry, type ExpoBundledMediaResolver, type ExpoBundledMediaResolverArgs, type ExpoBundledMediaValue, resolveExpoBundledMediaAsset, } from './bundledMediaResolver';
|
|
4
4
|
export { type ExecuteExpoRuntimeCapabilityArgs, executeExpoRuntimeCapabilityAsync, type ExpoRuntimeCapabilityDiagnostic, type ExpoRuntimeCapabilityDiagnosticCode, type ExpoRuntimeCapabilityExecutionResult, type ExpoRuntimeCapabilityHandler, type ExpoRuntimeCapabilityHandlerArgs, type ExpoRuntimeRouteResolution, resolveExpoRuntimeRoutePath, } from './capabilityBridge';
|
|
5
5
|
export type { ComponentRegistry } from './componentRegistry';
|
|
6
6
|
export { createComponentRegistry } from './componentRegistry';
|
|
7
7
|
export { createExpoRuntimeRegistry } from './createExpoRuntimeRegistry';
|
|
8
|
-
export { ExpoBarcodeScannerAdapter } from './ExpoBarcodeScannerAdapter';
|
|
8
|
+
export { ExpoBarcodeScannerAdapter, type ExpoBarcodeScannerAdapterProps, } from './ExpoBarcodeScannerAdapter';
|
|
9
9
|
export { ExpoRuntimeProviders, type ExpoRuntimeProvidersProps } from './ExpoRuntimeProviders';
|
|
10
10
|
export { ExpoZoraIconFontProvider, type ExpoZoraIconFontProviderProps, } from './ExpoZoraIconFontProvider';
|
|
11
11
|
export { type ExpoRuntimeConfigPluginOutput, type ExpoRuntimeDependencyMap, type ExpoRuntimeGeneratedAppOutputPlan, type ExpoRuntimeNativeOutputPlan, resolveExpoRuntimeConfigPluginOutput, resolveExpoRuntimeDependencyMap, resolveExpoRuntimeGeneratedAppOutput, resolveExpoRuntimeNativeOutput, } from './generatedAppOutput';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,2CAA2C,GAC5C,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,KAAK,mCAAmC,EACxC,iCAAiC,GAClC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,8BAA8B,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC7B,KAAK,4BAA4B,EACjC,KAAK,qBAAqB,EAC1B,4BAA4B,GAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,KAAK,gCAAgC,EACrC,iCAAiC,EACjC,KAAK,+BAA+B,EACpC,KAAK,mCAAmC,EACxC,KAAK,oCAAoC,EACzC,KAAK,4BAA4B,EACjC,KAAK,gCAAgC,EACrC,KAAK,0BAA0B,EAC/B,2BAA2B,GAC5B,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EACL,yBAAyB,EACzB,KAAK,8BAA8B,GACpC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,oBAAoB,EAAE,KAAK,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAC9F,OAAO,EACL,wBAAwB,EACxB,KAAK,6BAA6B,GACnC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,KAAK,6BAA6B,EAClC,KAAK,wBAAwB,EAC7B,KAAK,iCAAiC,EACtC,KAAK,2BAA2B,EAChC,oCAAoC,EACpC,+BAA+B,EAC/B,oCAAoC,EACpC,8BAA8B,GAC/B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EACL,KAAK,gCAAgC,EACrC,mCAAmC,GACpC,MAAM,6BAA6B,CAAC;AACrC,YAAY,EACV,oBAAoB,EACpB,eAAe,EACf,qBAAqB,GACtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { BARCODE_SCANNER_TYPES, mapPermissionStatusToCameraPermissionStatus, } from './barcodeScanRuntime';
|
|
2
2
|
export { getExpoBundledMediaRegistrySource, } from './bundledMediaRegistrySource';
|
|
3
3
|
export { createExpoBundledMediaResolver, resolveExpoBundledMediaAsset, } from './bundledMediaResolver';
|
|
4
4
|
export { executeExpoRuntimeCapabilityAsync, resolveExpoRuntimeRoutePath, } from './capabilityBridge';
|
|
5
5
|
export { createComponentRegistry } from './componentRegistry';
|
|
6
6
|
export { createExpoRuntimeRegistry } from './createExpoRuntimeRegistry';
|
|
7
|
-
export { ExpoBarcodeScannerAdapter } from './ExpoBarcodeScannerAdapter';
|
|
7
|
+
export { ExpoBarcodeScannerAdapter, } from './ExpoBarcodeScannerAdapter';
|
|
8
8
|
export { ExpoRuntimeProviders } from './ExpoRuntimeProviders';
|
|
9
9
|
export { ExpoZoraIconFontProvider, } from './ExpoZoraIconFontProvider';
|
|
10
10
|
export { resolveExpoRuntimeConfigPluginOutput, resolveExpoRuntimeDependencyMap, resolveExpoRuntimeGeneratedAppOutput, resolveExpoRuntimeNativeOutput, } from './generatedAppOutput';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,2CAA2C,GAC5C,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAEL,iCAAiC,GAClC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,8BAA8B,EAK9B,4BAA4B,GAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEL,iCAAiC,EAOjC,2BAA2B,GAC5B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EACL,yBAAyB,GAE1B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,oBAAoB,EAAkC,MAAM,wBAAwB,CAAC;AAC9F,OAAO,EACL,wBAAwB,GAEzB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAKL,oCAAoC,EACpC,+BAA+B,EAC/B,oCAAoC,EACpC,8BAA8B,GAC/B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAEL,mCAAmC,GACpC,MAAM,6BAA6B,CAAC;AAMrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["export {\n BARCODE_SCANNER_TYPES,\n mapPermissionStatusToCameraPermissionStatus,\n} from './barcodeScanRuntime';\nexport {\n type ExpoBundledMediaRegistrySourceEntry,\n getExpoBundledMediaRegistrySource,\n} from './bundledMediaRegistrySource';\nexport {\n createExpoBundledMediaResolver,\n type ExpoBundledMediaRegistry,\n type ExpoBundledMediaResolver,\n type ExpoBundledMediaResolverArgs,\n type ExpoBundledMediaValue,\n resolveExpoBundledMediaAsset,\n} from './bundledMediaResolver';\nexport {\n type ExecuteExpoRuntimeCapabilityArgs,\n executeExpoRuntimeCapabilityAsync,\n type ExpoRuntimeCapabilityDiagnostic,\n type ExpoRuntimeCapabilityDiagnosticCode,\n type ExpoRuntimeCapabilityExecutionResult,\n type ExpoRuntimeCapabilityHandler,\n type ExpoRuntimeCapabilityHandlerArgs,\n type ExpoRuntimeRouteResolution,\n resolveExpoRuntimeRoutePath,\n} from './capabilityBridge';\nexport type { ComponentRegistry } from './componentRegistry';\nexport { createComponentRegistry } from './componentRegistry';\nexport { createExpoRuntimeRegistry } from './createExpoRuntimeRegistry';\nexport {\n ExpoBarcodeScannerAdapter,\n type ExpoBarcodeScannerAdapterProps,\n} from './ExpoBarcodeScannerAdapter';\nexport { ExpoRuntimeProviders, type ExpoRuntimeProvidersProps } from './ExpoRuntimeProviders';\nexport {\n ExpoZoraIconFontProvider,\n type ExpoZoraIconFontProviderProps,\n} from './ExpoZoraIconFontProvider';\nexport {\n type ExpoRuntimeConfigPluginOutput,\n type ExpoRuntimeDependencyMap,\n type ExpoRuntimeGeneratedAppOutputPlan,\n type ExpoRuntimeNativeOutputPlan,\n resolveExpoRuntimeConfigPluginOutput,\n resolveExpoRuntimeDependencyMap,\n resolveExpoRuntimeGeneratedAppOutput,\n resolveExpoRuntimeNativeOutput,\n} from './generatedAppOutput';\nexport { getExpoBarcodeScannerViewSource } from './generatedSources';\nexport {\n type ExpoRuntimeLayoutIntegrationPlan,\n resolveExpoRuntimeLayoutIntegration,\n} from './layoutIntegrationPlanning';\nexport type {\n ExpoRuntimeAdapterId,\n ExpoRuntimePlan,\n ExpoRuntimeProviderId,\n} from './resolveExpoRuntimePlan';\nexport { resolveExpoRuntimePlan } from './resolveExpoRuntimePlan';\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ankhorage/expo-runtime",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "7.0.1",
|
|
5
5
|
"description": "Declarative runtime integration for Expo apps: maps app capabilities to permissions, packages, config plugins, providers, and adapters",
|
|
6
6
|
"homepage": "https://github.com/ankhorage/expo-runtime#readme",
|
|
7
7
|
"bugs": {
|
|
@@ -177,13 +177,14 @@
|
|
|
177
177
|
"validate:action-bridge": "bun scripts/actionBridgeAcceptance.ts",
|
|
178
178
|
"validate:expo-platform": "bun scripts/validateExpoPlatform.ts",
|
|
179
179
|
"validate:headless-platform": "bun scripts/headlessPlatformAcceptance.ts",
|
|
180
|
-
"validate:
|
|
180
|
+
"validate:icon-fonts-web": "bun scripts/iconFontWebAcceptance.ts",
|
|
181
|
+
"validate:packed-runtime": "bun scripts/packedRuntimeAcceptance.ts && bun scripts/iconFontWebAcceptance.ts",
|
|
181
182
|
"validate:web-barcode": "bun scripts/webBarcodeAcceptance.ts",
|
|
182
183
|
"version-packages": "ankhorage-changeset version"
|
|
183
184
|
},
|
|
184
185
|
"peerDependencies": {
|
|
185
186
|
"@ankhorage/permissions": "^0.2.63",
|
|
186
|
-
"@ankhorage/zora": "^
|
|
187
|
+
"@ankhorage/zora": "^25.8.3",
|
|
187
188
|
"@react-native-vector-icons/fontawesome": "^13.1.4",
|
|
188
189
|
"@react-native-vector-icons/fontawesome5": "^13.1.4",
|
|
189
190
|
"@react-native-vector-icons/fontawesome6": "^13.1.4",
|
|
@@ -253,7 +254,7 @@
|
|
|
253
254
|
"@ankhorage/devtools": "^2.3.18",
|
|
254
255
|
"@ankhorage/paradox": "^0.2.27",
|
|
255
256
|
"@ankhorage/permissions": "^0.2.63",
|
|
256
|
-
"@ankhorage/zora": "^
|
|
257
|
+
"@ankhorage/zora": "^25.8.3",
|
|
257
258
|
"@react-native-vector-icons/fontawesome": "^13.1.4",
|
|
258
259
|
"@react-native-vector-icons/fontawesome5": "^13.1.4",
|
|
259
260
|
"@react-native-vector-icons/fontawesome6": "^13.1.4",
|
|
@@ -1,71 +1,25 @@
|
|
|
1
1
|
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import type { CameraViewProps } from 'expo-camera';
|
|
2
3
|
|
|
3
4
|
import {
|
|
4
|
-
BARCODE_SCAN_DEDUPE_WINDOW_MS,
|
|
5
5
|
BARCODE_SCANNER_TYPES,
|
|
6
|
-
dispatchExpoBarcodeScan,
|
|
7
6
|
mapPermissionStatusToCameraPermissionStatus,
|
|
8
|
-
normalizeExpoBarcodeScanResult,
|
|
9
|
-
shouldIgnoreBarcodeScan,
|
|
10
7
|
} from './barcodeScanRuntime';
|
|
8
|
+
import type { ExpoBarcodeScannerAdapterProps } from './ExpoBarcodeScannerAdapter';
|
|
11
9
|
|
|
12
|
-
describe('Expo barcode
|
|
13
|
-
it('
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('drops empty scan payloads', () => {
|
|
26
|
-
expect(
|
|
27
|
-
normalizeExpoBarcodeScanResult({
|
|
28
|
-
data: ' ',
|
|
29
|
-
type: 'qr',
|
|
30
|
-
}),
|
|
31
|
-
).toBeNull();
|
|
10
|
+
describe('Expo barcode adapter configuration', () => {
|
|
11
|
+
it('uses the Expo Camera callback and payload contract at the adapter boundary', () => {
|
|
12
|
+
const callback: NonNullable<CameraViewProps['onBarcodeScanned']> = (result) => {
|
|
13
|
+
expect(result).toEqual({ data: '4006381333931', type: 'ean13' });
|
|
14
|
+
};
|
|
15
|
+
const props: ExpoBarcodeScannerAdapterProps = {
|
|
16
|
+
onBarcodeScanned: callback,
|
|
17
|
+
permissionStatus: 'granted',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
expect(props.onBarcodeScanned).toBe(callback);
|
|
32
21
|
});
|
|
33
|
-
});
|
|
34
22
|
|
|
35
|
-
describe('Expo barcode event deduplication', () => {
|
|
36
|
-
it('suppresses repeated scans inside the dedupe window', () => {
|
|
37
|
-
expect(
|
|
38
|
-
shouldIgnoreBarcodeScan(
|
|
39
|
-
{
|
|
40
|
-
value: '0123456789',
|
|
41
|
-
type: 'ean13',
|
|
42
|
-
timestamp: 1_000,
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
value: '0123456789',
|
|
46
|
-
type: 'ean13',
|
|
47
|
-
},
|
|
48
|
-
1_000 + BARCODE_SCAN_DEDUPE_WINDOW_MS - 1,
|
|
49
|
-
),
|
|
50
|
-
).toBe(true);
|
|
51
|
-
expect(
|
|
52
|
-
shouldIgnoreBarcodeScan(
|
|
53
|
-
{
|
|
54
|
-
value: '0123456789',
|
|
55
|
-
type: 'ean13',
|
|
56
|
-
timestamp: 1_000,
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
value: '0123456789',
|
|
60
|
-
type: 'ean13',
|
|
61
|
-
},
|
|
62
|
-
1_000 + BARCODE_SCAN_DEDUPE_WINDOW_MS,
|
|
63
|
-
),
|
|
64
|
-
).toBe(false);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
describe('Expo barcode adapter configuration', () => {
|
|
69
23
|
it('maps permission states into the ZORA camera permission surface', () => {
|
|
70
24
|
expect(mapPermissionStatusToCameraPermissionStatus('unknown', false)).toBe('unknown');
|
|
71
25
|
expect(mapPermissionStatusToCameraPermissionStatus('granted', false)).toBe('granted');
|
|
@@ -90,29 +44,4 @@ describe('Expo barcode adapter configuration', () => {
|
|
|
90
44
|
'upc_e',
|
|
91
45
|
]);
|
|
92
46
|
});
|
|
93
|
-
|
|
94
|
-
it.each([
|
|
95
|
-
['qr', 'https://ankhorage.dev'],
|
|
96
|
-
['ean13', '4006381333931'],
|
|
97
|
-
['ean8', '96385074'],
|
|
98
|
-
])('normalizes and forwards an accepted %s event', async (type, data) => {
|
|
99
|
-
const forwarded: { value: string; type?: string }[] = [];
|
|
100
|
-
let acceptedRecord: { value: string; type?: string; timestamp: number } | undefined;
|
|
101
|
-
|
|
102
|
-
expect(
|
|
103
|
-
await dispatchExpoBarcodeScan(
|
|
104
|
-
{ data, type },
|
|
105
|
-
null,
|
|
106
|
-
1_000,
|
|
107
|
-
(result) => {
|
|
108
|
-
forwarded.push(result);
|
|
109
|
-
},
|
|
110
|
-
(record) => {
|
|
111
|
-
acceptedRecord = record;
|
|
112
|
-
},
|
|
113
|
-
),
|
|
114
|
-
).toBe(true);
|
|
115
|
-
expect(forwarded).toEqual([{ value: data, type }]);
|
|
116
|
-
expect(acceptedRecord).toEqual({ value: data, type, timestamp: 1_000 });
|
|
117
|
-
});
|
|
118
47
|
});
|
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
import { Permission, usePermission } from '@ankhorage/permissions';
|
|
2
2
|
import { BarcodeScannerView, type BarcodeScannerViewProps } from '@ankhorage/zora';
|
|
3
|
-
import { type
|
|
3
|
+
import { type BarcodeType, CameraView, type CameraViewProps } from 'expo-camera';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { StyleSheet } from 'react-native';
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
BARCODE_SCANNER_TYPES,
|
|
9
|
-
type BarcodeScanRecord,
|
|
10
|
-
dispatchExpoBarcodeScan,
|
|
11
9
|
mapPermissionStatusToCameraPermissionStatus,
|
|
12
10
|
} from './barcodeScanRuntime';
|
|
13
11
|
|
|
14
12
|
const CAMERA_BARCODE_TYPES: BarcodeType[] = [...BARCODE_SCANNER_TYPES];
|
|
15
13
|
|
|
16
|
-
export
|
|
14
|
+
export interface ExpoBarcodeScannerAdapterProps extends BarcodeScannerViewProps {
|
|
15
|
+
readonly onBarcodeScanned?: CameraViewProps['onBarcodeScanned'];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/*** Renders the ZORA scanner surface with Expo Camera and its native scan callback. */
|
|
19
|
+
export function ExpoBarcodeScannerAdapter(props: ExpoBarcodeScannerAdapterProps) {
|
|
17
20
|
const { onBarcodeScanned, onRequestPermission, ...viewProps } = props;
|
|
18
21
|
const cameraPermission = usePermission(Permission.Camera);
|
|
19
22
|
const [isRequestingPermission, setIsRequestingPermission] = React.useState(false);
|
|
20
|
-
const lastScanRef = React.useRef<BarcodeScanRecord | null>(null);
|
|
21
23
|
|
|
22
24
|
const permissionStatus = mapPermissionStatusToCameraPermissionStatus(
|
|
23
25
|
cameraPermission.status,
|
|
@@ -34,26 +36,11 @@ export function ExpoBarcodeScannerAdapter(props: BarcodeScannerViewProps) {
|
|
|
34
36
|
}
|
|
35
37
|
}, [cameraPermission, onRequestPermission]);
|
|
36
38
|
|
|
37
|
-
const handleBarcodeScanned = React.useCallback(
|
|
38
|
-
(result: BarcodeScanningResult) => {
|
|
39
|
-
void dispatchExpoBarcodeScan(
|
|
40
|
-
result,
|
|
41
|
-
lastScanRef.current,
|
|
42
|
-
Date.now(),
|
|
43
|
-
onBarcodeScanned,
|
|
44
|
-
(record) => {
|
|
45
|
-
lastScanRef.current = record;
|
|
46
|
-
},
|
|
47
|
-
);
|
|
48
|
-
},
|
|
49
|
-
[onBarcodeScanned],
|
|
50
|
-
);
|
|
51
|
-
|
|
52
39
|
const camera =
|
|
53
40
|
permissionStatus === 'granted' ? (
|
|
54
41
|
<CameraView
|
|
55
42
|
barcodeScannerSettings={{ barcodeTypes: CAMERA_BARCODE_TYPES }}
|
|
56
|
-
onBarcodeScanned={
|
|
43
|
+
onBarcodeScanned={onBarcodeScanned}
|
|
57
44
|
style={styles.camera}
|
|
58
45
|
/>
|
|
59
46
|
) : undefined;
|
|
@@ -9,6 +9,22 @@ void mock.module('expo-font', () => ({ useFonts }));
|
|
|
9
9
|
|
|
10
10
|
const { ExpoZoraIconFontProvider } = await import('./ExpoZoraIconFontProvider.web');
|
|
11
11
|
|
|
12
|
+
function assertProviderChildren(child: React.ReactNode): void {
|
|
13
|
+
const element = ExpoZoraIconFontProvider({ children: child });
|
|
14
|
+
|
|
15
|
+
expect(React.isValidElement(element)).toBe(true);
|
|
16
|
+
if (!React.isValidElement(element)) {
|
|
17
|
+
throw new Error('expected a React element');
|
|
18
|
+
}
|
|
19
|
+
expect(element.props.children).toBe(child);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function renderProviderStructure(): React.ReactNode {
|
|
23
|
+
return ExpoZoraIconFontProvider({
|
|
24
|
+
children: React.createElement('main', { 'data-testid': 'icon-font-consumer' }, 'Ready'),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
12
28
|
describe('ExpoZoraIconFontProvider Web', () => {
|
|
13
29
|
afterAll(() => {
|
|
14
30
|
mock.restore();
|
|
@@ -16,7 +32,7 @@ describe('ExpoZoraIconFontProvider Web', () => {
|
|
|
16
32
|
|
|
17
33
|
test('loads every font face used by the ZORA icon providers before rendering', () => {
|
|
18
34
|
const child = React.createElement('child');
|
|
19
|
-
|
|
35
|
+
assertProviderChildren(child);
|
|
20
36
|
|
|
21
37
|
expect(useFonts).toHaveBeenCalledTimes(1);
|
|
22
38
|
const fonts = useFonts.mock.calls[0]?.[0] ?? {};
|
|
@@ -33,17 +49,25 @@ describe('ExpoZoraIconFontProvider Web', () => {
|
|
|
33
49
|
['Ionicons', 'Ionicons.ttf'],
|
|
34
50
|
['MaterialDesignIcons', 'MaterialDesignIcons.ttf'],
|
|
35
51
|
]);
|
|
36
|
-
expect(React.isValidElement(element)).toBe(true);
|
|
37
|
-
if (!React.isValidElement(element)) {
|
|
38
|
-
throw new Error('expected a React element');
|
|
39
|
-
}
|
|
40
|
-
expect(element.props.children).toBe(child);
|
|
41
52
|
});
|
|
42
53
|
|
|
43
|
-
test('
|
|
54
|
+
test('keeps children mounted while fonts are loading', () => {
|
|
55
|
+
useFonts.mockImplementationOnce(() => [false, null]);
|
|
56
|
+
|
|
57
|
+
const child = React.createElement('child');
|
|
58
|
+
assertProviderChildren(child);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('keeps the server, initial client, and loaded render structures equal', () => {
|
|
62
|
+
useFonts.mockImplementationOnce(() => [false, null]);
|
|
63
|
+
const serverStructure = renderProviderStructure();
|
|
44
64
|
useFonts.mockImplementationOnce(() => [false, null]);
|
|
65
|
+
const initialClientStructure = renderProviderStructure();
|
|
66
|
+
useFonts.mockImplementationOnce(() => [true, null]);
|
|
67
|
+
const loadedClientStructure = renderProviderStructure();
|
|
45
68
|
|
|
46
|
-
expect(
|
|
69
|
+
expect(serverStructure).toEqual(initialClientStructure);
|
|
70
|
+
expect(loadedClientStructure).toEqual(serverStructure);
|
|
47
71
|
});
|
|
48
72
|
|
|
49
73
|
test('surfaces font-loading failures', () => {
|
|
@@ -27,15 +27,11 @@ export interface ExpoZoraIconFontProviderProps {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export function ExpoZoraIconFontProvider(props: ExpoZoraIconFontProviderProps) {
|
|
30
|
-
const [
|
|
30
|
+
const [, error] = useFonts(ZORA_ICON_FONTS);
|
|
31
31
|
|
|
32
32
|
if (error) {
|
|
33
33
|
throw error;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
if (!loaded) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
36
|
return <>{props.children}</>;
|
|
41
37
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { PermissionStatus } from '@ankhorage/permissions';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CameraPermissionStatus } from '@ankhorage/zora';
|
|
3
3
|
import type { BarcodeType } from 'expo-camera';
|
|
4
4
|
|
|
5
|
-
export const BARCODE_SCAN_DEDUPE_WINDOW_MS = 1500;
|
|
6
|
-
|
|
7
5
|
export const BARCODE_SCANNER_TYPES = [
|
|
8
6
|
'aztec',
|
|
9
7
|
'codabar',
|
|
@@ -20,17 +18,7 @@ export const BARCODE_SCANNER_TYPES = [
|
|
|
20
18
|
'upc_e',
|
|
21
19
|
] as const satisfies readonly BarcodeType[];
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
readonly timestamp: number;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface ExpoBarcodeScanResultLike {
|
|
28
|
-
readonly data: string;
|
|
29
|
-
readonly type?: string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
type ExpoBarcodeScanCallback = (result: BarcodeScanResult) => Promise<void> | void;
|
|
33
|
-
|
|
21
|
+
/*** Maps the Permissions owner status to ZORA's documented camera UI status. */
|
|
34
22
|
export function mapPermissionStatusToCameraPermissionStatus(
|
|
35
23
|
status: PermissionStatus,
|
|
36
24
|
isRequestingPermission: boolean,
|
|
@@ -48,56 +36,3 @@ export function mapPermissionStatusToCameraPermissionStatus(
|
|
|
48
36
|
return 'denied';
|
|
49
37
|
}
|
|
50
38
|
}
|
|
51
|
-
|
|
52
|
-
export function normalizeExpoBarcodeScanResult(
|
|
53
|
-
result: ExpoBarcodeScanResultLike,
|
|
54
|
-
): BarcodeScanResult | null {
|
|
55
|
-
const value = result.data.trim();
|
|
56
|
-
if (value.length === 0) {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const type = typeof result.type === 'string' && result.type.length > 0 ? result.type : undefined;
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
value,
|
|
64
|
-
type,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function shouldIgnoreBarcodeScan(
|
|
69
|
-
previous: BarcodeScanRecord | null,
|
|
70
|
-
next: BarcodeScanResult,
|
|
71
|
-
now: number,
|
|
72
|
-
): boolean {
|
|
73
|
-
if (previous === null) {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return (
|
|
78
|
-
previous.value === next.value &&
|
|
79
|
-
previous.type === next.type &&
|
|
80
|
-
now - previous.timestamp < BARCODE_SCAN_DEDUPE_WINDOW_MS
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export async function dispatchExpoBarcodeScan(
|
|
85
|
-
result: ExpoBarcodeScanResultLike,
|
|
86
|
-
previous: BarcodeScanRecord | null,
|
|
87
|
-
now: number,
|
|
88
|
-
onBarcodeScanned: ExpoBarcodeScanCallback | undefined,
|
|
89
|
-
onAccepted: (record: BarcodeScanRecord) => void,
|
|
90
|
-
): Promise<boolean> {
|
|
91
|
-
const normalizedResult = normalizeExpoBarcodeScanResult(result);
|
|
92
|
-
if (normalizedResult === null || shouldIgnoreBarcodeScan(previous, normalizedResult, now)) {
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const record = {
|
|
97
|
-
...normalizedResult,
|
|
98
|
-
timestamp: now,
|
|
99
|
-
};
|
|
100
|
-
onAccepted(record);
|
|
101
|
-
await onBarcodeScanned?.(normalizedResult);
|
|
102
|
-
return true;
|
|
103
|
-
}
|
package/src/iconFonts.test.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { expect, test } from 'bun:test';
|
|
2
|
+
import React from 'react';
|
|
2
3
|
|
|
3
4
|
import { ExpoZoraIconFontProvider } from './ExpoZoraIconFontProvider';
|
|
4
5
|
|
|
@@ -25,3 +26,14 @@ test('exports the icon font boundary through its focused subpath', async () => {
|
|
|
25
26
|
});
|
|
26
27
|
expect(ExpoZoraIconFontProvider).toBeFunction();
|
|
27
28
|
});
|
|
29
|
+
|
|
30
|
+
test('keeps the native provider as a transparent child boundary', () => {
|
|
31
|
+
const child = React.createElement('native-child');
|
|
32
|
+
const element = ExpoZoraIconFontProvider({ children: child });
|
|
33
|
+
|
|
34
|
+
expect(React.isValidElement(element)).toBe(true);
|
|
35
|
+
if (!React.isValidElement(element)) {
|
|
36
|
+
throw new Error('expected a React element');
|
|
37
|
+
}
|
|
38
|
+
expect(element.props.children).toBe(child);
|
|
39
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
export {
|
|
2
|
-
BARCODE_SCAN_DEDUPE_WINDOW_MS,
|
|
3
2
|
BARCODE_SCANNER_TYPES,
|
|
4
|
-
type BarcodeScanRecord,
|
|
5
|
-
type ExpoBarcodeScanResultLike,
|
|
6
3
|
mapPermissionStatusToCameraPermissionStatus,
|
|
7
|
-
normalizeExpoBarcodeScanResult,
|
|
8
|
-
shouldIgnoreBarcodeScan,
|
|
9
4
|
} from './barcodeScanRuntime';
|
|
10
5
|
export {
|
|
11
6
|
type ExpoBundledMediaRegistrySourceEntry,
|
|
@@ -33,7 +28,10 @@ export {
|
|
|
33
28
|
export type { ComponentRegistry } from './componentRegistry';
|
|
34
29
|
export { createComponentRegistry } from './componentRegistry';
|
|
35
30
|
export { createExpoRuntimeRegistry } from './createExpoRuntimeRegistry';
|
|
36
|
-
export {
|
|
31
|
+
export {
|
|
32
|
+
ExpoBarcodeScannerAdapter,
|
|
33
|
+
type ExpoBarcodeScannerAdapterProps,
|
|
34
|
+
} from './ExpoBarcodeScannerAdapter';
|
|
37
35
|
export { ExpoRuntimeProviders, type ExpoRuntimeProvidersProps } from './ExpoRuntimeProviders';
|
|
38
36
|
export {
|
|
39
37
|
ExpoZoraIconFontProvider,
|