Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

Commit

Permalink
feat(types): add TypeScript definition files
Browse files Browse the repository at this point in the history
Solves #785
  • Loading branch information
Felipe Constantino committed Feb 23, 2018
1 parent 8e22168 commit a94bad5
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
]
},
"main": "src/index.js",
"types": "types",
"nativePackage": true,
"pre-commit": "lint:staged",
"repository": {
Expand Down
160 changes: 160 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
// Type definitions for react-native-camera 1.0
// Definitions by Felipe Constantino <https://github.com/fconstant>
// If you modify this file, put your GitHub info here as well (for easy contacting purposes)

/*
* Author notes:
* I've tried to find a easy tool to convert from Flow to Typescript definition files (.d.ts).
* So we woudn't have to do it manually... Sadly, I haven't found it.
*
* If you are seeing this from the future, please, send us your cutting-edge technology :) (if it exists)
*/
import { Component } from 'react';
import { ViewProperties } from "react-native";

type AutoFocus = { on, off };
type FlashMode = { on, off, torch, auto }
type CameraType = { front, back }
type WhiteBalance = { sunny, cloudy, shadow, incandescent, fluorescent, auto }
type BarCodeType = { aztec, code128, code39, code39mod43, code93, ean13, ean8, pdf417, qr, upce, interleaved2of5, itf14, datamatrix }
type VideoQuality = { '2160p', '1080p', '720p', '480p', '4:3' }

type FaceDetectionClassifications = { all, none }
type FaceDetectionLandmarks = { all, none }
type FaceDetectionMode = { fast, accurate }

export interface Constants {
AutoFocus: AutoFocus;
FlashMode: FlashMode;
Type: CameraType;
WhiteBalance: WhiteBalance;
VideoQuality: VideoQuality;
BarCodeType: BarCodeType;
FaceDetection: {
Classifications: FaceDetectionClassifications;
Landmarks: FaceDetectionLandmarks;
Mode: FaceDetectionMode;
}
}

export interface RNCameraProps extends ViewProperties {
autoFocus?: keyof AutoFocus;
type?: keyof CameraType;
flashMode?: keyof FlashMode;
notAuthorizedView?: JSX.Element;
pendingAuthorizationView?: JSX.Element;

onCameraReady?(): void;
onMountError?(): void;

/** Value: float from 0 to 1.0 */
zoom?: number;
/** Value: float from 0 to 1.0 */
focusDepth?: number;

// -- BARCODE PROPS
barCodeTypes?: Array<keyof BarCodeType>;
onBarCodeRead?(data: string, type: keyof BarCodeType): void;

// -- FACE DETECTION PROPS

onFacesDetected?(response: { faces: Face[] }): void;
onFaceDetectionError?(response: { isOperational: boolean }): void;
faceDetectionMode?: keyof FaceDetectionMode;
faceDetectionLandmarks?: keyof FaceDetectionLandmarks;
faceDetectionClassifications?: keyof FaceDetectionClassifications;

// -- ANDROID ONLY PROPS

/** Android only */
ratio?: number;
/** Android only */
permissionDialogTitle?: string;
/** Android only */
permissionDialogMessage?: string;

// -- IOS ONLY PROPS

/** iOS Only */
captureAudio?: boolean;

}

interface Point {
x: number,
y: number
}

interface Face {
faceID?: number,
bounds: {
size: {
width: number;
height: number;
};
origin: Point;
};
smilingProbability?: number;
leftEarPosition?: Point;
rightEarPosition?: Point;
leftEyePosition?: Point;
leftEyeOpenProbability?: number;
rightEyePosition?: Point;
rightEyeOpenProbability?: number;
leftCheekPosition?: Point;
rightCheekPosition?: Point;
leftMouthPosition?: Point;
mouthPosition?: Point;
rightMouthPosition?: Point;
bottomMouthPosition?: Point;
noseBasePosition?: Point;
yawAngle?: number;
rollAngle?: number;
}

interface TakePictureOptions {
quality?: number;
base64?: boolean;
exif?: boolean;
}

interface TakePictureResponse {
width: number;
height: number;
uri: string;
base64?: string;
exif?: { [name: string]: any };
}


interface RecordOptions {
quality?: keyof VideoQuality;
maxDuration?: number;
maxFileSize?: number;
mute?: boolean;
}

interface RecordResponse {
/** Path to the video saved on your app's cache directory. */
uri: string;
}

export class RNCamera extends Component<RNCameraProps> {
static Constants: Constants;

takePictureAsync(options?: TakePictureOptions): Promise<TakePictureResponse>;
recordAsync(options?: RecordOptions): Promise<RecordResponse>;
stopRecording(): void;

/** Android only */
getSupportedRatiosAsync(): Promise<string[]>;
}

// -- DEPRECATED CONTENT BELOW

/**
* @deprecated As of 1.0.0 release, RCTCamera is deprecated. Please use RNCamera for the latest fixes and improvements.
*/
export default class RCTCamera extends Component<any> {
static constants: any;
}

0 comments on commit a94bad5

Please sign in to comment.