UNPKG

2.67 kBTypeScriptView Raw
1import { ComponentType } from 'react'
2import { StandardProps, CommonEventFunction } from './common'
3
4interface CameraProps extends StandardProps {
5 /** 模式,有效值为normal, scanCode
6 * @default "normal"
7 * @supported weapp, rn, tt
8 */
9 mode?: keyof CameraProps.Mode
10
11 /** 分辨率,不支持动态修改
12 * @default "medium"
13 * @supported weapp, tt
14 */
15 resolution?: keyof CameraProps.Resolution
16
17 /** 摄像头朝向
18 * @default "back"
19 * @supported weapp, rn, tt
20 */
21 devicePosition?: keyof CameraProps.DevicePosition
22
23 /** 闪光灯
24 * @default "auto"
25 * @supported weapp, rn, tt
26 */
27 flash?: keyof CameraProps.Flash
28
29 /** 指定期望的相机帧数据尺寸
30 * @default "medium"
31 * @supported weapp, tt
32 */
33 frameSize?: keyof CameraProps.FrameSize
34
35 /** 扫码识别区域,格式为[x, y, w, h],
36 * x,y是相对于camera显示区域的左上角,
37 * w,h为区域宽度,单位px,仅在 mode="scanCode" 时生效
38 * @supported weapp
39 */
40 scanArea?: number[]
41
42 /** 摄像头在非正常终止时触发,
43 * 如退出后台等情况
44 * @supported weapp, rn, tt
45 */
46 onStop?: CommonEventFunction
47
48 /** 用户不允许使用摄像头时触发
49 * @supported weapp, rn, tt
50 */
51 onError?: CommonEventFunction
52
53 /** 相机初始化完成时触发
54 * @supported weapp, rn, tt
55 */
56 onInitDone?: CommonEventFunction<CameraProps.onInitDoneEventDetail>
57
58 /** 在成功识别到一维码时触发,
59 * 仅在 mode="scanCode" 时生效
60 * @supported weapp, rn, tt
61 */
62 onScanCode?: CommonEventFunction
63}
64
65declare namespace CameraProps {
66 /** mode 的合法值 */
67 interface Mode {
68 /** 相机模式 */
69 normal
70 /** 扫码模式 */
71 scanCode
72 }
73 /** resolution 的合法值 */
74 interface Resolution {
75 /** 低 */
76 low
77 /** 中 */
78 medium
79 /** 高 */
80 high
81 }
82 /** device-position 的合法值 */
83 interface DevicePosition {
84 /** 前置 */
85 front
86 /** 后置 */
87 back
88 }
89 /** flash 的合法值 */
90 interface Flash {
91 /** 自动 */
92 auto
93 /** 打开 */
94 on
95 /** 关闭 */
96 off
97 /** 常亮 */
98 torch
99 }
100 /** frame-size 的合法值 */
101 interface FrameSize {
102 /** 小尺寸帧数据 */
103 small
104 /** 中尺寸帧数据 */
105 medium
106 /** 大尺寸帧数据 */
107 large
108 }
109
110 interface onInitDoneEventDetail {
111 /** 最大变焦 */
112 maxZoom: number
113 }
114}
115
116/** 系统相机
117 * @classification media
118 * @supported weapp, rn, tt
119 * @see https://developers.weixin.qq.com/miniprogram/dev/component/camera.html
120 */
121declare const Camera: ComponentType<CameraProps>
122
123export { Camera, CameraProps }