FileAttachmentPanel
Record attachments panel with pick-and-upload from files, photos or the camera, per-file progress with retry, list and grid views, and delete confirmation.
Installation
pnpm dlx @kivacore/ui-cli add @kivacore/rn-file-attachment-panelpnpm add expo-document-picker expo-image-pickerBoth pickers are optional peers loaded lazily. The Add sheet offers only the sources that are installed:
| Source | Package | Sheet item |
|---|---|---|
document | expo-document-picker | Browse files (multi-select, filtered by the MIME part of accept) |
library | expo-image-picker | Photo library (images + videos, multi-select) |
camera | expo-image-picker | Take photo |
With a single installed source the Add button opens that picker directly; with none (and no onPickFiles) the Add button is hidden.
Usage
import {
FileAttachmentPanel,
type KivaFile,
type NativeFile
} from '@/components/kiva-native/file-attachment-panel';
async function uploadFile(file: NativeFile, options?: { onProgress: (progress: number) => void }): Promise<KivaFile> {
const form = new FormData();
form.append('file', { uri: file.uri, name: file.name, type: file.type } as never);
// Use XMLHttpRequest (or expo-file-system uploadAsync) to report real progress.
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open('POST', `${apiUrl}/v1/apps/base/data-sources/contact/items/${recordId}/files`);
xhr.setRequestHeader('Authorization', `Bearer ${token}`);
xhr.upload.onprogress = event => options?.onProgress((event.loaded / event.total) * 100);
xhr.onload = () => (xhr.status < 300 ? resolve(JSON.parse(xhr.responseText).data) : reject(new Error('Upload failed')));
xhr.onerror = () => reject(new Error('Network error'));
xhr.send(form);
});
}
<FileAttachmentPanel
files={files}
maxFiles={10}
maxFileSize={20 * 1024 * 1024}
accept={['image/*', 'application/pdf']}
onUploadFile={uploadFile}
onDeleteFile={id => deleteFile(id)}
isDeletePending={deleteMutation.isPending}
onValidationError={message => toast.error(message)} />Behaviour:
- Add → source sheet → picker → every file is validated (
maxFileSize,accept, remainingmaxFilesslots; rejections go toonValidationError) →onUploadFileis called per file in parallel. - Each upload gets a progress row. Without
onProgressreports the bar sits at an indeterminate 50% (like web); a finished upload shows a check for 1.5 s. A rejected promise turns the row into an error row with Retry (re-runsonUploadFilewith the same file) and Dismiss. - Tapping a file calls
onFileOpen, orLinking.openURL(signed_url)whenonFileOpenis omitted. - Delete asks through
DeleteConfirmDialog(objectName="file"); the dialog closes whenonDeleteFileresolves and shows a spinner whileisDeletePending. - Uncontrolled view mode starts in grid when any file is an image, else list.
API Reference
FileAttachmentPanelProps
| Prop | Type | Default | Description |
|---|---|---|---|
files | KivaFile[] | - | Attached files (required) |
title | string | 'Attachments' | Header title |
editable | boolean | true | Show the Add button and delete affordances |
isLoading | boolean | false | Show the loading spinner + skeleton rows |
maxHeight | number | - | Caps the panel height (dp) and scrolls its content. Omit to render inline (web default is 560) |
maxFileSize | number | 52428800 (50 MB) | Maximum file size in bytes |
accept | string | string[] | - | Accepted types — a MIME list (['image/*', 'application/pdf']) or a web accept string ('image/*,.pdf'). Extension patterns match the file name |
maxFiles | number | - | Maximum number of files. Shown as n/max in the counter badge; Add is disabled when reached and extra picks are reported via onValidationError |
onUploadFile | (file: NativeFile, options?: UploadFileOptions) => Promise<KivaFile> | - | Uploads one picked file. Report progress through options.onProgress(0–100). Required for the Add button |
onDeleteFile | (fileId: string) => void | Promise<void> | - | Called after the delete confirmation. A rejection keeps the dialog open |
onInsertExternalFiles | (files: ExternalFilePayload[]) => void | Promise<void> | - | API parity with web. Native has no OneDrive / Google Drive picker, so it is never called |
onFileOpen | (file: KivaFile) => void | Linking.openURL(signed_url) | File tap handler |
isDeletePending | boolean | false | Pending state of the delete confirmation (and the row being deleted) |
className | string | - | Container classes |
oneDriveConfig | OneDrivePickerConfig | - | API parity with web — inert on native |
googleDriveConfig | GoogleDrivePickerConfig | - | API parity with web — inert on native |
viewMode | 'list' | 'grid' | auto | Native extra. Controlled view mode; uncontrolled = grid when images are present |
onViewModeChange | (mode: ViewMode) => void | - | Native extra. View toggle callback |
uploadingFiles | UploadingFile[] | - | Native extra. Controlled upload rows — when set, they replace the internally tracked uploads (rendered without Retry / Dismiss) |
onPickFiles | () => Promise<NativeFile[]> | - | Native extra. Custom picker that replaces the source sheet; return [] on cancel |
onValidationError | (error: string) => void | - | Native extra. A picked file was rejected (size, type, maxFiles) |
style | ViewStyle | - | Container style |
KivaFile
The web record shape; everything except id / file_name is optional on native.
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier |
file_name | string | File name |
file_type | string | MIME type — drives the coloured file-type icon and image thumbnails |
file_size | number | Size in bytes |
signed_url | string | null | Signed URL — thumbnails and the default open action |
source | 'local' | 'microsoft_onedrive' | 'google_drive' | Origin; cloud sources show a brand badge |
file_data | Record<string, unknown> | null | Provider metadata |
created_on | string | ISO creation date |
record_id | string | null | Owning record |
NativeFile
| Field | Type | Description |
|---|---|---|
uri | string | Local file URI (file://, content://, ph://) |
name | string | File name with extension |
type | string | MIME type (application/octet-stream when unknown) |
size | number | Size in bytes, when known |
UploadFileOptions
| Field | Type | Description |
|---|---|---|
onProgress | (progress: number) => void | Report upload progress (0–100) |
UploadingFile
| Field | Type | Description |
|---|---|---|
id | string | Row id |
file | NativeFile | File being uploaded |
progress | number | 0–100 |
status | 'uploading' | 'complete' | 'error' | Row state |
error | string | Error message (error rows) |
ExternalFilePayload
| Field | Type | Description |
|---|---|---|
source | 'microsoft_onedrive' | 'google_drive' | Provider |
file_name | string | File name |
file_type | string | MIME type |
signed_url | string | Provider URL |
file_data | Record<string, unknown> | Provider metadata |
expire_in | number | URL lifetime |
Components
| Component | Description |
|---|---|
FileAttachmentPanel | Header (title, counter, list/grid toggle, Add), file list or 3-column grid, upload rows, delete confirmation |
Type Exports
| Type | Description |
|---|---|
FileAttachmentPanelProps | Panel props |
KivaFile | Attached file record |
NativeFile | Picked file ({ uri, name, type, size? }) |
UploadFileOptions | Second argument of onUploadFile |
UploadingFile | Upload row |
ViewMode | 'list' | 'grid' |
ExternalFilePayload | Cloud file payload (API parity) |
OneDrivePickerConfig / GoogleDrivePickerConfig | Web picker configs (API parity, inert) |
FileAttachmentPanelViewMode | Deprecated alias of ViewMode |
FileAttachmentPickedFile | Deprecated alias of NativeFile |
i18n keys
Via useUiTranslation(): ui.fileAttachment.title, add, addFiles, sourceFiles, sourcePhotos, sourceCamera, listView, gridView, loadingFiles, noFiles, emptyHint, emptyReadOnly, uploadFailed, retry, dismiss, fileTooLarge ({name}, {size}), fileTypeNotAccepted ({name}), maxFilesReached ({count}), plus ui.common.delete.
Breaking changes
- The component moved to a folder; import path
@/components/kiva-native/file-attachment-panelis unchanged. titledefault'Files'→'Attachments'(web).maxFileSizenow defaults to 50 MB (was unlimited).uploadingFilesentries changed from{ id, name, progress: 0–1 }to the webUploadingFileshape{ id, file: NativeFile, progress: 0–100, status, error? }.- Upload failures now render as an error row with Retry / Dismiss and are no longer reported through
onValidationError(which now only covers rejected picks). onDeleteFileis confirmed throughDeleteConfirmDialoginstead ofAlert.alert; the dialog waits for the returned promise.- Tapping a file without
onFileOpennow openssigned_url(was a no-op). - Uncontrolled view mode defaults to grid when images are present (was always list).
- The Add button now opens a source sheet (files / photos / camera, depending on installed pickers) instead of the document picker directly; it is disabled (not hidden) when
maxFilesis reached. FileAttachmentPanelViewModeandFileAttachmentPickedFileare deprecated aliases ofViewMode/NativeFile.