@velion-la/onboarding-sdk-react-native 1.0.0-beta.9 → 1.0.0
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/lib/commonjs/camera/DocumentCapture.js +67 -26
- package/lib/commonjs/camera/DocumentCapture.js.map +1 -1
- package/lib/commonjs/i18n/strings/en.js +3 -2
- package/lib/commonjs/i18n/strings/en.js.map +1 -1
- package/lib/commonjs/i18n/strings/es.js +3 -2
- package/lib/commonjs/i18n/strings/es.js.map +1 -1
- package/lib/commonjs/steps/DocumentsOcrStep.js +121 -23
- package/lib/commonjs/steps/DocumentsOcrStep.js.map +1 -1
- package/lib/commonjs/steps/PhoneContactStep.js +10 -4
- package/lib/commonjs/steps/PhoneContactStep.js.map +1 -1
- package/lib/commonjs/steps/PhoneOtpStep.js +17 -6
- package/lib/commonjs/steps/PhoneOtpStep.js.map +1 -1
- package/lib/commonjs/ui/StepShell.js +122 -12
- package/lib/commonjs/ui/StepShell.js.map +1 -1
- package/lib/commonjs/ui/overlays/ProgressBar.js +8 -2
- package/lib/commonjs/ui/overlays/ProgressBar.js.map +1 -1
- package/lib/commonjs/utils/documentCrop.js +115 -0
- package/lib/commonjs/utils/documentCrop.js.map +1 -0
- package/lib/module/camera/DocumentCapture.js +67 -26
- package/lib/module/camera/DocumentCapture.js.map +1 -1
- package/lib/module/i18n/strings/en.js +3 -2
- package/lib/module/i18n/strings/en.js.map +1 -1
- package/lib/module/i18n/strings/es.js +3 -2
- package/lib/module/i18n/strings/es.js.map +1 -1
- package/lib/module/steps/DocumentsOcrStep.js +121 -23
- package/lib/module/steps/DocumentsOcrStep.js.map +1 -1
- package/lib/module/steps/PhoneContactStep.js +10 -4
- package/lib/module/steps/PhoneContactStep.js.map +1 -1
- package/lib/module/steps/PhoneOtpStep.js +17 -6
- package/lib/module/steps/PhoneOtpStep.js.map +1 -1
- package/lib/module/ui/StepShell.js +122 -13
- package/lib/module/ui/StepShell.js.map +1 -1
- package/lib/module/ui/overlays/ProgressBar.js +8 -1
- package/lib/module/ui/overlays/ProgressBar.js.map +1 -1
- package/lib/module/utils/documentCrop.js +109 -0
- package/lib/module/utils/documentCrop.js.map +1 -0
- package/lib/typescript/camera/DocumentCapture.d.ts +20 -8
- package/lib/typescript/camera/DocumentCapture.d.ts.map +1 -1
- package/lib/typescript/i18n/strings/en.d.ts.map +1 -1
- package/lib/typescript/i18n/strings/es.d.ts +1 -0
- package/lib/typescript/i18n/strings/es.d.ts.map +1 -1
- package/lib/typescript/steps/DocumentsOcrStep.d.ts +8 -6
- package/lib/typescript/steps/DocumentsOcrStep.d.ts.map +1 -1
- package/lib/typescript/ui/StepShell.d.ts.map +1 -1
- package/lib/typescript/ui/overlays/ProgressBar.d.ts +6 -0
- package/lib/typescript/ui/overlays/ProgressBar.d.ts.map +1 -1
- package/lib/typescript/utils/documentCrop.d.ts +62 -0
- package/lib/typescript/utils/documentCrop.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/camera/DocumentCapture.tsx +66 -25
- package/src/i18n/strings/en.ts +3 -2
- package/src/i18n/strings/es.ts +3 -2
- package/src/steps/DocumentsOcrStep.tsx +145 -24
- package/src/steps/PhoneContactStep.tsx +9 -3
- package/src/steps/PhoneOtpStep.tsx +14 -4
- package/src/ui/StepShell.tsx +114 -12
- package/src/ui/overlays/ProgressBar.tsx +8 -1
- package/src/utils/documentCrop.ts +138 -0
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
* triggers `takePhoto()` with `qualityPrioritization: 'balanced'`; the file
|
|
6
6
|
* URI is returned to the caller via `onCaptured`.
|
|
7
7
|
*
|
|
8
|
-
* Visual: dark scrim with a transparent rectangular cutout (ID-1
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
8
|
+
* Visual: dark scrim with a transparent rectangular cutout (ID-1 ratio). The
|
|
9
|
+
* cutout is both the visible guide AND the crop region: on capture we hand the
|
|
10
|
+
* caller the guide rectangle so the photo can be cropped to exactly what the
|
|
11
|
+
* user framed (OSDKR-2). This is a geometric crop to a fixed guide — NOT edge
|
|
12
|
+
* detection / OpenCV; we never inspect pixels. The backend's Document AI still
|
|
13
|
+
* runs OCR and its own face crop on top.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
@@ -33,6 +33,17 @@ import type { DocumentOrientation, DocumentSide } from '../types';
|
|
|
33
33
|
import { useTheme, withAlpha } from '../ui/theme';
|
|
34
34
|
import { Button } from '../ui/primitives/Button';
|
|
35
35
|
import { useSafeAreaInsets } from '../utils/useSafeAreaInsets';
|
|
36
|
+
import { computeCutout, type CutoutRect } from '../utils/documentCrop';
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Geometry of the on-screen guide at capture time, handed to `onCaptured` so
|
|
40
|
+
* the photo can be cropped to exactly what the user framed.
|
|
41
|
+
*/
|
|
42
|
+
export interface CaptureGuide {
|
|
43
|
+
cutout: CutoutRect;
|
|
44
|
+
screenW: number;
|
|
45
|
+
screenH: number;
|
|
46
|
+
}
|
|
36
47
|
|
|
37
48
|
export interface DocumentCaptureProps {
|
|
38
49
|
side: DocumentSide;
|
|
@@ -47,7 +58,13 @@ export interface DocumentCaptureProps {
|
|
|
47
58
|
retryLabel: string;
|
|
48
59
|
/** Localized "Cancel" / back label. */
|
|
49
60
|
cancelLabel: string;
|
|
50
|
-
|
|
61
|
+
/** Localized label shown over the camera while the shot is processed. */
|
|
62
|
+
processingLabel: string;
|
|
63
|
+
onCaptured: (
|
|
64
|
+
photo: PhotoFile,
|
|
65
|
+
side: DocumentSide,
|
|
66
|
+
guide: CaptureGuide,
|
|
67
|
+
) => void | Promise<void>;
|
|
51
68
|
onCancel: () => void;
|
|
52
69
|
}
|
|
53
70
|
|
|
@@ -59,11 +76,13 @@ export function DocumentCapture({
|
|
|
59
76
|
permissionDeniedLabel,
|
|
60
77
|
retryLabel,
|
|
61
78
|
cancelLabel,
|
|
79
|
+
processingLabel,
|
|
62
80
|
onCaptured,
|
|
63
81
|
onCancel,
|
|
64
82
|
}: DocumentCaptureProps) {
|
|
65
83
|
const theme = useTheme();
|
|
66
84
|
const insets = useSafeAreaInsets();
|
|
85
|
+
const { width: screenW, height: screenH } = useWindowDimensions();
|
|
67
86
|
const cameraRef = useRef<Camera>(null);
|
|
68
87
|
// Cross-platform back-camera selection.
|
|
69
88
|
//
|
|
@@ -157,13 +176,19 @@ export function DocumentCapture({
|
|
|
157
176
|
flash: 'off',
|
|
158
177
|
enableShutterSound: false,
|
|
159
178
|
});
|
|
160
|
-
|
|
179
|
+
// Await the caller's crop/compress so the processing overlay stays up
|
|
180
|
+
// for the whole capture→preview gap (a few seconds), giving the user
|
|
181
|
+
// feedback instead of an idle camera. On success the parent flips phase
|
|
182
|
+
// and this component unmounts; on failure / "stay on capture" the finally
|
|
183
|
+
// re-enables the shutter.
|
|
184
|
+
const cutout = computeCutout(screenW, screenH, orientation);
|
|
185
|
+
await onCaptured(photo, side, { cutout, screenW, screenH });
|
|
161
186
|
} catch (err) {
|
|
162
187
|
setError(err instanceof Error ? err.message : String(err));
|
|
163
188
|
} finally {
|
|
164
189
|
setShooting(false);
|
|
165
190
|
}
|
|
166
|
-
}, [onCaptured, side, shooting]);
|
|
191
|
+
}, [onCaptured, side, shooting, orientation, screenW, screenH]);
|
|
167
192
|
|
|
168
193
|
if (!hasPermission) {
|
|
169
194
|
return (
|
|
@@ -227,6 +252,11 @@ export function DocumentCapture({
|
|
|
227
252
|
device={device}
|
|
228
253
|
photo
|
|
229
254
|
photoQualityBalance="quality"
|
|
255
|
+
// Explicit `cover`: the guide-crop math in `computeGuideCropRect`
|
|
256
|
+
// assumes the preview center-crops the sensor frame to the screen
|
|
257
|
+
// aspect ratio. `cover` is vision-camera's default, but we pin it so
|
|
258
|
+
// the crop never silently drifts if that default changes.
|
|
259
|
+
resizeMode="cover"
|
|
230
260
|
enableZoomGesture={false}
|
|
231
261
|
isActive
|
|
232
262
|
/>
|
|
@@ -285,6 +315,12 @@ export function DocumentCapture({
|
|
|
285
315
|
/>
|
|
286
316
|
</Pressable>
|
|
287
317
|
</View>
|
|
318
|
+
{shooting ? (
|
|
319
|
+
<View style={styles.processingOverlay}>
|
|
320
|
+
<ActivityIndicator color="#FFFFFF" size="large" />
|
|
321
|
+
<Text style={styles.processingText}>{processingLabel}</Text>
|
|
322
|
+
</View>
|
|
323
|
+
) : null}
|
|
288
324
|
</View>
|
|
289
325
|
);
|
|
290
326
|
}
|
|
@@ -295,8 +331,6 @@ interface MaskProps {
|
|
|
295
331
|
orientation: DocumentOrientation;
|
|
296
332
|
}
|
|
297
333
|
|
|
298
|
-
const CUTOUT_WIDTH_RATIO = 0.85; // 85% of screen width
|
|
299
|
-
const CUTOUT_MAX_HEIGHT_RATIO = 0.62; // never taller than 62% of screen height
|
|
300
334
|
const CORNER_LENGTH = 28;
|
|
301
335
|
const CORNER_THICKNESS = 3;
|
|
302
336
|
/**
|
|
@@ -309,20 +343,14 @@ const DIM_COLOR = 'rgba(0,0,0,0.55)';
|
|
|
309
343
|
|
|
310
344
|
function DocumentMaskOverlay({ orientation }: MaskProps) {
|
|
311
345
|
const { width: screenW, height: screenH } = useWindowDimensions();
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
if (cutoutH > maxH) {
|
|
321
|
-
cutoutH = maxH;
|
|
322
|
-
cutoutW = cutoutH * aspectRatio;
|
|
323
|
-
}
|
|
324
|
-
const left = (screenW - cutoutW) / 2;
|
|
325
|
-
const top = (screenH - cutoutH) / 2;
|
|
346
|
+
// Shared with the post-capture crop (`computeGuideCropRect`) so the dimmed
|
|
347
|
+
// cutout the user sees and the pixels we keep are the exact same rectangle.
|
|
348
|
+
const {
|
|
349
|
+
left,
|
|
350
|
+
top,
|
|
351
|
+
width: cutoutW,
|
|
352
|
+
height: cutoutH,
|
|
353
|
+
} = computeCutout(screenW, screenH, orientation);
|
|
326
354
|
const R = CUTOUT_RADIUS;
|
|
327
355
|
|
|
328
356
|
// SVG mask: opaque outer rect minus a rounded inner rect. The mask paints
|
|
@@ -511,4 +539,17 @@ const styles = StyleSheet.create({
|
|
|
511
539
|
borderColor: '#FFFFFF',
|
|
512
540
|
backgroundColor: 'transparent',
|
|
513
541
|
},
|
|
542
|
+
processingOverlay: {
|
|
543
|
+
...StyleSheet.absoluteFillObject,
|
|
544
|
+
alignItems: 'center',
|
|
545
|
+
justifyContent: 'center',
|
|
546
|
+
gap: 14,
|
|
547
|
+
backgroundColor: 'rgba(0,0,0,0.6)',
|
|
548
|
+
},
|
|
549
|
+
processingText: {
|
|
550
|
+
color: '#FFFFFF',
|
|
551
|
+
fontSize: 15,
|
|
552
|
+
fontWeight: '600',
|
|
553
|
+
textAlign: 'center',
|
|
554
|
+
},
|
|
514
555
|
});
|
package/src/i18n/strings/en.ts
CHANGED
|
@@ -22,7 +22,7 @@ export const EN: StringsTable = {
|
|
|
22
22
|
human_basic_info: {
|
|
23
23
|
title: 'Personal information',
|
|
24
24
|
subtitle:
|
|
25
|
-
'Enter your name and ID exactly as shown on your
|
|
25
|
+
'Enter your name and ID exactly as shown on your identification.',
|
|
26
26
|
givenNames: 'Given name(s)',
|
|
27
27
|
familyNames: 'Family name(s)',
|
|
28
28
|
idType: 'ID type',
|
|
@@ -78,7 +78,7 @@ export const EN: StringsTable = {
|
|
|
78
78
|
tax_info: {
|
|
79
79
|
title: 'Tax information',
|
|
80
80
|
subtitle:
|
|
81
|
-
'
|
|
81
|
+
'Complete your tax information to help us get to know you better.',
|
|
82
82
|
taxpayerType: 'Taxpayer category',
|
|
83
83
|
taxpayerIdType: 'Tax identification type',
|
|
84
84
|
taxpayerId: 'Identification number',
|
|
@@ -216,6 +216,7 @@ export const EN: StringsTable = {
|
|
|
216
216
|
confirmBtn: 'Confirm',
|
|
217
217
|
confirmFront: 'Confirm front',
|
|
218
218
|
confirmBack: 'Confirm back',
|
|
219
|
+
processing: 'Processing image…',
|
|
219
220
|
initializing: 'Preparing capture…',
|
|
220
221
|
uploadingFront: 'Uploading front…',
|
|
221
222
|
uploadingBack: 'Uploading back…',
|
package/src/i18n/strings/es.ts
CHANGED
|
@@ -25,7 +25,7 @@ export const ES = {
|
|
|
25
25
|
human_basic_info: {
|
|
26
26
|
title: 'Datos personales',
|
|
27
27
|
subtitle:
|
|
28
|
-
'Ingresá tu nombre y documento tal como figuran en tu identificación
|
|
28
|
+
'Ingresá tu nombre y documento tal como figuran en tu identificación.',
|
|
29
29
|
givenNames: 'Nombre(s)',
|
|
30
30
|
familyNames: 'Apellido(s)',
|
|
31
31
|
idType: 'Tipo de documento',
|
|
@@ -81,7 +81,7 @@ export const ES = {
|
|
|
81
81
|
tax_info: {
|
|
82
82
|
title: 'Información fiscal',
|
|
83
83
|
subtitle:
|
|
84
|
-
'
|
|
84
|
+
'Completá tu información fiscal para ayudarnos a conocerte mejor.',
|
|
85
85
|
taxpayerType: 'Categoría fiscal',
|
|
86
86
|
taxpayerIdType: 'Tipo de identificación fiscal',
|
|
87
87
|
taxpayerId: 'Número de identificación',
|
|
@@ -219,6 +219,7 @@ export const ES = {
|
|
|
219
219
|
confirmBtn: 'Confirmar',
|
|
220
220
|
confirmFront: 'Confirmar frente',
|
|
221
221
|
confirmBack: 'Confirmar dorso',
|
|
222
|
+
processing: 'Procesando imagen…',
|
|
222
223
|
initializing: 'Preparando captura…',
|
|
223
224
|
uploadingFront: 'Subiendo frente…',
|
|
224
225
|
uploadingBack: 'Subiendo dorso…',
|
|
@@ -5,13 +5,15 @@
|
|
|
5
5
|
* intro → captureFront → reviewFront → captureBack → reviewBack →
|
|
6
6
|
* POST /documents-init → PUT image/jpeg × 2 → POST /documents-verify → done.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* Crop: on capture we receive the on-screen guide rectangle and crop the photo
|
|
9
|
+
* to it (OSDKR-2) — a geometric crop to the visible ID-1 frame, NOT edge
|
|
10
|
+
* detection / OpenCV. This trims the camera background, improves OCR framing
|
|
11
|
+
* and shrinks the upload. The backend's Document AI still runs OCR + its own
|
|
12
|
+
* face crop on top, so we keep a safety margin around the guide.
|
|
11
13
|
*
|
|
12
|
-
* Compression: vision-camera writes a high-quality JPEG.
|
|
13
|
-
* `expo-image-manipulator` before upload so we keep
|
|
14
|
-
* 5 MB ceiling Velion's storage layer expects.
|
|
14
|
+
* Compression: vision-camera writes a high-quality JPEG. After cropping we
|
|
15
|
+
* resize + re-compress with `expo-image-manipulator` before upload so we keep
|
|
16
|
+
* the payload under the 5 MB ceiling Velion's storage layer expects.
|
|
15
17
|
*/
|
|
16
18
|
|
|
17
19
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
@@ -43,7 +45,8 @@ import { useTheme, mixHex } from '../ui/theme';
|
|
|
43
45
|
import { getStrings } from '../i18n';
|
|
44
46
|
import { resolveCaptureModeFromStepConfig } from '../utils/stepConfig';
|
|
45
47
|
import { log } from '../utils/log';
|
|
46
|
-
import { DocumentCapture } from '../camera/DocumentCapture';
|
|
48
|
+
import { DocumentCapture, type CaptureGuide } from '../camera/DocumentCapture';
|
|
49
|
+
import { computeGuideCropRect } from '../utils/documentCrop';
|
|
47
50
|
import type { ApiCaller } from '../transport/api';
|
|
48
51
|
import type { StepDeps, StepModule } from './types';
|
|
49
52
|
import { toSubmissionError } from './_shared';
|
|
@@ -151,11 +154,16 @@ function DocumentsOcrView({
|
|
|
151
154
|
const [bannerError, setBannerError] = useState<string | null>(null);
|
|
152
155
|
const [busyLabel, setBusyLabel] = useState<string | null>(null);
|
|
153
156
|
const [retry, setRetry] = useState<{ message: string } | null>(null);
|
|
157
|
+
// Measured size of the preview area, used to fit the framed card to the
|
|
158
|
+
// capture's exact aspect ratio (no empty letterbox bands around the crop).
|
|
159
|
+
const [previewBox, setPreviewBox] = useState<{ w: number; h: number } | null>(
|
|
160
|
+
null,
|
|
161
|
+
);
|
|
154
162
|
|
|
155
163
|
const handleCaptured = useCallback(
|
|
156
|
-
async (photo: PhotoFile, side: DocumentSide) => {
|
|
164
|
+
async (photo: PhotoFile, side: DocumentSide, guide: CaptureGuide) => {
|
|
157
165
|
try {
|
|
158
|
-
const compressed = await compressJpeg(photo.path);
|
|
166
|
+
const compressed = await compressJpeg(photo.path, guide);
|
|
159
167
|
if (compressed.byteLength > MAX_BYTES) {
|
|
160
168
|
setBannerError(t.documents_ocr.fileTooLarge);
|
|
161
169
|
// Stay on the capture phase so the user can retake immediately.
|
|
@@ -249,6 +257,7 @@ function DocumentsOcrView({
|
|
|
249
257
|
permissionDeniedLabel={t.documents_ocr.cameraPermissionDenied}
|
|
250
258
|
retryLabel={t.documents_ocr.cameraTryAgain}
|
|
251
259
|
cancelLabel={t.common.cancel}
|
|
260
|
+
processingLabel={t.documents_ocr.processing}
|
|
252
261
|
onCancel={() =>
|
|
253
262
|
setPhase(side === 'FRONT' ? 'intro' : 'reviewFront')
|
|
254
263
|
}
|
|
@@ -270,12 +279,39 @@ function DocumentsOcrView({
|
|
|
270
279
|
<Text style={[styles.reviewTitle, { color: theme.textColor }]}>
|
|
271
280
|
{side === 'FRONT' ? t.documents_ocr.frontTitle : t.documents_ocr.backTitle}
|
|
272
281
|
</Text>
|
|
273
|
-
<View
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
282
|
+
<View
|
|
283
|
+
style={styles.previewWrap}
|
|
284
|
+
onLayout={(e) =>
|
|
285
|
+
setPreviewBox({
|
|
286
|
+
w: e.nativeEvent.layout.width,
|
|
287
|
+
h: e.nativeEvent.layout.height,
|
|
288
|
+
})
|
|
289
|
+
}
|
|
290
|
+
>
|
|
291
|
+
{previewBox ? (
|
|
292
|
+
<View
|
|
293
|
+
style={[
|
|
294
|
+
styles.previewCard,
|
|
295
|
+
fitContain(
|
|
296
|
+
captured.width / captured.height,
|
|
297
|
+
previewBox.w,
|
|
298
|
+
previewBox.h,
|
|
299
|
+
),
|
|
300
|
+
{
|
|
301
|
+
borderColor: theme.borderColor,
|
|
302
|
+
borderRadius: theme.borderRadiusPx,
|
|
303
|
+
},
|
|
304
|
+
]}
|
|
305
|
+
>
|
|
306
|
+
<Image
|
|
307
|
+
source={{ uri: captured.uri }}
|
|
308
|
+
style={styles.preview}
|
|
309
|
+
// Card matches the capture's aspect ratio exactly, so `cover`
|
|
310
|
+
// fills it edge to edge with no distortion and no bands.
|
|
311
|
+
resizeMode="cover"
|
|
312
|
+
/>
|
|
313
|
+
</View>
|
|
314
|
+
) : null}
|
|
279
315
|
</View>
|
|
280
316
|
{bannerError ? <Banner message={bannerError} /> : null}
|
|
281
317
|
<View style={styles.reviewActions}>
|
|
@@ -370,15 +406,53 @@ function DocumentsOcrView({
|
|
|
370
406
|
);
|
|
371
407
|
}
|
|
372
408
|
|
|
373
|
-
async function compressJpeg(
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
)
|
|
409
|
+
async function compressJpeg(
|
|
410
|
+
uri: string,
|
|
411
|
+
guide: CaptureGuide,
|
|
412
|
+
): Promise<CapturedSide> {
|
|
413
|
+
const source = normalizeFileUri(uri);
|
|
414
|
+
|
|
415
|
+
// Display dimensions of the captured photo — exactly the orientation the
|
|
416
|
+
// user saw framed in the preview (the live camera and the captured image are
|
|
417
|
+
// both shown upright with `cover` fit). We crop strictly to the on-screen
|
|
418
|
+
// guide rectangle the user centred the document in; we never inspect pixels
|
|
419
|
+
// and we never try to detect/rotate based on how the phone was held.
|
|
420
|
+
const { width: imageW, height: imageH } = await getDisplaySize(source);
|
|
421
|
+
|
|
422
|
+
const crop = computeGuideCropRect({
|
|
423
|
+
screenW: guide.screenW,
|
|
424
|
+
screenH: guide.screenH,
|
|
425
|
+
imageW,
|
|
426
|
+
imageH,
|
|
427
|
+
cutout: guide.cutout,
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
// Crop to the guide, then resize the long edge to MAX_LONG_EDGE (never
|
|
431
|
+
// upscale — the crop can leave a small region) and recompress to ~78%.
|
|
432
|
+
const actions: ImageManipulator.Action[] = [
|
|
433
|
+
{
|
|
434
|
+
crop: {
|
|
435
|
+
originX: crop.x,
|
|
436
|
+
originY: crop.y,
|
|
437
|
+
width: crop.width,
|
|
438
|
+
height: crop.height,
|
|
439
|
+
},
|
|
440
|
+
},
|
|
441
|
+
];
|
|
442
|
+
const longEdge = Math.max(crop.width, crop.height);
|
|
443
|
+
if (longEdge > MAX_LONG_EDGE) {
|
|
444
|
+
actions.push({
|
|
445
|
+
resize:
|
|
446
|
+
crop.width >= crop.height
|
|
447
|
+
? { width: MAX_LONG_EDGE }
|
|
448
|
+
: { height: MAX_LONG_EDGE },
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
const result = await ImageManipulator.manipulateAsync(source, actions, {
|
|
453
|
+
compress: COMPRESS_QUALITY,
|
|
454
|
+
format: ImageManipulator.SaveFormat.JPEG,
|
|
455
|
+
});
|
|
382
456
|
const byteLength = await fetchByteLength(result.uri);
|
|
383
457
|
return {
|
|
384
458
|
uri: result.uri,
|
|
@@ -388,6 +462,24 @@ async function compressJpeg(uri: string): Promise<CapturedSide> {
|
|
|
388
462
|
};
|
|
389
463
|
}
|
|
390
464
|
|
|
465
|
+
/**
|
|
466
|
+
* Resolve the captured photo's *display* dimensions (upright, EXIF applied) —
|
|
467
|
+
* what the user saw in the preview. `Image.getSize` reads the header without a
|
|
468
|
+
* full re-encode, so it's both cheap and the source of truth for the crop
|
|
469
|
+
* mapping. No orientation guessing: the value is the displayed size, period.
|
|
470
|
+
*/
|
|
471
|
+
function getDisplaySize(
|
|
472
|
+
uri: string,
|
|
473
|
+
): Promise<{ width: number; height: number }> {
|
|
474
|
+
return new Promise((resolve, reject) => {
|
|
475
|
+
Image.getSize(
|
|
476
|
+
uri,
|
|
477
|
+
(width, height) => resolve({ width, height }),
|
|
478
|
+
(err) => reject(err instanceof Error ? err : new Error(String(err))),
|
|
479
|
+
);
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
|
|
391
483
|
async function uploadJpeg(uri: string, signedUrl: string): Promise<void> {
|
|
392
484
|
const response = await fetch(uri);
|
|
393
485
|
if (!response.ok) {
|
|
@@ -411,6 +503,25 @@ async function fetchByteLength(uri: string): Promise<number> {
|
|
|
411
503
|
return blob.size;
|
|
412
504
|
}
|
|
413
505
|
|
|
506
|
+
/**
|
|
507
|
+
* Fit a `width/height` box of the given aspect ratio inside `boxW × boxH`
|
|
508
|
+
* (contain). Returns the largest size that keeps the aspect ratio and fits —
|
|
509
|
+
* so the framed preview hugs the capture with no empty bands.
|
|
510
|
+
*/
|
|
511
|
+
function fitContain(
|
|
512
|
+
aspect: number,
|
|
513
|
+
boxW: number,
|
|
514
|
+
boxH: number,
|
|
515
|
+
): { width: number; height: number } {
|
|
516
|
+
let width = boxW;
|
|
517
|
+
let height = boxW / aspect;
|
|
518
|
+
if (height > boxH) {
|
|
519
|
+
height = boxH;
|
|
520
|
+
width = boxH * aspect;
|
|
521
|
+
}
|
|
522
|
+
return { width, height };
|
|
523
|
+
}
|
|
524
|
+
|
|
414
525
|
function normalizeFileUri(uri: string): string {
|
|
415
526
|
// Vision-camera returns paths with a leading `/var/mobile/...` on iOS
|
|
416
527
|
// (no scheme) — `expo-image-manipulator` requires a `file://` prefix.
|
|
@@ -467,6 +578,16 @@ const styles = StyleSheet.create({
|
|
|
467
578
|
alignItems: 'center',
|
|
468
579
|
justifyContent: 'center',
|
|
469
580
|
},
|
|
581
|
+
previewCard: {
|
|
582
|
+
borderWidth: 1,
|
|
583
|
+
overflow: 'hidden',
|
|
584
|
+
// Subtle lift so the framed capture reads as a deliberate card.
|
|
585
|
+
shadowColor: '#000',
|
|
586
|
+
shadowOpacity: 0.12,
|
|
587
|
+
shadowRadius: 10,
|
|
588
|
+
shadowOffset: { width: 0, height: 4 },
|
|
589
|
+
elevation: 3,
|
|
590
|
+
},
|
|
470
591
|
preview: {
|
|
471
592
|
width: '100%',
|
|
472
593
|
height: '100%',
|
|
@@ -114,6 +114,8 @@ function PhoneContactView({
|
|
|
114
114
|
}
|
|
115
115
|
}, [api, phone, onComplete, sessionId, t, validation]);
|
|
116
116
|
|
|
117
|
+
const phoneField = validation.bind('phone', phone);
|
|
118
|
+
|
|
117
119
|
if (retry) {
|
|
118
120
|
return (
|
|
119
121
|
<RetryDialog
|
|
@@ -141,8 +143,9 @@ function PhoneContactView({
|
|
|
141
143
|
backDisabled={submitting}
|
|
142
144
|
>
|
|
143
145
|
<Input
|
|
144
|
-
label
|
|
145
|
-
|
|
146
|
+
// No visible label — the step title already names the field. Keep an
|
|
147
|
+
// accessibility label so screen readers still announce it.
|
|
148
|
+
accessibilityLabel={t.phone_contact.label}
|
|
146
149
|
autoCapitalize="none"
|
|
147
150
|
autoCorrect={false}
|
|
148
151
|
autoComplete="tel"
|
|
@@ -150,7 +153,10 @@ function PhoneContactView({
|
|
|
150
153
|
keyboardType="phone-pad"
|
|
151
154
|
placeholder="+5491112345678"
|
|
152
155
|
value={phone}
|
|
153
|
-
{...
|
|
156
|
+
{...phoneField}
|
|
157
|
+
// Strip whitespace so a pasted "+54 911 1234 5678" lands as E.164.
|
|
158
|
+
// Overrides the spread `onChangeText` from `bind`.
|
|
159
|
+
onChangeText={(text) => phoneField.onChangeText(text.replace(/\s+/g, ''))}
|
|
154
160
|
/>
|
|
155
161
|
{bannerError ? <Banner message={bannerError} /> : null}
|
|
156
162
|
<Button
|
|
@@ -149,6 +149,9 @@ function PhoneOtpView({
|
|
|
149
149
|
}
|
|
150
150
|
}, [api, onComplete, otp, otpValidation, sessionId, t]);
|
|
151
151
|
|
|
152
|
+
const phoneField = phoneValidation.bind('phone', phone);
|
|
153
|
+
const otpField = otpValidation.bind('otp', otp);
|
|
154
|
+
|
|
152
155
|
if (retry) {
|
|
153
156
|
return (
|
|
154
157
|
<RetryDialog
|
|
@@ -176,8 +179,9 @@ function PhoneOtpView({
|
|
|
176
179
|
backDisabled={busy !== null}
|
|
177
180
|
>
|
|
178
181
|
<Input
|
|
179
|
-
label
|
|
180
|
-
|
|
182
|
+
// No visible label — the step title already names the field. Keep an
|
|
183
|
+
// accessibility label so screen readers still announce it.
|
|
184
|
+
accessibilityLabel={t.phone_otp.phoneLabel}
|
|
181
185
|
autoCapitalize="none"
|
|
182
186
|
autoCorrect={false}
|
|
183
187
|
autoComplete="tel"
|
|
@@ -186,7 +190,9 @@ function PhoneOtpView({
|
|
|
186
190
|
placeholder="+5491112345678"
|
|
187
191
|
editable={stage === 'request'}
|
|
188
192
|
value={phone}
|
|
189
|
-
{...
|
|
193
|
+
{...phoneField}
|
|
194
|
+
// Strip whitespace so a pasted "+54 911 1234 5678" lands as E.164.
|
|
195
|
+
onChangeText={(text) => phoneField.onChangeText(text.replace(/\s+/g, ''))}
|
|
190
196
|
/>
|
|
191
197
|
{stage === 'request' ? (
|
|
192
198
|
<Button
|
|
@@ -198,6 +204,8 @@ function PhoneOtpView({
|
|
|
198
204
|
) : (
|
|
199
205
|
<>
|
|
200
206
|
<Input
|
|
207
|
+
// Label kept here: in the verify stage the phone field is also
|
|
208
|
+
// visible, so the label disambiguates which field is the code.
|
|
201
209
|
label={t.phone_otp.otpLabel}
|
|
202
210
|
required
|
|
203
211
|
autoCapitalize="none"
|
|
@@ -206,7 +214,9 @@ function PhoneOtpView({
|
|
|
206
214
|
textContentType="oneTimeCode"
|
|
207
215
|
maxLength={6}
|
|
208
216
|
value={otp}
|
|
209
|
-
{...
|
|
217
|
+
{...otpField}
|
|
218
|
+
// Strip whitespace so a pasted code (e.g. "123 456") becomes "123456".
|
|
219
|
+
onChangeText={(text) => otpField.onChangeText(text.replace(/\s+/g, ''))}
|
|
210
220
|
/>
|
|
211
221
|
{bannerError ? <Banner message={bannerError} /> : null}
|
|
212
222
|
<Button
|