Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions PROJECT.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,63 @@ themed through `useTheme()` so a host's theme applies:
`onError({source, error})` reports an image the default renderer could not load (a lapsed signed URL).
- `DecisionDialog` — Paper `Dialog` in a `Portal` (the host needs Paper's `Provider`).
- `Timeline` — `history` and `steps`.
- Document requirements (contract request #117, 0.5.4), fed by a `getMyStatus` checklist item, so no host keeps a
document type of its own:
- `Partner/DocumentRequirementCard` (portable) — a Paper `Card` composed as Paper composes one: the title is
`requirementTitle(item)` (the rule's name for the market, else the catalogue's), `subtitle` is the host's,
then, in its `Card.Content`, `covers` (the photos taken and not sent, in order, each `{ uri, label }` with the
name a screen reader says), `note` and the rule's explanation, and `actions`
(`{ label, onPress, isDisabled?, mode?, loading?, testID? }`) as Paper `Button`s straight inside `Card.Actions`,
which keeps a `mode` given and gives the rest theirs; `loading` is the Button's own. Without `actions` it only
reads (the console). The note sits in a polite live region (`aria-live`: Android's live region, the web's
`aria-live`) that stays mounted, so a screen reader announces each next step. `Card.Actions` gets, through its
`style`, `flexWrap` and a `spacing.x2` row gap (it does not wrap by itself; its alignment and padding stay), and
its buttons are keyed by position, as `Card.Actions` itself tells them apart (a label changes as photos are taken).
- `Partner/DocumentCovers` (portable, not exported) — the card's photos: one is a `Card.Cover`; more are a
Material 3 hero carousel (a horizontal `ScrollView`: `snapToInterval` on the phone, `pagingEnabled`'s CSS scroll
snap on the web; items `spacing.x2` apart, the next peeking `spacing.x14`, Material's 8 dp and 56 dp), or all whole
side by side where the measured width fits them at Material's largest large item (twice the cover's height, which
the first cover reports, plus the gap). On the web the carousel's scrollbar shows (a mouse has no swipe). The item
it rests on is followed from `onScroll`, and a new width (rotation, resize) scrolls back to it. Each photo is an
image button (`imagebutton`; `button` + `aria-label` on the web, where react-native-web maps no role for it) named
by its `label`; it opens `DocumentViewer` full screen (Paper `Portal` + `Modal`, its height the window's between
the safe-area insets; the internal `SheetHeader` with its `global.close`) on that page, with the document's sides
(the covers' labels) when there are two. testIDs: `<testID>-covers`, `-carousel`, `-cover-<i>`, `-viewer`,
`-viewer-header-close`, `-viewer-document`.
- `Partner/DocumentVersionList` (portable) — `item.versions` as `ListRow`s from `documentVersionRows`; they open
nothing, so no chevron. A row's description: when it was sent, the scan's catalogue label while the scan is not
`SCAN_STATUS.CLEAN` (pending, and partner 0.2.54's infected, never spelled here), the details code's label, and
`documentExpiresOn` («Expires Nov 23, 2026»): `expires_at` is a calendar day, formatted by `formatDateTime` in UTC
so no reader's zone moves it. `documentExpires` stays for the app's older list.
- `Partner/DocumentCaptureCard` (barrel only: the picker is native) — the card with the way to send it, as
`item.capture` says (`pages` 1, or 2 = the front then the back). Controlled: `{ item, subtitle?, pages = [],
onPagesChange(pages), onSend(), isSending = false, testID = 'document-requirement' }` — the host owns the pages
(the picker's assets, in order) and clears them only once its send succeeded, so a failed send keeps them; the
card never clears them. Taking a photo sends nothing: the pages show as covers; its first action, a text button,
takes a photo («Add», or «Add the front»/«Add the back»; «Retake» once every page is there, when a photo starts
the document again), and the last, «Send to review», the only one with a border (outlined) and disabled until
every page is taken, calls `onSend()`. While `isSending` every action is disabled and «Send to review» shows the
Button's `loading`. The note asks for the back (`documentAddBackPrompt`) or, every page there and nothing sending,
says the photos are not sent yet (`documentNotSent`). Every photo is taken with `DOCUMENT_CAPTURE_OPTIONS`:
`maxWidth`/`maxHeight` 5,120 (an ID-1 card's PDF417 at ISO/IEC 15415's 5 px per module over AAMVA's 0.170 mm X
needs 3,597 px at 70% of the frame; an A4/Letter page at 300 ppi, 5,011 px; both bounds or the picker does not
resize), `quality` 1, `assetRepresentationMode: 'compatible'` (iOS JPEG, not HEIC) and `conversionQuality` 1
(Android's HEIC → JPEG). Photos only: it offers no PDF (owner, 2026-11-04).
- `ImagePicker.Avatar` `variant="sheet"` renders no control of its own; the caller opens the sheet with the
ref's `show()`, so its own Paper `Button` can sit inside a `Card.Actions`. `avatar` and `button` are as before.
Every variant: `captureOptions` (react-native-image-picker's options) are laid over the defaults (a photo, quality
1, base64), so callers that pass none behave as before; `onChange(asset)` is called only with a photo; the sheet
ignores taps while a pick is in progress; where it would offer a single choice (the web, which has no camera
option) `show()` takes that choice. `ImagePickerAPI`'s `takePhoto(options)` / `chooseFromLibrary(options)` always
resolve, never reject: the asset, or `null` — cancelled (silently), a permission refused (the permission alert,
with Settings) or any other picker error, read from its `errorCode` (`global.somethingWentWrong` /
`global.tryAgainLater`). The library asks for no permission: image-picker 8 opens Android's Photo Picker and iOS's
PHPicker, which need none (asking blocked Android 13+ and iOS limited access); the camera keeps its permission.
- Their fixed words (`documentAddFront`, `documentAddBack`, `documentAddBackPrompt`, `documentRetake` — moved here
from the app with its values —, `documentNotSent`, `documentFront`, `documentBack`, `documentSuperseded`,
`documentExpiresOn`) live in `Translations/*.json`, in the catalogue's «Agregar»; the stories
(`Partner/DocumentRequirement.stories.js`) use the local circuit's real items, and render the capture card itself
with `pages` for the photo states.
- `Partner/viewModel.js` (barrel/portable: `PartnerViewModel`, because `statusLabel` is the Order one):
the key is the package's `statusLabelKey(group, value)` resolved with `localized`; a value outside the
vocabulary, or a key the registered catalogue lacks, renders the raw value. Each kind's group is read
Expand Down
14 changes: 7 additions & 7 deletions packages/components/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jmstechnologiesinc/react-native-components",
"version": "0.5.3",
"version": "0.5.4",
"description": "Biblioteca de componentes de interfaz compartida por las aplicaciones de Daxir.",
"author": "yerloveraaa <yerloveraaa@gmail.com>",
"homepage": "https://github.com/jmstechnologiesinc/react-native-components#readme",
Expand All @@ -26,7 +26,7 @@
"url": "https://github.com/jmstechnologiesinc/react-native-components/issues"
},
"devDependencies": {
"@jmstechnologiesinc/partner": "0.2.48",
"@jmstechnologiesinc/partner": "0.2.54",
"prettier": "^2.5.1",
"rimraf": "^3.0.2"
},
Expand All @@ -36,7 +36,7 @@
"@jmstechnologiesinc/commons": "^0.1.5",
"@jmstechnologiesinc/order": "^0.6.0",
"@jmstechnologiesinc/order-narration": "^0.0.9",
"@jmstechnologiesinc/partner": "^0.2.47",
"@jmstechnologiesinc/partner": "^0.2.54",
"@jmstechnologiesinc/react-native-google-places-autocomplete": "^2.4.14",
"@jmstechnologiesinc/react-native-image-blur-loading": "^1.2.5",
"@jmstechnologiesinc/react-native-paper": "^5.12.12",
Expand Down
135 changes: 73 additions & 62 deletions packages/components/src/ImagePicker/ImagePickerAPI.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
import { Linking, Alert } from 'react-native';
import { launchCamera, launchImageLibrary } from 'react-native-image-picker';
import { checkAndAskForPermissionCamara, checkAndAskForPermissionMediaLibrary } from './utils';
import { RESULTS } from 'react-native-permissions';
import { checkAndAskForPermissionCamara } from './utils';

// What every pick asked for before a caller could pass options of its own (`takePhoto(options)`): a photo at full
// quality, with its base64. A caller's options are laid over these.
const DEFAULT_OPTIONS = Object.freeze({ mediaType: 'photo', quality: 1, includeBase64: true });

// react-native-image-picker's `errorCode` for a pick its platform refused for want of a permission; its other codes
// (`camera_unavailable`, `others`) are failures a setting cannot fix.
const PERMISSION_ERROR = 'permission';

// The answers of a camera permission request that Settings can change; anything else (`unavailable`, a request that
// threw) is a failure, not a refusal.
const PERMISSION_REFUSED = Object.freeze([RESULTS.DENIED, RESULTS.BLOCKED]);

/**
* Takes one photo with the camera or picks one from the library.
*
* `takePhoto(options)` and `chooseFromLibrary(options)` always resolve, and never reject, so a caller never waits on
* a pick that ended: with the picked asset, or with `null` when nothing was picked — cancelled (silently), refused a
* permission (the permission alert, with a way to Settings) or failed (the generic failure alert). `options` are
* react-native-image-picker's, laid over `DEFAULT_OPTIONS`.
*/
class ImagePickerAPI {
constructor({
titlePermissionCamera,
Expand All @@ -10,29 +31,28 @@ class ImagePickerAPI {
descriptionPermissionPhotos,
cancelPermission,
settingPermission,
titleFailure,
descriptionFailure,
closeFailure,
}) {
this.titlePermissionCamera = titlePermissionCamera;
this.titlePermissionPhotos = titlePermissionPhotos;
this.descriptionPermissionCamera = descriptionPermissionCamera;
this.descriptionPermissionPhotos = descriptionPermissionPhotos;
this.cancelPermission = cancelPermission;
this.settingPermission = settingPermission;
this.titleFailure = titleFailure;
this.descriptionFailure = descriptionFailure;
this.closeFailure = closeFailure;
}

catchPermissionStatusCamara() {
Alert.alert(
this.titlePermissionCamera,
this.descriptionPermissionCamera,
[
{
text: this.cancelPermission,
onPress: () => console.log('Cancel Pressed'),
style: 'cancel',
},
{
text: this.settingPermission,
onPress: () => Linking.openSettings(),
},
{ text: this.cancelPermission, style: 'cancel' },
{ text: this.settingPermission, onPress: () => Linking.openSettings() },
],
{ cancelable: false }
);
Expand All @@ -43,65 +63,56 @@ class ImagePickerAPI {
this.titlePermissionPhotos,
this.descriptionPermissionPhotos,
[
{
text: this.cancelPermission,
onPress: () => console.log('Cancel Pressed'),
style: 'cancel',
},
{
text: this.settingPermission,
onPress: () => Linking.openSettings(),
},
{ text: this.cancelPermission, style: 'cancel' },
{ text: this.settingPermission, onPress: () => Linking.openSettings() },
],
{ cancelable: false }
);
}

takePhoto() {
return new Promise((resolve) => {
checkAndAskForPermissionCamara()
.then(() => launchCamera({ mediaType: 'photo', quality: 1, includeBase64: true }))
.then((response) => {
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
Alert(response.error);
console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
resolve(response?.assets[0]);
}
})
.catch(() => this.catchPermissionStatusCamara());
});
// The button is named here: without one Android's alert falls back to an English «OK».
alertFailure() {
Alert.alert(this.titleFailure, this.descriptionFailure, [{ text: this.closeFailure }]);
}

/** The asset `launcher` picked, or null once the user has been told why there is none. */
launch(launcher, options, alertPermission) {
return launcher({ ...DEFAULT_OPTIONS, ...options })
.then((response) => {
if (response.didCancel) return null;
if (response.errorCode === PERMISSION_ERROR) {
alertPermission();
return null;
}
if (response.errorCode) {
this.alertFailure();
return null;
}
return response.assets?.[0] ?? null;
})
.catch(() => {
this.alertFailure();
return null;
});
}

takePhoto(options) {
return checkAndAskForPermissionCamara().then(
() => this.launch(launchCamera, options, () => this.catchPermissionStatusCamara()),
(status) => {
if (PERMISSION_REFUSED.includes(status)) this.catchPermissionStatusCamara();
else this.alertFailure();
return null;
}
);
}

chooseFromLibrary() {
return new Promise((resolve) => {
checkAndAskForPermissionMediaLibrary()
.then(() =>
launchImageLibrary({
mediaType: 'photo',
quality: 1,
includeBase64: true,
allowsMultipleSelection: true,
})
)
.then((response) => {
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
Alert(response.error);
console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
resolve(response?.assets[0]);
}
})
.catch(() => this.catchPermissionStatusPhotos());
});
// No permission is asked: react-native-image-picker 8 opens Android's Photo Picker and iOS's PHPicker, which run
// outside the app and hand back only what the user picks. Asking for the library permission blocked the pick where
// it cannot be granted: Android 13+ (the app declares no READ_EXTERNAL_STORAGE) and iOS limited access. The picker
// still reports `permission` where its platform checks one (iOS with `includeExtra`).
chooseFromLibrary(options) {
return this.launch(launchImageLibrary, options, () => this.catchPermissionStatusPhotos());
}
}

Expand Down
Loading
Loading