@velion-la/onboarding-sdk-react-native 1.0.0-beta.9 → 1.1.0-beta.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
package/src/ui/StepShell.tsx
CHANGED
|
@@ -7,16 +7,24 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { ReactNode } from 'react';
|
|
10
|
+
import { useRef } from 'react';
|
|
10
11
|
import {
|
|
12
|
+
Animated,
|
|
11
13
|
KeyboardAvoidingView,
|
|
12
14
|
Platform,
|
|
13
|
-
ScrollView,
|
|
14
15
|
StyleSheet,
|
|
15
16
|
Text,
|
|
16
17
|
View,
|
|
17
18
|
} from 'react-native';
|
|
19
|
+
import Svg, {
|
|
20
|
+
Defs,
|
|
21
|
+
LinearGradient as SvgLinearGradient,
|
|
22
|
+
Rect,
|
|
23
|
+
Stop,
|
|
24
|
+
} from 'react-native-svg';
|
|
18
25
|
import { useTheme, withAlpha } from './theme';
|
|
19
26
|
import { BackButton } from './primitives/BackButton';
|
|
27
|
+
import { PROGRESS_BAR_HEIGHT } from './overlays/ProgressBar';
|
|
20
28
|
import { useSafeAreaInsets } from '../utils/useSafeAreaInsets';
|
|
21
29
|
|
|
22
30
|
export interface StepShellProps {
|
|
@@ -53,26 +61,41 @@ export function StepShell({
|
|
|
53
61
|
const insets = useSafeAreaInsets();
|
|
54
62
|
|
|
55
63
|
const showIconCircle = !theme.hideStepIcons && iconNode != null;
|
|
64
|
+
const showBack = onBack != null;
|
|
56
65
|
|
|
57
|
-
|
|
58
|
-
|
|
66
|
+
// Drive the top-fade opacity from the scroll offset so the gradient is fully
|
|
67
|
+
// invisible at rest (scrollY = 0) — the header/icon reads crisp — and only
|
|
68
|
+
// ramps in as the content scrolls up under the fixed back strip (OSDKR-12).
|
|
69
|
+
const scrollY = useRef(new Animated.Value(0)).current;
|
|
70
|
+
const fadeOpacity = scrollY.interpolate({
|
|
71
|
+
inputRange: [0, FADE_RAMP_DISTANCE],
|
|
72
|
+
outputRange: [0, 1],
|
|
73
|
+
extrapolate: 'clamp',
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const scroll = (
|
|
77
|
+
<Animated.ScrollView
|
|
59
78
|
style={styles.scroll}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
79
|
+
scrollEventThrottle={16}
|
|
80
|
+
onScroll={Animated.event(
|
|
81
|
+
[{ nativeEvent: { contentOffset: { y: scrollY } } }],
|
|
82
|
+
{ useNativeDriver: true },
|
|
83
|
+
)}
|
|
84
|
+
// When the fixed back strip is present it already clears the status bar +
|
|
85
|
+
// progress bar, so the scroll body only needs its base top padding.
|
|
86
|
+
// Without it, add the device safe-area insets so the header (icon + title)
|
|
87
|
+
// clears the top camera / notch. The bottom inset always clears the
|
|
88
|
+
// navigation bar / gesture area on edge-to-edge Android and on iOS devices
|
|
89
|
+
// with a home indicator.
|
|
64
90
|
contentContainerStyle={[
|
|
65
91
|
styles.scrollBody,
|
|
66
92
|
{
|
|
67
|
-
paddingTop: BASE_PADDING_TOP + insets.top,
|
|
93
|
+
paddingTop: showBack ? BASE_PADDING_TOP : BASE_PADDING_TOP + insets.top,
|
|
68
94
|
paddingBottom: BASE_PADDING_BOTTOM + insets.bottom,
|
|
69
95
|
},
|
|
70
96
|
]}
|
|
71
97
|
keyboardShouldPersistTaps="handled"
|
|
72
98
|
>
|
|
73
|
-
{onBack ? (
|
|
74
|
-
<BackButton label={backLabel} onPress={onBack} disabled={backDisabled} />
|
|
75
|
-
) : null}
|
|
76
99
|
<View style={styles.header}>
|
|
77
100
|
{showIconCircle ? (
|
|
78
101
|
<View
|
|
@@ -99,7 +122,66 @@ export function StepShell({
|
|
|
99
122
|
) : null}
|
|
100
123
|
</View>
|
|
101
124
|
<View style={styles.column}>{children}</View>
|
|
102
|
-
</ScrollView>
|
|
125
|
+
</Animated.ScrollView>
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
// The back control lives in a fixed strip OUTSIDE the ScrollView so it stays
|
|
129
|
+
// pinned just below the (fixed) ProgressBar while the form scrolls behind it.
|
|
130
|
+
// `paddingTop` clears the status-bar / notch inset plus the progress bar's
|
|
131
|
+
// own height so "Atrás" never tucks under the bar (OSDKR-12).
|
|
132
|
+
const body = (
|
|
133
|
+
<View style={styles.flex}>
|
|
134
|
+
{showBack ? (
|
|
135
|
+
<View
|
|
136
|
+
style={[
|
|
137
|
+
styles.backStrip,
|
|
138
|
+
{ paddingTop: insets.top + PROGRESS_BAR_HEIGHT },
|
|
139
|
+
]}
|
|
140
|
+
>
|
|
141
|
+
<BackButton
|
|
142
|
+
label={backLabel}
|
|
143
|
+
onPress={onBack}
|
|
144
|
+
disabled={backDisabled}
|
|
145
|
+
/>
|
|
146
|
+
</View>
|
|
147
|
+
) : null}
|
|
148
|
+
<View style={styles.scrollWrap}>
|
|
149
|
+
{scroll}
|
|
150
|
+
{/* Soft top fade: the ScrollView hard-clips content at its top edge,
|
|
151
|
+
which reads as an abrupt cut as the header scrolls up under the
|
|
152
|
+
fixed back strip. A short background-to-transparent gradient lets
|
|
153
|
+
the content dissolve instead (OSDKR-12). Its opacity is tied to the
|
|
154
|
+
scroll offset so it stays invisible at rest and only appears once
|
|
155
|
+
the user scrolls. pointerEvents="none" so it never intercepts
|
|
156
|
+
touches / scroll. */}
|
|
157
|
+
<Animated.View
|
|
158
|
+
pointerEvents="none"
|
|
159
|
+
style={[styles.topFade, { height: TOP_FADE_HEIGHT, opacity: fadeOpacity }]}
|
|
160
|
+
>
|
|
161
|
+
<Svg width="100%" height="100%">
|
|
162
|
+
<Defs>
|
|
163
|
+
<SvgLinearGradient id="stepTopFade" x1="0" y1="0" x2="0" y2="1">
|
|
164
|
+
{/* Eased falloff (not linear): opaque near the top, then a long
|
|
165
|
+
gentle tail toward transparent, so the dissolve has no
|
|
166
|
+
perceptible edge. */}
|
|
167
|
+
<Stop offset="0" stopColor={theme.backgroundColor} stopOpacity={1} />
|
|
168
|
+
<Stop offset="0.35" stopColor={theme.backgroundColor} stopOpacity={0.85} />
|
|
169
|
+
<Stop offset="0.6" stopColor={theme.backgroundColor} stopOpacity={0.5} />
|
|
170
|
+
<Stop offset="0.82" stopColor={theme.backgroundColor} stopOpacity={0.18} />
|
|
171
|
+
<Stop offset="1" stopColor={theme.backgroundColor} stopOpacity={0} />
|
|
172
|
+
</SvgLinearGradient>
|
|
173
|
+
</Defs>
|
|
174
|
+
<Rect
|
|
175
|
+
x="0"
|
|
176
|
+
y="0"
|
|
177
|
+
width="100%"
|
|
178
|
+
height="100%"
|
|
179
|
+
fill="url(#stepTopFade)"
|
|
180
|
+
/>
|
|
181
|
+
</Svg>
|
|
182
|
+
</Animated.View>
|
|
183
|
+
</View>
|
|
184
|
+
</View>
|
|
103
185
|
);
|
|
104
186
|
|
|
105
187
|
if (avoidKeyboard) {
|
|
@@ -119,6 +201,14 @@ export function StepShell({
|
|
|
119
201
|
// of these at render time (see `contentContainerStyle` above).
|
|
120
202
|
const BASE_PADDING_TOP = 12;
|
|
121
203
|
const BASE_PADDING_BOTTOM = 28;
|
|
204
|
+
// Height of the background-to-transparent gradient masking the ScrollView's
|
|
205
|
+
// top clip edge. Tall on purpose: a long band makes the dissolve a gradual
|
|
206
|
+
// transition rather than a visible line.
|
|
207
|
+
const TOP_FADE_HEIGHT = 120;
|
|
208
|
+
// Scroll distance (px) over which the fade ramps from invisible (at rest) to
|
|
209
|
+
// fully active. Decoupled from TOP_FADE_HEIGHT so the long gradient still kicks
|
|
210
|
+
// in promptly as the user starts scrolling.
|
|
211
|
+
const FADE_RAMP_DISTANCE = 36;
|
|
122
212
|
|
|
123
213
|
const styles = StyleSheet.create({
|
|
124
214
|
flex: {
|
|
@@ -127,6 +217,18 @@ const styles = StyleSheet.create({
|
|
|
127
217
|
scroll: {
|
|
128
218
|
flex: 1,
|
|
129
219
|
},
|
|
220
|
+
scrollWrap: {
|
|
221
|
+
flex: 1,
|
|
222
|
+
},
|
|
223
|
+
topFade: {
|
|
224
|
+
position: 'absolute',
|
|
225
|
+
top: 0,
|
|
226
|
+
left: 0,
|
|
227
|
+
right: 0,
|
|
228
|
+
},
|
|
229
|
+
backStrip: {
|
|
230
|
+
paddingHorizontal: 18,
|
|
231
|
+
},
|
|
130
232
|
scrollBody: {
|
|
131
233
|
paddingHorizontal: 18,
|
|
132
234
|
paddingTop: BASE_PADDING_TOP,
|
|
@@ -11,6 +11,13 @@ import { useEffect, useRef } from 'react';
|
|
|
11
11
|
import { Animated, StyleSheet } from 'react-native';
|
|
12
12
|
import { mixHex, useReducedMotion, useTheme } from '../theme';
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Height of the progress track, in px. Exported so layout-aware chrome (e.g.
|
|
16
|
+
* `StepShell`'s fixed back-button strip) can sit flush below the bar without
|
|
17
|
+
* duplicating the magic number.
|
|
18
|
+
*/
|
|
19
|
+
export const PROGRESS_BAR_HEIGHT = 4;
|
|
20
|
+
|
|
14
21
|
export interface ProgressBarProps {
|
|
15
22
|
/** 0–100. Components compute the trickling logic externally and pass it in. */
|
|
16
23
|
value: number;
|
|
@@ -89,7 +96,7 @@ export const PROGRESS_BAR = {
|
|
|
89
96
|
|
|
90
97
|
const styles = StyleSheet.create({
|
|
91
98
|
track: {
|
|
92
|
-
height:
|
|
99
|
+
height: PROGRESS_BAR_HEIGHT,
|
|
93
100
|
width: '100%',
|
|
94
101
|
overflow: 'hidden',
|
|
95
102
|
},
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Geometry for the document capture guide + crop.
|
|
3
|
+
*
|
|
4
|
+
* Two pure helpers, shared between the camera overlay and the post-capture
|
|
5
|
+
* crop so the pixels we keep are *exactly* the rectangle the user framed:
|
|
6
|
+
*
|
|
7
|
+
* - `computeCutout` — the on-screen ID-1 guide rectangle (screen px).
|
|
8
|
+
* - `computeGuideCropRect` — maps that guide rectangle into the captured
|
|
9
|
+
* photo's pixel space, compensating for the camera preview's `cover` fit
|
|
10
|
+
* (the preview center-crops the sensor frame to the screen aspect ratio).
|
|
11
|
+
*
|
|
12
|
+
* This is a *geometric* crop to a fixed guide, NOT edge detection / OpenCV —
|
|
13
|
+
* we never inspect pixels. The backend's Document AI still runs OCR and its
|
|
14
|
+
* own face crop on top, so we keep a safety margin around the guide to avoid
|
|
15
|
+
* clipping the document (or the portrait the backend needs).
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type { DocumentOrientation } from '../types';
|
|
19
|
+
|
|
20
|
+
export interface CutoutRect {
|
|
21
|
+
left: number;
|
|
22
|
+
top: number;
|
|
23
|
+
width: number;
|
|
24
|
+
height: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface PixelRect {
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
width: number;
|
|
31
|
+
height: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// ID-1 aspect ratios (width / height). Portrait ≈ 0.625 (held vertically),
|
|
35
|
+
// landscape ≈ 1.586 (the real ID-1 card ratio, 85.6 × 53.98 mm).
|
|
36
|
+
const PORTRAIT_ASPECT = 0.625;
|
|
37
|
+
const LANDSCAPE_ASPECT = 1.586;
|
|
38
|
+
|
|
39
|
+
// The guide is 85% of screen width, but never taller than 62% of screen height
|
|
40
|
+
// (portrait ID-1 on tall phones would otherwise overflow).
|
|
41
|
+
const CUTOUT_WIDTH_RATIO = 0.85;
|
|
42
|
+
const CUTOUT_MAX_HEIGHT_RATIO = 0.62;
|
|
43
|
+
|
|
44
|
+
/** Default crop margin: expand each side of the guide by this fraction of the
|
|
45
|
+
* guide size, so a document slightly overflowing the frame isn't clipped. */
|
|
46
|
+
export const DEFAULT_CROP_MARGIN = 0.07;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The on-screen guide rectangle, in screen pixels. Mirrors what the mask
|
|
50
|
+
* overlay draws so the crop matches the visible cutout exactly.
|
|
51
|
+
*/
|
|
52
|
+
export function computeCutout(
|
|
53
|
+
screenW: number,
|
|
54
|
+
screenH: number,
|
|
55
|
+
orientation: DocumentOrientation,
|
|
56
|
+
): CutoutRect {
|
|
57
|
+
const aspectRatio =
|
|
58
|
+
orientation === 'portrait' ? PORTRAIT_ASPECT : LANDSCAPE_ASPECT;
|
|
59
|
+
|
|
60
|
+
let width = screenW * CUTOUT_WIDTH_RATIO;
|
|
61
|
+
let height = width / aspectRatio;
|
|
62
|
+
const maxH = screenH * CUTOUT_MAX_HEIGHT_RATIO;
|
|
63
|
+
if (height > maxH) {
|
|
64
|
+
height = maxH;
|
|
65
|
+
width = height * aspectRatio;
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
left: (screenW - width) / 2,
|
|
69
|
+
top: (screenH - height) / 2,
|
|
70
|
+
width,
|
|
71
|
+
height,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Map the on-screen guide rectangle into the captured photo's pixel space.
|
|
77
|
+
*
|
|
78
|
+
* The preview renders the photo with `cover` fit: the sensor frame is scaled
|
|
79
|
+
* up until it fills the screen and the overflow is center-cropped. So a screen
|
|
80
|
+
* point `(sx, sy)` maps to photo pixel `((W_img - W_screen/s)/2 + sx/s, …)`,
|
|
81
|
+
* where `s = max(W_screen/W_img, H_screen/H_img)`.
|
|
82
|
+
*
|
|
83
|
+
* `imageW`/`imageH` MUST be the photo's *display* (orientation-normalized)
|
|
84
|
+
* dimensions — i.e. portrait when the device is portrait — not the raw sensor
|
|
85
|
+
* dimensions, which are often landscape with an EXIF rotation flag.
|
|
86
|
+
*
|
|
87
|
+
* The result is expanded by `margin` (fraction of the mapped guide) and
|
|
88
|
+
* clamped to the image bounds, then rounded to integers (the manipulator
|
|
89
|
+
* rejects fractional crop rects).
|
|
90
|
+
*/
|
|
91
|
+
export function computeGuideCropRect(params: {
|
|
92
|
+
screenW: number;
|
|
93
|
+
screenH: number;
|
|
94
|
+
imageW: number;
|
|
95
|
+
imageH: number;
|
|
96
|
+
cutout: CutoutRect;
|
|
97
|
+
margin?: number;
|
|
98
|
+
}): PixelRect {
|
|
99
|
+
const {
|
|
100
|
+
screenW,
|
|
101
|
+
screenH,
|
|
102
|
+
imageW,
|
|
103
|
+
imageH,
|
|
104
|
+
cutout,
|
|
105
|
+
margin = DEFAULT_CROP_MARGIN,
|
|
106
|
+
} = params;
|
|
107
|
+
|
|
108
|
+
const scale = Math.max(screenW / imageW, screenH / imageH);
|
|
109
|
+
// Image pixels hidden off each edge by the cover crop.
|
|
110
|
+
const offsetX = (imageW - screenW / scale) / 2;
|
|
111
|
+
const offsetY = (imageH - screenH / scale) / 2;
|
|
112
|
+
|
|
113
|
+
let x = offsetX + cutout.left / scale;
|
|
114
|
+
let y = offsetY + cutout.top / scale;
|
|
115
|
+
let width = cutout.width / scale;
|
|
116
|
+
let height = cutout.height / scale;
|
|
117
|
+
|
|
118
|
+
// Expand by the safety margin.
|
|
119
|
+
const mx = width * margin;
|
|
120
|
+
const my = height * margin;
|
|
121
|
+
x -= mx;
|
|
122
|
+
y -= my;
|
|
123
|
+
width += mx * 2;
|
|
124
|
+
height += my * 2;
|
|
125
|
+
|
|
126
|
+
// Clamp to image bounds.
|
|
127
|
+
x = Math.max(0, x);
|
|
128
|
+
y = Math.max(0, y);
|
|
129
|
+
width = Math.min(width, imageW - x);
|
|
130
|
+
height = Math.min(height, imageH - y);
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
x: Math.round(x),
|
|
134
|
+
y: Math.round(y),
|
|
135
|
+
width: Math.round(width),
|
|
136
|
+
height: Math.round(height),
|
|
137
|
+
};
|
|
138
|
+
}
|