native
Clipboard, share sheet, haptics, location, camera and fingerprint unlock, each with a web fallback.
Every export of kitr/native, kitr/native/react, kitr/native/provider, read from the published type definitions. The guide shows them in use.
kitr/native
createMemoryNativeDrivers
function createMemoryNativeDrivers(overrides?: NativeConfig['drivers']): {
clipboard: ClipboardDriver;
share: ShareDriver;
haptics: HapticsDriver;
geolocation: GeolocationDriver;
camera: CameraDriver;
biometrics: BiometricsDriver;
shared: SharePayload[];
haptics_log: HapticKind[];
};
createNative
function createNative(config?: NativeConfig, app?: KitrApp): Native;
useNative
function useNative(app: KitrApp): Native;
webBiometrics
function webBiometrics(): BiometricsDriver | null;
WebAuthn user verification with a platform authenticator (Touch ID, Windows Hello).
webCamera
function webCamera(): CameraDriver | null;
webClipboard
function webClipboard(): ClipboardDriver | null;
webGeolocation
function webGeolocation(): GeolocationDriver | null;
webHaptics
function webHaptics(): HapticsDriver | null;
webShare
function webShare(): ShareDriver | null;
UnsupportedError
class UnsupportedError extends Error {
capability: NativeCapability;
constructor(capability: NativeCapability);
}
defineConfig
const defineConfig: <const C extends NativeConfig>(config: C) => C;
BiometricsDriver
interface BiometricsDriver {
/** Whether the device has an enrolled biometric or device credential. */
available(): Promise<boolean>;
/** Prompt; resolves to true on success, false when cancelled or failed. */
authenticate(options?: {
reason?: string;
}): Promise<boolean>;
}
CameraDriver
interface CameraDriver {
/** Take a photo (or, on the web, open the capture-enabled file input). */
capture(options?: {
source?: 'camera' | 'library';
quality?: number;
}): Promise<Photo | null>;
}
Capability
interface Capability<T> {
supported: boolean;
driver: T;
name: string;
}
ClipboardDriver
interface ClipboardDriver {
readText(): Promise<string>;
writeText(text: string): Promise<void>;
}
Device capabilities behind one API: clipboard, share sheet, haptics, geolocation, camera and
biometrics. Each is its own capability, so a platform package can replace one without touching
the others; the web drivers use the matching browser API and report supported: false elsewhere.
GeolocationDriver
interface GeolocationDriver {
current(options?: {
highAccuracy?: boolean;
timeout?: number;
}): Promise<Position>;
watch(listener: (position: Position) => void, options?: {
highAccuracy?: boolean;
}): () => void;
}
HapticsDriver
interface HapticsDriver {
impact(kind: HapticKind): Promise<void>;
}
Native
interface Native {
clipboard: Capability<ClipboardDriver> & ClipboardDriver;
share: Capability<ShareDriver> & ShareDriver;
haptics: Capability<HapticsDriver> & HapticsDriver;
geolocation: Capability<GeolocationDriver> & GeolocationDriver;
camera: Capability<CameraDriver> & CameraDriver;
biometrics: Capability<BiometricsDriver> & BiometricsDriver;
/** Which capabilities have a working driver, for devtools and feature gating. */
supported(): Record<NativeCapability, boolean>;
}
NativeConfig
interface NativeConfig {
/** Replace individual drivers (tests, custom hardware). */
drivers?: Partial<{
clipboard: ClipboardDriver;
share: ShareDriver;
haptics: HapticsDriver;
geolocation: GeolocationDriver;
camera: CameraDriver;
biometrics: BiometricsDriver;
}>;
}
Photo
interface Photo {
blob: Blob;
type: string;
/** Where the image came from. */
source: 'camera' | 'library';
}
Position
interface Position {
latitude: number;
longitude: number;
accuracy: number;
altitude?: number | null;
heading?: number | null;
speed?: number | null;
timestamp: number;
}
ShareDriver
interface ShareDriver {
canShare(payload: SharePayload): boolean;
/** Resolves to true when shared, false when dismissed. */
share(payload: SharePayload): Promise<boolean>;
}
SharePayload
interface SharePayload {
title?: string;
text?: string;
url?: string;
files?: File[];
}
HapticKind
type HapticKind = 'light' | 'medium' | 'heavy' | 'success' | 'warning' | 'error' | 'selection';
NativeCapability
type NativeCapability = 'clipboard' | 'share' | 'haptics' | 'geolocation' | 'camera' | 'biometrics';
kitr/native/react
useClipboard
function useClipboard(timeout?: number): {
copy: (text: string) => Promise<void>;
copied: boolean;
supported: boolean;
};
const { copy, copied } = useClipboard(): copy text and show a confirmation for timeout ms.
useGeolocation
function useGeolocation(options?: {
watch?: boolean;
highAccuracy?: boolean;
}): {
position: Position | null;
error: Error | null;
supported: boolean;
};
Current position, updated while mounted when watch is true.
useNative
function useNative(): Native;
useShare
function useShare(): {
supported: boolean;
canShare: (payload: SharePayload) => boolean;
share: (payload: SharePayload) => Promise<boolean>;
};
const { share, canShare } = useShare(): the share sheet, with a flag to hide the button where there is none.
kitr/native/provider
nativeProvider
const nativeProvider: import("@kitr/core").KitrProvider;
Binds native from the drivers platform packages registered (clipboard, share, haptics,
geolocation, camera, biometrics) with web drivers for the rest.