Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新设备相关types #14679

Merged
merged 9 commits into from
Oct 23, 2023
10 changes: 5 additions & 5 deletions packages/taro-h5/types/overlay.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Taro from '@tarojs/taro'

declare module '@tarojs/taro' {
namespace vibrateShort {
interface Option {
type?: 'heavy' | 'medium' | 'light'
}
}
// namespace vibrateShort {
// interface Option {
// type?: 'heavy' | 'medium' | 'light'
// }
// }
}
10 changes: 5 additions & 5 deletions packages/taro-rn/types/overlay.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Taro from '@tarojs/taro'

declare module '@tarojs/taro' {
namespace vibrateShort {
interface Option {
type?: 'heavy' | 'medium' | 'light'
}
}
// namespace vibrateShort {
// interface Option {
// type?: 'heavy' | 'medium' | 'light'
// }
// }
}
14 changes: 8 additions & 6 deletions packages/taro/types/api/device/accelerometer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ declare module '../../index' {
* ```tsx
* Taro.startAccelerometer({ interval: 'game' })
* ```
* @supported weapp, h5, rn, tt
* @supported weapp, alipay, swan, jd, qq, tt, h5, rn
* @see https://developers.weixin.qq.com/miniprogram/dev/api/device/accelerometer/wx.startAccelerometer.html
*/
startAccelerometer (res?: startAccelerometer.Option): Promise<TaroGeneral.CallbackResult>
Expand All @@ -67,14 +67,14 @@ declare module '../../index' {
* ```tsx
* Taro.stopAccelerometer()
* ```
* @supported weapp, h5, rn, tt
* @supported weapp, alipay, swan, jd, qq, tt, h5, rn
* @see https://developers.weixin.qq.com/miniprogram/dev/api/device/accelerometer/wx.stopAccelerometer.html
*/
stopAccelerometer (res?: stopAccelerometer.Option): Promise<TaroGeneral.CallbackResult>

/**
* 监听加速度数据,频率:5次/秒,接口调用后会自动开始监听,可使用 `Taro.stopAccelerometer` 停止监听。
* @supported weapp, h5, rn, tt
* @supported weapp, alipay, swan, jd, qq, tt, h5, rn
* @example
* ```tsx
* Taro.onAccelerometerChange(res => {
Expand All @@ -85,16 +85,18 @@ declare module '../../index' {
* ```
* @see https://developers.weixin.qq.com/miniprogram/dev/api/device/accelerometer/wx.onAccelerometerChange.html
*/
onAccelerometerChange (callback: onAccelerometerChange.Callback): void
onAccelerometerChange(
callback: onAccelerometerChange.Callback
): void

/**
* 取消监听加速度数据事件,参数为空,则取消所有的事件监听。
* @supported weapp, h5, rn
* @supported weapp, alipay, swan, jd, tt, h5, rn
* @see https://developers.weixin.qq.com/miniprogram/dev/api/device/accelerometer/wx.offAccelerometerChange.html
*/
offAccelerometerChange(
/** 加速度数据事件的回调函数 */
callback?: (...args: any[]) => any,
callback?: onAccelerometerChange.Callback
): void
}
}
2 changes: 1 addition & 1 deletion packages/taro/types/api/device/accessibility.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ declare module '../../index' {

interface TaroStatic {
/** 检测是否开启视觉无障碍功能。
* @supported weapp
* @supported weapp, jd
* @see https://developers.weixin.qq.com/miniprogram/dev/api/device/accessibility/wx.checkIsOpenAccessibility.html
*/
checkIsOpenAccessibility(option: checkIsOpenAccessibility.Option): Promise<TaroGeneral.CallbackResult>
Expand Down
4 changes: 2 additions & 2 deletions packages/taro/types/api/device/battery.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ declare module '../../index' {

interface TaroStatic {
/** Taro.getBatteryInfo 的同步版本
* @supported weapp
* @supported weapp, alipay, swan, jd, qq
* @see https://developers.weixin.qq.com/miniprogram/dev/api/device/battery/wx.getBatteryInfoSync.html
*/
getBatteryInfoSync(): getBatteryInfoSync.Result

/** 获取设备电量。同步 API Taro.getBatteryInfoSync 在 iOS 上不可用。
* @supported weapp, h5
* @supported weapp, alipay, swan, jd, qq, h5
* @see https://developers.weixin.qq.com/miniprogram/dev/api/device/battery/wx.getBatteryInfo.html
*/
getBatteryInfo(option?: getBatteryInfo.Option): Promise<getBatteryInfo.SuccessCallbackResult>
Expand Down
57 changes: 40 additions & 17 deletions packages/taro/types/api/device/bluetooth-ble.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ declare module '../../index' {
serviceId: string
/** 蓝牙设备特征值对应的二进制值 */
value: ArrayBuffer
/** 蓝牙特征值的写模式设置,有两种模式,iOS 优先 write,安卓优先 writeNoResponse 。(基础库 2.22.0 开始支持) */
writeType?: keyof WriteType
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: (res: TaroGeneral.BluetoothError) => void
/** 接口调用失败的回调函数 */
fail?: (res: TaroGeneral.BluetoothError) => void
/** 接口调用成功的回调函数 */
success?: (res: TaroGeneral.BluetoothError) => void
}
interface WriteType {
/** 强制回复写,不支持时报错 */
write
/** 强制无回复写,不支持时报错 */
writeNoResponse
}
}

namespace setBLEMTU {
Expand Down Expand Up @@ -122,13 +130,21 @@ declare module '../../index' {
serviceId: string
/** 是否启用 notify */
state: boolean
/** 设置特征订阅类型,有效值有 notification 和 indication
* @default "indication"
*/
type?: keyof Type
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: (res: TaroGeneral.BluetoothError) => void
/** 接口调用失败的回调函数 */
fail?: (res: TaroGeneral.BluetoothError) => void
/** 接口调用成功的回调函数 */
success?: (res: TaroGeneral.BluetoothError) => void
}
interface Type {
notification
indication
}
}

namespace getBLEMTU {
Expand All @@ -138,7 +154,7 @@ declare module '../../index' {
/** 写模式 (iOS 特有参数)
* @default "write"
*/
writeType: keyof WriteType
writeType?: keyof WriteType
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: (res: TaroGeneral.BluetoothError) => void
/** 接口调用失败的回调函数 */
Expand Down Expand Up @@ -244,6 +260,10 @@ declare module '../../index' {
read: boolean
/** 该特征值是否支持 write 操作 */
write: boolean
/** 该特征是否支持无回复写操作 */
writeNoResponse: boolean
/** 该特征是否支持有回复写操作 */
writeDefault: boolean
}
}

Expand Down Expand Up @@ -291,7 +311,7 @@ declare module '../../index' {
* - 小程序不会对写入数据包大小做限制,但系统与蓝牙设备会限制蓝牙4.0单次传输的数据大小,超过最大字节数后会发生写入错误,建议每次写入不超过20字节。
* - 若单次写入数据过长,iOS 上存在系统不会有任何回调的情况(包括错误回调)。
* - 安卓平台上,在调用 `notifyBLECharacteristicValueChange` 成功后立即调用 `writeBLECharacteristicValue` 接口,在部分机型上会发生 10008 系统错误
* @supported weapp
* @supported weapp, alipay, jd
* @example
* ```tsx
* // 向蓝牙设备发送一个0x00的16进制数据
Expand Down Expand Up @@ -319,7 +339,10 @@ declare module '../../index' {
): Promise<writeBLECharacteristicValue.Promised>

/** 协商设置蓝牙低功耗的最大传输单元 (Maximum Transmission Unit, MTU)
* @supported weapp
*
* - 需在 Taro.createBLEConnection 调用成功后调用
* - 仅安卓系统 5.1 以上版本有效,iOS 因系统限制不支持。
* @supported weapp, alipay, jd
* @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.setBLEMTU.html
*/
setBLEMTU(
Expand All @@ -331,7 +354,7 @@ declare module '../../index' {
* **注意**
* - 并行调用多次会存在读失败的可能性。
* - 接口读取到的信息需要在 `onBLECharacteristicValueChange` 方法注册的回调中获取。
* @supported weapp
* @supported weapp, alipay, jd
* @example
* ```tsx
* // 必须在这里的回调才能获取
Expand Down Expand Up @@ -372,7 +395,7 @@ declare module '../../index' {
): void

/** 监听低功耗蓝牙连接状态的改变事件。包括开发者主动连接或断开连接,设备丢失,连接异常断开等等
* @supported weapp
* @supported weapp, alipay, jd
* @example
* ```tsx
* Taro.onBLEConnectionStateChange(function (res) {
Expand All @@ -388,7 +411,7 @@ declare module '../../index' {
): void

/** 监听低功耗蓝牙设备的特征值变化事件。必须先启用 `notifyBLECharacteristicValueChange` 接口才能接收到设备推送的 notification。
* @supported weapp
* @supported weapp, alipay, jd
* @example
* ```tsx
* // ArrayBuffer转16进制字符串示例
Expand Down Expand Up @@ -419,20 +442,20 @@ declare module '../../index' {
*/
offBLEMTUChange(
/** 蓝牙低功耗的最大传输单元变化事件的回调函数 */
callback: onBLEMTUChange.Callback,
callback?: onBLEMTUChange.Callback,
): void

/** 取消监听蓝牙低功耗连接状态的改变事件
* @supported weapp
* @supported weapp, alipay
* @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.offBLEConnectionStateChange.html
*/
offBLEConnectionStateChange(
/** 蓝牙低功耗连接状态的改变事件的回调函数 */
callback: onBLEConnectionStateChange.Callback,
callback?: onBLEConnectionStateChange.Callback,
): void

/** 取消监听蓝牙低功耗设备的特征值变化事件
* @supported weapp
* @supported weapp, alipay
* @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.offBLECharacteristicValueChange.html
*/
offBLECharacteristicValueChange(
Expand All @@ -447,7 +470,7 @@ declare module '../../index' {
* **注意**
* - 订阅操作成功后需要设备主动更新特征值的 value,才会触发 Taro.onBLECharacteristicValueChange 回调。
* - 安卓平台上,在调用 `notifyBLECharacteristicValueChange` 成功后立即调用 `writeBLECharacteristicValue` 接口,在部分机型上会发生 10008 系统错误
* @supported weapp
* @supported weapp, alipay, jd
* @example
* ```tsx
* Taro.notifyBLECharacteristicValueChange({
Expand All @@ -474,7 +497,7 @@ declare module '../../index' {
* 注意:
* - 小程序中 MTU 为 ATT_MTU,包含 Op-Code 和 Attribute Handle 的长度,实际可以传输的数据长度为 ATT_MTU - 3
* - iOS 系统中 MTU 为固定值;安卓系统中,MTU 会在系统协商成功之后发生改变,建议使用 [Taro.onBLEMTUChange](/docs/apis/device/bluetooth-ble/onBLEMTUChange) 监听。
* @supported weapp
* @supported weapp, alipay, jd
* @example
* ```tsx
* Taro.getBLEMTU({
Expand All @@ -492,7 +515,7 @@ declare module '../../index' {
): Promise<getBLEMTU.SuccessCallbackResult>

/** 获取蓝牙设备所有服务(service)。
* @supported weapp
* @supported weapp, alipay, jd
* @example
* ```tsx
* Taro.getBLEDeviceServices({
Expand All @@ -510,15 +533,15 @@ declare module '../../index' {
): Promise<getBLEDeviceServices.SuccessCallbackResult>

/** 获取蓝牙低功耗设备的信号强度 (Received Signal Strength Indication, RSSI)。
* @supported weapp
* @supported weapp, alipay, jd
* @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.getBLEDeviceRSSI.html
*/
getBLEDeviceRSSI(
option: getBLEDeviceRSSI.Option,
): Promise<getBLEDeviceRSSI.SuccessCallbackResult>

/** 获取蓝牙设备某个服务中所有特征值(characteristic)。
* @supported weapp
* @supported weapp, alipay, jd
* @example
* ```tsx
* Taro.getBLEDeviceCharacteristics({
Expand All @@ -545,7 +568,7 @@ declare module '../../index' {
* - 请保证尽量成对的调用 `createBLEConnection` 和 `closeBLEConnection` 接口。安卓如果多次调用 `createBLEConnection` 创建连接,有可能导致系统持有同一设备多个连接的实例,导致调用 `closeBLEConnection` 的时候并不能真正的断开与设备的连接。
* - 蓝牙连接随时可能断开,建议监听 Taro.onBLEConnectionStateChange 回调事件,当蓝牙设备断开时按需执行重连操作
* - 若对未连接的设备或已断开连接的设备调用数据读写操作的接口,会返回 10006 错误,建议进行重连操作。
* @supported weapp
* @supported weapp, alipay, jd
* @example
* ```tsx
* Taro.createBLEConnection({
Expand All @@ -561,7 +584,7 @@ declare module '../../index' {
createBLEConnection(option: createBLEConnection.Option): Promise<createBLEConnection.Promised>

/** 断开与低功耗蓝牙设备的连接。
* @supported weapp
* @supported weapp, alipay, jd
* @example
* ```tsx
* Taro.closeBLEConnection({
Expand Down
Loading