Driver onboarding now photographs the licence, ID card and vehicle
registration and reads the credential fields off them, plus a camera-only
profile selfie riders check the arriving driver against. Adds in-app chat
and WebRTC calls, push-backed ride offers, ratings, cancellation and
payment sheets, settlement, and the owner dashboard endpoints behind them.
Camera permission on Android:
- Declare CAMERA and READ_MEDIA_IMAGES in the manifest. expo-image-picker's
own plugin never declares CAMERA, and Android denies a request for an
undeclared permission instantly and silently — no dialog is ever shown,
which is indistinguishable from the app not asking at all.
- Handle canAskAgain: once Android stops showing the dialog, repeating why
we need it is a dead end, so offer Open Settings instead (lib/capture-
permission.ts), matching what the location flow already did.
Session: a 401 on a request that carried a token now ends the session
instead of being reinterpreted per-screen — driver-home had been reading it
as "this user has no driver profile" and showing an onboarding form to an
already-onboarded driver. Requests without a token are exempt so a failed
sign-in doesn't sign you out, and the notification is latched per token so
concurrent polls tear the session down once. (root) gains the auth guard
that turns that into the sign-in screen; app/index.tsx only guarded the way
in, leaving a session that ended mid-screen with nowhere to go.
Also ignore .uploads/ — it holds driver licence, ID and vehicle scans plus
profile photos, which are personal data and must not be committed.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
58 lines
2.3 KiB
TypeScript
58 lines
2.3 KiB
TypeScript
import { requireOptionalNativeModule } from "expo-modules-core";
|
|
|
|
import type * as ImagePickerModule from "expo-image-picker";
|
|
|
|
export type ImagePickerApi = typeof ImagePickerModule;
|
|
|
|
/** The native module expo-image-picker is a JS wrapper around. */
|
|
const NATIVE_MODULE = "ExponentImagePicker";
|
|
|
|
/**
|
|
* Whether photo capture can work at all in this build.
|
|
*
|
|
* `requireOptionalNativeModule` is the non-throwing twin of the
|
|
* `requireNativeModule` call that expo-image-picker makes as it loads: it
|
|
* returns null instead of raising `Cannot find native module
|
|
* 'ExponentImagePicker'`. Asking first means the error is never constructed,
|
|
* never logged, and never has a chance to escape into a driver's face — which
|
|
* beats importing the package and catching the throw, because a throw that
|
|
* happens while a module is evaluating can surface in places a try/catch
|
|
* around the import does not cover.
|
|
*
|
|
* expo-modules-core itself is part of every Expo binary, so importing it here
|
|
* is safe on exactly the old builds this is guarding against.
|
|
*/
|
|
export const isImagePickerAvailable = (): boolean =>
|
|
requireOptionalNativeModule(NATIVE_MODULE) !== null;
|
|
|
|
/**
|
|
* Loads expo-image-picker, or returns null when this binary predates it.
|
|
*
|
|
* The package resolves its native counterpart at *import* time, so importing
|
|
* it at the top of a screen doesn't fail politely at the camera button: it
|
|
* fails while the route tree is being built, taking the whole app down —
|
|
* riders included — on any build made before the package was added. Deferring
|
|
* the require moves that failure to the one tap that needs it and makes it
|
|
* recoverable.
|
|
*
|
|
* A null return means one thing only: the app needs rebuilding. Photo capture
|
|
* genuinely requires the native module; nothing here can substitute for it.
|
|
*/
|
|
let cached: ImagePickerApi | null = null;
|
|
|
|
export const loadImagePicker = (): ImagePickerApi | null => {
|
|
if (cached) return cached;
|
|
if (!isImagePickerAvailable()) return null;
|
|
|
|
try {
|
|
// Static string so Metro still bundles it — only the evaluation is
|
|
// deferred, not the packaging.
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
cached = require("expo-image-picker") as ImagePickerApi;
|
|
return cached;
|
|
} catch (error) {
|
|
console.log("[IMAGE_PICKER_UNAVAILABLE]: ", error);
|
|
return null;
|
|
}
|
|
};
|