forked from NervJS/taro
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from xiaoyan428820/release-3.6.8-app
fix: 修复网络相关接口实现及加速计接口桥接问题
- Loading branch information
Showing
9 changed files
with
256 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
packages/taro-mpharmony/src/api/device/accelerometer/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './offAccelerometerChange' | ||
export * from './onAccelerometerChange' | ||
export * from './startAccelerometer' | ||
export * from './stopAccelerometer' |
20 changes: 20 additions & 0 deletions
20
packages/taro-mpharmony/src/api/device/accelerometer/offAccelerometerChange.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Taro from '@tarojs/taro' | ||
import { shouldBeFunction } from 'src/utils' | ||
|
||
/** | ||
* 取消监听加速度数据事件,参数为空,则取消所有的事件监听 | ||
*/ | ||
export const offAccelerometerChange: typeof Taro.offAccelerometerChange = (callback) => { | ||
const name = 'offAccelerometerChange' | ||
|
||
// callback must be an Function or undefined | ||
const isFunction = shouldBeFunction(callback) | ||
if (!isFunction.flag && typeof callback !== 'undefined') { | ||
const res = { errMsg: `${name}:fail ${isFunction.msg}` } | ||
console.error(res.errMsg) | ||
return | ||
} | ||
|
||
// @ts-ignore | ||
native.offAccelerometerChange(callback) | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/taro-mpharmony/src/api/device/accelerometer/onAccelerometerChange.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Taro from '@tarojs/taro' | ||
import { shouldBeFunction } from 'src/utils' | ||
|
||
/** | ||
* 监听加速度数据事件。频率根据 Taro.startAccelerometer() 的 interval 参数。可使用 Taro.stopAccelerometer() 停止监听。 | ||
*/ | ||
export const onAccelerometerChange: typeof Taro.onAccelerometerChange = (callback) => { | ||
const name = 'onAccelerometerChange' | ||
|
||
// callback must be an Function | ||
const isFunction = shouldBeFunction(callback) | ||
if (!isFunction.flag) { | ||
const res = { errMsg: `${name}:fail ${isFunction.msg}` } | ||
console.error(res.errMsg) | ||
return | ||
} | ||
|
||
// @ts-ignore | ||
native.onAccelerometerChange(callback) | ||
} |
55 changes: 55 additions & 0 deletions
55
packages/taro-mpharmony/src/api/device/accelerometer/startAccelerometer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import Taro from '@tarojs/taro' | ||
import { shouldBeObject } from 'src/utils' | ||
import { MethodHandler } from 'src/utils/handler' | ||
|
||
/** | ||
* 开始监听加速度数据。 | ||
*/ | ||
export const startAccelerometer: typeof Taro.startAccelerometer = (options) => { | ||
const name = 'startAccelerometer' | ||
|
||
return new Promise((resolve, reject) => { | ||
if (typeof options === 'undefined') { | ||
// @ts-ignore | ||
native.startAccelerometer({ | ||
interval: 'normal', | ||
success: (res: any) => { | ||
resolve(res) | ||
}, | ||
fail: (res: any) => { | ||
resolve(res) | ||
} | ||
}) | ||
return | ||
} | ||
|
||
// options must be an Object | ||
const isObject = shouldBeObject(options) | ||
if (!isObject.flag) { | ||
const res = { errMsg: `${name}:fail ${isObject.msg}` } | ||
console.error(res.errMsg) | ||
return Promise.reject(res) | ||
} | ||
const { | ||
interval = 'normal', | ||
success, | ||
fail, | ||
complete | ||
} = options as Exclude<typeof options, undefined> | ||
|
||
const handle = new MethodHandler<{ | ||
errMsg?: string | ||
}>({ name, success, fail, complete }) | ||
|
||
// @ts-ignore | ||
native.startAccelerometer({ | ||
interval: interval, | ||
success: (res: any) => { | ||
handle.success(res, { resolve, reject }) | ||
}, | ||
fail: (res: any) => { | ||
handle.fail(res, { resolve, reject }) | ||
} | ||
}) | ||
}) | ||
} |
Oops, something went wrong.