mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-23 20:10:05 +08:00
[types][mlkit-vision] rework types
This commit is contained in:
@@ -63,3 +63,4 @@ android/.settings
|
||||
*.coverage.json
|
||||
.circleci
|
||||
.eslintignore
|
||||
type-test.ts
|
||||
|
||||
@@ -21,11 +21,11 @@ import VisionBarcodeFormat from './VisionBarcodeFormat';
|
||||
export default class VisionBarcodeDetectorOptions extends MutatableParams {
|
||||
constructor() {
|
||||
super();
|
||||
this.set('barcodeFormats', [VisionBarcodeFormat.ALL_FORMATS]); // TODO format all formats
|
||||
this.set('barcodeFormats', [VisionBarcodeFormat.ALL_FORMATS]);
|
||||
}
|
||||
|
||||
setBarcodeFormats(...formats) {
|
||||
// todo
|
||||
this.set('barcodeFormats', []);
|
||||
// todo validate
|
||||
this.set('barcodeFormats', formats);
|
||||
}
|
||||
}
|
||||
|
||||
69
packages/ml-vision/lib/index.d.ts
vendored
69
packages/ml-vision/lib/index.d.ts
vendored
@@ -15,12 +15,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
import {
|
||||
ReactNativeFirebaseModule,
|
||||
ReactNativeFirebaseModuleAndStatics,
|
||||
ReactNativeFirebaseNamespace,
|
||||
} from '@react-native-firebase/app-types';
|
||||
import './BarcodeDetectorTypes';
|
||||
import { ReactNativeFirebase } from '@react-native-firebase/app';
|
||||
|
||||
/**
|
||||
* Firebase ML Kit package for React Native.
|
||||
@@ -59,6 +54,8 @@ import './BarcodeDetectorTypes';
|
||||
* @firebase ml-vision
|
||||
*/
|
||||
export namespace MLKitVision {
|
||||
import FirebaseModule = ReactNativeFirebase.FirebaseModule;
|
||||
|
||||
export interface Statics {
|
||||
VisionFaceDetectorOptions: VisionFaceDetectorOptions;
|
||||
VisionImageLabelerOptions: VisionImageLabelerOptions;
|
||||
@@ -1068,7 +1065,7 @@ export namespace MLKitVision {
|
||||
* const defaultAppMLKit = firebase.mlKitVision();
|
||||
* ```
|
||||
*/
|
||||
export class Module extends ReactNativeFirebaseModule {
|
||||
export class Module extends FirebaseModule {
|
||||
/**
|
||||
* Detects faces from a local image file.
|
||||
*
|
||||
@@ -1244,48 +1241,36 @@ export const VisionBarcodeWifiEncryptionType = MLKITVision.VisionBarcodeWifiEncr
|
||||
export const VisionBarcodeDetectorOptions = MLKITVision.VisionBarcodeDetectorOptions;
|
||||
|
||||
declare module '@react-native-firebase/ml-vision' {
|
||||
import { ReactNativeFirebaseNamespace } from '@react-native-firebase/app-types';
|
||||
import ReactNativeFirebaseModule = ReactNativeFirebase.Module;
|
||||
import FirebaseModuleWithStaticsAndApp = ReactNativeFirebase.FirebaseModuleWithStaticsAndApp;
|
||||
|
||||
const FirebaseNamespaceExport: {} & ReactNativeFirebaseNamespace;
|
||||
const firebaseNamedExport: {} & ReactNativeFirebaseModule;
|
||||
export const firebase = firebaseNamedExport;
|
||||
|
||||
/**
|
||||
* @example
|
||||
* ```js
|
||||
* import { firebase } from '@react-native-firebase/ml-vision';
|
||||
* firebase.mlKitVision().X(...);
|
||||
* ```
|
||||
*/
|
||||
export const firebase = FirebaseNamespaceExport;
|
||||
|
||||
const MLKitVisionDefaultExport: ReactNativeFirebaseModuleAndStatics<
|
||||
MLKitVision.Module,
|
||||
MLKitVision.Statics
|
||||
>;
|
||||
/**
|
||||
* @example
|
||||
* ```js
|
||||
* import mlKitVision from '@react-native-firebase/ml-vision';
|
||||
* mlKitVision().X(...);
|
||||
* ```
|
||||
*/
|
||||
export default MLKitVisionDefaultExport;
|
||||
const module: FirebaseModuleWithStaticsAndApp<MLKitVision.Module, MLKitVision.Statics>;
|
||||
export default module;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach namespace to `firebase.` and `FirebaseApp.`.
|
||||
*/
|
||||
declare module '@react-native-firebase/app-types' {
|
||||
interface ReactNativeFirebaseNamespace {
|
||||
/**
|
||||
* MLKitVision
|
||||
*/
|
||||
mlKitVision: ReactNativeFirebaseModuleAndStatics<MLKitVision.Module, MLKitVision.Statics>;
|
||||
}
|
||||
declare module '@react-native-firebase/app' {
|
||||
namespace ReactNativeFirebase {
|
||||
import FirebaseModuleWithStaticsAndApp = ReactNativeFirebase.FirebaseModuleWithStaticsAndApp;
|
||||
interface Module {
|
||||
mlKitVision: FirebaseModuleWithStaticsAndApp<MLKitVision.Module, MLKitVision.Statics>;
|
||||
}
|
||||
|
||||
interface FirebaseApp {
|
||||
/**
|
||||
* MLKitVision
|
||||
*/
|
||||
mlKitVision(): MLKitVision.Module;
|
||||
interface FirebaseApp {
|
||||
mlKitVision(): MLKitVision.Module;
|
||||
}
|
||||
|
||||
interface FirebaseConfig {
|
||||
ml_vision_face_model: boolean;
|
||||
ml_vision_ocr_model: boolean;
|
||||
ml_vision_barcode_model: boolean;
|
||||
ml_vision_label_model: boolean;
|
||||
ml_vision_image_label_model: boolean;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
26
packages/ml-vision/type-test.ts
Normal file
26
packages/ml-vision/type-test.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import firebase from '@react-native-firebase/app';
|
||||
import defaultExport, { firebase as firebaseFromModule } from '@react-native-firebase/ml-vision';
|
||||
|
||||
// checks module exists at root
|
||||
console.log(firebase.mlKitVision().app.name);
|
||||
|
||||
// checks module exists at app level
|
||||
console.log(firebase.app().mlKitVision().app.name);
|
||||
|
||||
// checks statics exist
|
||||
console.log(firebase.mlKitVision.SDK_VERSION);
|
||||
|
||||
// checks statics exist on defaultExport
|
||||
console.log(defaultExport.SDK_VERSION);
|
||||
|
||||
// checks root exists
|
||||
console.log(firebase.SDK_VERSION);
|
||||
|
||||
// checks firebase named export exists on module
|
||||
console.log(firebaseFromModule.SDK_VERSION);
|
||||
|
||||
// checks multi-app support exists
|
||||
console.log(firebase.mlKitVision(firebase.app()).app.name);
|
||||
|
||||
// checks default export supports app arg
|
||||
console.log(defaultExport(firebase.app()).app.name);
|
||||
Reference in New Issue
Block a user