From 1e0be27c4ce36a26dad53d63d79c22a8fb35324d Mon Sep 17 00:00:00 2001 From: xiaoyan428820 <121045285@qq.com> Date: Tue, 11 Jun 2024 17:54:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20[harmony-hybrid]=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=83=A8=E5=88=86API=E8=B0=83=E7=94=A8=E5=8E=9F=E7=94=9F?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/pages/api/media/camera/index.tsx | 14 +------ .../openAPIS/biometricAuthorization/index.tsx | 14 +++++-- .../apis/device/memory/offMemoryWarning.ts | 10 +---- .../api/apis/device/memory/onMemoryWarning.ts | 13 +----- .../src/api/apis/device/wifi/NativeWifi.ts | 40 +++++++++++++++++++ .../src/api/apis/device/wifi/connectWifi.ts | 5 ++- .../api/apis/device/wifi/getConnectedWifi.ts | 5 ++- .../src/api/apis/device/wifi/getWifiList.ts | 5 ++- .../src/api/apis/device/wifi/index.ts | 6 --- .../api/apis/device/wifi/offGetWifiList.ts | 5 ++- .../api/apis/device/wifi/offWifiConnected.ts | 5 ++- .../wifi/offWifiConnectedWithPartialInfo.ts | 5 ++- .../src/api/apis/device/wifi/onGetWifiList.ts | 5 ++- .../api/apis/device/wifi/onWifiConnected.ts | 5 ++- .../wifi/onWifiConnectedWithPartialInfo.ts | 5 ++- .../src/api/apis/device/wifi/startWifi.ts | 5 ++- .../src/api/apis/device/wifi/stopWifi.ts | 5 ++- .../src/api/apis/files/getFileInfo.ts | 1 - .../api/apis/harmony-native/ApiDecorator.ts | 11 +++++ .../src/api/apis/location/NativeLocation.ts | 40 +++++++++++++++++++ .../src/api/apis/location/chooseLocation.ts | 4 +- .../src/api/apis/location/getFuzzyLocation.ts | 5 ++- .../src/api/apis/location/getLocation.ts | 4 +- .../src/api/apis/location/index.ts | 7 ---- .../api/apis/location/offLocationChange.ts | 4 +- .../apis/location/offLocationChangeError.ts | 5 ++- .../src/api/apis/location/onLocationChange.ts | 4 +- .../apis/location/onLocationChangeError.ts | 5 ++- .../src/api/apis/location/openLocation.ts | 6 +-- .../api/apis/location/startLocationUpdate.ts | 5 ++- .../location/startLocationUpdateBackground.ts | 5 ++- .../api/apis/location/stopLocationUpdate.ts | 5 ++- .../src/api/apis/media/image/compressImage.ts | 3 +- .../media/video/saveVideoToPhotosAlbum.ts | 2 +- .../soter/checkIsSoterEnrolledInDevice.ts | 24 ++++++----- .../checkIsSupportSoterAuthentication.ts | 19 ++++----- .../soter/startSoterAuthentication.ts | 25 ++++++------ .../src/api/apis/ui/navigation-bar/index.ts | 2 - .../components/components-react/Map/Map.tsx | 18 +++++---- .../components-react/SameLayerRender.ts | 16 ++++++++ 40 files changed, 233 insertions(+), 139 deletions(-) create mode 100644 packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/NativeWifi.ts create mode 100644 packages/taro-platform-harmony-hybrid/src/api/apis/harmony-native/ApiDecorator.ts create mode 100644 packages/taro-platform-harmony-hybrid/src/api/apis/location/NativeLocation.ts create mode 100644 packages/taro-platform-harmony-hybrid/src/components/components-react/SameLayerRender.ts diff --git a/examples/mini-program-example/src/pages/api/media/camera/index.tsx b/examples/mini-program-example/src/pages/api/media/camera/index.tsx index 6d8e1fa5fb35..303095c4c5f1 100644 --- a/examples/mini-program-example/src/pages/api/media/camera/index.tsx +++ b/examples/mini-program-example/src/pages/api/media/camera/index.tsx @@ -1,6 +1,6 @@ import React from 'react' import Taro from '@tarojs/taro' -import { View, Button, Text } from '@tarojs/components' +import { View } from '@tarojs/components' import ButtonList from '@/components/buttonList' import './index.scss' import { TestConsole } from '@/util/util' @@ -47,9 +47,6 @@ export default class Index extends React.Component { TestConsole.consoleComplete.call(this, res, apiIndex) }, }) - .then((res) => { - TestConsole.consoleResult.call(this, res, apiIndex) - }) }, }, { @@ -71,9 +68,6 @@ export default class Index extends React.Component { TestConsole.consoleNormal('startRecord callback :', res) }, }) - .then((res) => { - TestConsole.consoleResult.call(this, res, apiIndex) - }) }, }, { @@ -92,9 +86,6 @@ export default class Index extends React.Component { TestConsole.consoleComplete.call(this, res, apiIndex) }, }) - .then((res) => { - TestConsole.consoleResult.call(this, res, apiIndex) - }) }, }, { @@ -114,9 +105,6 @@ export default class Index extends React.Component { TestConsole.consoleComplete.call(this, res, apiIndex) }, }) - .then((res) => { - TestConsole.consoleResult.call(this, res, apiIndex) - }) }, }, ], diff --git a/examples/mini-program-example/src/pages/api/openAPIS/biometricAuthorization/index.tsx b/examples/mini-program-example/src/pages/api/openAPIS/biometricAuthorization/index.tsx index 9223fb70ea3a..e3eeaf1064d4 100644 --- a/examples/mini-program-example/src/pages/api/openAPIS/biometricAuthorization/index.tsx +++ b/examples/mini-program-example/src/pages/api/openAPIS/biometricAuthorization/index.tsx @@ -1,6 +1,6 @@ import React from 'react' import Taro from '@tarojs/taro' -import { View, Text } from '@tarojs/components' +import { View } from '@tarojs/components' import ButtonList from '@/components/buttonList' import './index.scss' @@ -14,15 +14,21 @@ export default class Index extends React.Component { list: [ { id: 'startSoterAuthentication 指纹', - func: null, + func: () => { + this.startSoterAuthentication('fingerPrint') + }, }, { id: 'startSoterAuthentication 人脸', - func: null, + func: () => { + this.startSoterAuthentication('facial') + }, }, { id: 'startSoterAuthentication 声纹', - func: null, + func: () => { + this.startSoterAuthentication('speech') + }, }, { id: 'checkIsSupportSoterAuthentication', diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/device/memory/offMemoryWarning.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/device/memory/offMemoryWarning.ts index 8766f8b4558c..e03304194f0b 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/device/memory/offMemoryWarning.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/device/memory/offMemoryWarning.ts @@ -1,17 +1,11 @@ import Taro from '@tarojs/taro' -import native from '../../NativeApi' - /** * 取消监听内存不足告警事件 * * @canUse offMemoryWarning * @null_implementation */ -export const offMemoryWarning: typeof Taro.offMemoryWarning = (callback) => { - // @ts-ignore - if (native[offMemoryWarning]) { - // @ts-ignore - native.offMemoryWarning(callback) - } +export const offMemoryWarning: typeof Taro.offMemoryWarning = (_callback) => { + } diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/device/memory/onMemoryWarning.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/device/memory/onMemoryWarning.ts index 9f0b7022a212..3fe3f5d3dc9d 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/device/memory/onMemoryWarning.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/device/memory/onMemoryWarning.ts @@ -6,15 +6,6 @@ import Taro from '@tarojs/taro' * @canUse onMemoryWarning * @null_implementation */ -export const onMemoryWarning: typeof Taro.onMemoryWarning = (callback) => { - // @ts-ignore - if (native[onMemoryWarning]) { - // @ts-ignore - native.onMemoryWarning((res: any) => { - const ret: Taro.onMemoryWarning.CallbackResult = { - level: res.level, - } - callback(ret) - }) - } +export const onMemoryWarning: typeof Taro.onMemoryWarning = (_callback) => { + } diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/NativeWifi.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/NativeWifi.ts new file mode 100644 index 000000000000..3092dcc2d9c5 --- /dev/null +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/NativeWifi.ts @@ -0,0 +1,40 @@ +import { asyncAndNotRelease, asyncAndRelease } from '../../harmony-native/ApiDecorator' + +class NativeWifi { + @asyncAndRelease + connectWifi (_options: any):void {} + + @asyncAndRelease + getConnectedWifi (_options: any):void {} + + @asyncAndRelease + getWifiList (_options: any):void {} + + @asyncAndRelease + offGetWifiList (_options: any):void {} + + @asyncAndRelease + offWifiConnected (_options: any):void {} + + @asyncAndRelease + offWifiConnectedWithPartialInfo (_options: any):void {} + + @asyncAndNotRelease + onGetWifiList (_options: any):void {} + + @asyncAndNotRelease + onWifiConnected (_options: any):void {} + + @asyncAndNotRelease + onWifiConnectedWithPartialInfo (_options: any):void {} + + @asyncAndRelease + startWifi (_options: any):void {} + + @asyncAndRelease + stopWifi (_options: any):void {} +} + +const nativeWifi = new NativeWifi() + +export default nativeWifi \ No newline at end of file diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/connectWifi.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/connectWifi.ts index 869e6d73a97f..7a2c89580b91 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/connectWifi.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/connectWifi.ts @@ -2,6 +2,8 @@ import Taro from '@tarojs/taro' import { getParameterError, shouldBeObject } from 'src/api/apis/utils' import { MethodHandler } from 'src/api/apis/utils/handler' +import nativeWifi from './NativeWifi' + /** * 连接 Wi-Fi * @@ -63,8 +65,7 @@ export const connectWifi: typeof Taro.connectWifi = (options) => { ) } - // @ts-ignore - native.connectWifi({ + nativeWifi.connectWifi({ SSID: SSID, password: password, BSSID: BSSID, diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/getConnectedWifi.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/getConnectedWifi.ts index 9d542268f1b1..6dd8e31adab1 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/getConnectedWifi.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/getConnectedWifi.ts @@ -2,6 +2,8 @@ import Taro from '@tarojs/taro' import { shouldBeObject } from 'src/api/apis/utils' import { MethodHandler } from 'src/api/apis/utils/handler' +import nativeWifi from './NativeWifi' + /** * 获取已连接中的 Wi-Fi 信息 * @@ -20,8 +22,7 @@ export const getConnectedWifi: typeof Taro.getConnectedWifi = (options) => { const handle = new MethodHandler({ name, success, fail, complete }) return new Promise((resolve, reject) => { - // @ts-ignore - native.getConnectedWifi({ + nativeWifi.getConnectedWifi({ success: (res: any) => { handle.success(res, { resolve, reject }) }, diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/getWifiList.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/getWifiList.ts index 4182e9ff1eb5..160779d6694c 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/getWifiList.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/getWifiList.ts @@ -2,6 +2,8 @@ import Taro from '@tarojs/taro' import { shouldBeObject } from 'src/api/apis/utils' import { MethodHandler } from 'src/api/apis/utils/handler' +import nativeWifi from './NativeWifi' + /** * 请求获取 Wi-Fi 列表 * @@ -19,8 +21,7 @@ export const getWifiList: typeof Taro.getWifiList = (options) => { const handle = new MethodHandler({ name, success, fail, complete }) return new Promise((resolve, reject) => { - // @ts-ignore - native.getWifiList({ + nativeWifi.getWifiList({ success: (res: any) => { handle.success(res, { resolve, reject }) }, diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/index.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/index.ts index 0b56be887d9f..6e96662f2ce1 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/index.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/index.ts @@ -1,8 +1,3 @@ -/** - * 设置 wifiList 中 AP 的相关信息 - * - * @canNotUse setWifiList - */ export * from './connectWifi' export * from './getConnectedWifi' export * from './getWifiList' @@ -14,7 +9,6 @@ export * from './onWifiConnected' export * from './onWifiConnectedWithPartialInfo' export * from './startWifi' export * from './stopWifi' -export { setWifiList } from '@tarojs/taro-h5' /** * Wifi 信息(native 返回) diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/offGetWifiList.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/offGetWifiList.ts index b5a64dd555f3..a987c74bf450 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/offGetWifiList.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/offGetWifiList.ts @@ -1,6 +1,8 @@ import Taro from '@tarojs/taro' import { shouldBeFunction } from 'src/api/apis/utils' +import nativeWifi from './NativeWifi' + /** * 取消监听获取到 Wi-Fi 列表数据事件 * @@ -17,6 +19,5 @@ export const offGetWifiList: typeof Taro.offGetWifiList = (callback) => { return } - // @ts-ignore - native.offGetWifiList(callback) + nativeWifi.offGetWifiList(callback) } diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/offWifiConnected.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/offWifiConnected.ts index 02dfdd6464f6..3a8fc4addabd 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/offWifiConnected.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/offWifiConnected.ts @@ -1,6 +1,8 @@ import Taro from '@tarojs/taro' import { shouldBeFunction } from 'src/api/apis/utils' +import nativeWifi from './NativeWifi' + /** * 取消监听连接上 Wi-Fi 的事件 * @@ -17,8 +19,7 @@ export const offWifiConnected: typeof Taro.offWifiConnected = (callback) => { return } - // @ts-ignore - native.offWifiConnected((res: any) => { + nativeWifi.offWifiConnected((res: any) => { const result: Taro.onWifiConnected.CallbackResult = { /** Wi-Fi 信息 */ wifi: { diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/offWifiConnectedWithPartialInfo.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/offWifiConnectedWithPartialInfo.ts index 9a862115f830..745ef0583af9 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/offWifiConnectedWithPartialInfo.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/offWifiConnectedWithPartialInfo.ts @@ -1,6 +1,8 @@ import Taro from '@tarojs/taro' import { shouldBeFunction } from 'src/api/apis/utils' +import nativeWifi from './NativeWifi' + /** * 取消监听连接上 Wi-Fi 的事件 * @@ -17,8 +19,7 @@ export const offWifiConnectedWithPartialInfo: typeof Taro.offWifiConnectedWithPa return } - // @ts-ignore - native.offWifiConnectedWithPartialInfo((res: any) => { + nativeWifi.offWifiConnectedWithPartialInfo((res: any) => { const result: Taro.onWifiConnectedWithPartialInfo.CallbackResult = { /** 只包含 SSID 属性的 WifiInfo 对象 */ wifi: { SSID: res.wifi.SSID }, diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/onGetWifiList.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/onGetWifiList.ts index 3d93ccedc90a..ece04c16e83b 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/onGetWifiList.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/onGetWifiList.ts @@ -1,6 +1,8 @@ import Taro from '@tarojs/taro' import { shouldBeFunction } from 'src/api/apis/utils' +import nativeWifi from './NativeWifi' + /** * 监听获取到 Wi-Fi 列表数据事件 * @@ -18,6 +20,5 @@ export const onGetWifiList: typeof Taro.onGetWifiList = (callback) => { return } - // @ts-ignore - native.onGetWifiList(callback) + nativeWifi.onGetWifiList(callback) } diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/onWifiConnected.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/onWifiConnected.ts index 9b5e5378598b..d75364846cc4 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/onWifiConnected.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/onWifiConnected.ts @@ -1,6 +1,8 @@ import Taro from '@tarojs/taro' import { shouldBeFunction } from 'src/api/apis/utils' +import nativeWifi from './NativeWifi' + /** * 监听连接上 Wi-Fi 的事件 * @@ -18,8 +20,7 @@ export const onWifiConnected: typeof Taro.onWifiConnected = (callback) => { return } - // @ts-ignore - native.onWifiConnected((res: any) => { + nativeWifi.onWifiConnected((res: any) => { const result: Taro.onWifiConnected.CallbackResult = { /** Wi-Fi 信息 */ wifi: { diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/onWifiConnectedWithPartialInfo.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/onWifiConnectedWithPartialInfo.ts index aae6f4df6cfc..0008851e8d46 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/onWifiConnectedWithPartialInfo.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/onWifiConnectedWithPartialInfo.ts @@ -1,6 +1,8 @@ import Taro from '@tarojs/taro' import { shouldBeFunction } from 'src/api/apis/utils' +import nativeWifi from './NativeWifi' + /** * 监听连接上 Wi-Fi 的事件 * @@ -18,8 +20,7 @@ export const onWifiConnectedWithPartialInfo: typeof Taro.onWifiConnectedWithPart return } - // @ts-ignore - native.onWifiConnectedWithPartialInfo((res: any) => { + nativeWifi.onWifiConnectedWithPartialInfo((res: any) => { const result: Taro.onWifiConnectedWithPartialInfo.CallbackResult = { /** 只包含 SSID 属性的 WifiInfo 对象 */ wifi: { SSID: res.wifi.SSID }, diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/startWifi.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/startWifi.ts index b1bae7d5eb7d..f86ceda9cea0 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/startWifi.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/startWifi.ts @@ -2,6 +2,8 @@ import Taro from '@tarojs/taro' import { shouldBeObject } from 'src/api/apis/utils' import { MethodHandler } from 'src/api/apis/utils/handler' +import nativeWifi from './NativeWifi' + /** * 初始化 Wi-Fi 模块 * @@ -19,8 +21,7 @@ export const startWifi: typeof Taro.startWifi = (options) => { const handle = new MethodHandler({ name, success, fail, complete }) return new Promise((resolve, reject) => { - // @ts-ignore - native.startWifi({ + nativeWifi.startWifi({ success: (res: any) => { handle.success(res, { resolve, reject }) }, diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/stopWifi.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/stopWifi.ts index b2b69c934e6c..6032cfb0198e 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/stopWifi.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/stopWifi.ts @@ -2,6 +2,8 @@ import Taro from '@tarojs/taro' import { shouldBeObject } from 'src/api/apis/utils' import { MethodHandler } from 'src/api/apis/utils/handler' +import nativeWifi from './NativeWifi' + /** * 关闭 Wi-Fi 模块 * @@ -19,8 +21,7 @@ export const stopWifi: typeof Taro.stopWifi = (options) => { const handle = new MethodHandler({ name, success, fail, complete }) return new Promise((resolve, reject) => { - // @ts-ignore - native.stopWifi({ + nativeWifi.stopWifi({ success: (res: any) => { handle.success(res, { resolve, reject }) }, diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/files/getFileInfo.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/files/getFileInfo.ts index d6c60bad2fdb..bc93b9943ca9 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/files/getFileInfo.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/files/getFileInfo.ts @@ -42,7 +42,6 @@ export const getFileInfo: typeof Taro.getFileInfo = (options) => { return new Promise( (resolve, reject) => { - // @ts-ignore native.getFileInfo({ filePath: filePath, digestAlgorithm: digestAlgorithm, diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/harmony-native/ApiDecorator.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/harmony-native/ApiDecorator.ts new file mode 100644 index 000000000000..06badb60464c --- /dev/null +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/harmony-native/ApiDecorator.ts @@ -0,0 +1,11 @@ +// @ts-ignore +export const syncAndRelease = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: false, autoRelease: true }) || (target => target) + +// @ts-ignore +// const syncAndNotRelease = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: false, autoRelease: false }) || (target => target) + +// @ts-ignore +export const asyncAndRelease = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: true, autoRelease: true }) || (target => target) + +// @ts-ignore +export const asyncAndNotRelease = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: true, autoRelease: false }) || (target => target) \ No newline at end of file diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/location/NativeLocation.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/location/NativeLocation.ts new file mode 100644 index 000000000000..ee93734f80ce --- /dev/null +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/location/NativeLocation.ts @@ -0,0 +1,40 @@ +import { asyncAndNotRelease, asyncAndRelease } from '../harmony-native/ApiDecorator' + +class NativeLocation { + @asyncAndRelease + chooseLocation (_options: any):void {} + + @asyncAndRelease + openLocation (_options: any):void {} + + @asyncAndRelease + getFuzzyLocation (_options: any):void {} + + @asyncAndRelease + getLocation (_options: any):void {} + + @asyncAndNotRelease + onLocationChange (_options: any):void {} + + @asyncAndRelease + offLocationChange (_options: any):void {} + + @asyncAndNotRelease + onLocationChangeError (_options: any):void {} + + @asyncAndRelease + offLocationChangeError (_options: any):void {} + + @asyncAndRelease + startLocationUpdate (_options: any):void {} + + @asyncAndRelease + startLocationUpdateBackground (_options: any):void {} + + @asyncAndRelease + stopLocationUpdate (_options: any):void {} +} + +const nativeLocation = new NativeLocation() + +export default nativeLocation \ No newline at end of file diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/location/chooseLocation.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/location/chooseLocation.ts index 55f11f4605dc..359ce2779b55 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/location/chooseLocation.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/location/chooseLocation.ts @@ -1,8 +1,8 @@ import Taro from '@tarojs/taro' -import native from '../NativeApi' import { shouldBeObject } from '../utils' import { MethodHandler } from '../utils/handler' +import nativeLocation from './NativeLocation' /** * 打开地图选择位置。 @@ -27,7 +27,7 @@ export const chooseLocation: typeof Taro.chooseLocation = (options = {}) => { } = options const handle = new MethodHandler({ name, success, fail, complete }) return new Promise((resolve, reject) => { - native.chooseLocation({ + nativeLocation.chooseLocation({ latitude, longitude, success: (res: any) => { diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/location/getFuzzyLocation.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/location/getFuzzyLocation.ts index 767fcde3d750..afccc9e77ca6 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/location/getFuzzyLocation.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/location/getFuzzyLocation.ts @@ -1,8 +1,9 @@ import Taro from '@tarojs/taro' -import native from '../NativeApi' import { shouldBeObject } from '../utils' import { MethodHandler } from '../utils/handler' +import nativeLocation from './NativeLocation' + /** * 获取当前的模糊地理位置 * @@ -26,7 +27,7 @@ export const getFuzzyLocation: typeof Taro.getFuzzyLocation = (options) => { const handle = new MethodHandler({ name, success, fail, complete }) return new Promise((resolve, reject) => { - native.getLocation({ + nativeLocation.getLocation({ type: type, isHighAccuracy: false, highAccuracyExpireTime: undefined, diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/location/getLocation.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/location/getLocation.ts index e5cd8d510373..56a6bee7e11b 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/location/getLocation.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/location/getLocation.ts @@ -1,8 +1,8 @@ import Taro from '@tarojs/taro' -import native from '../NativeApi' import { shouldBeObject } from '../utils' import { MethodHandler } from '../utils/handler' +import nativeLocation from './NativeLocation' /** * 获取当前的地理位置、速度 @@ -30,7 +30,7 @@ export const getLocation: typeof Taro.getLocation = (options) => { const handle = new MethodHandler({ name, success, fail, complete }) return new Promise((resolve, reject) => { - native.getLocation({ + nativeLocation.getLocation({ isHighAccuracy: isHighAccuracy, highAccuracyExpireTime: highAccuracyExpireTime, type: type, diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/location/index.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/location/index.ts index 6c317ba53535..e9cc29af56e8 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/location/index.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/location/index.ts @@ -9,10 +9,3 @@ export * from './openLocation' export * from './startLocationUpdate' export * from './startLocationUpdateBackground' export * from './stopLocationUpdate' - -/** - * 打开POI列表选择位置 - * - * @canNotUse choosePoi - */ -export { choosePoi } from '@tarojs/taro-h5' diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/location/offLocationChange.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/location/offLocationChange.ts index 77f4ae460a74..46dcd97ef28e 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/location/offLocationChange.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/location/offLocationChange.ts @@ -1,7 +1,7 @@ import Taro from '@tarojs/taro' import { shouldBeFunction } from 'src/api/apis/utils' -import native from '../NativeApi' +import nativeLocation from './NativeLocation' /** * 取消监听实时地理位置变化事件 @@ -17,7 +17,7 @@ export const offLocationChange: typeof Taro.offLocationChange = (callback) => { console.error(res.errMsg) return } - native.offLocationChange((res: any) => { + nativeLocation.offLocationChange((res: any) => { const cbResult: Taro.onLocationChange.CallbackResult = { /** 位置的精确度 */ accuracy: res.accuracy, diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/location/offLocationChangeError.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/location/offLocationChangeError.ts index 85a2b13c3355..97d3ce399f41 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/location/offLocationChangeError.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/location/offLocationChangeError.ts @@ -1,6 +1,8 @@ import Taro from '@tarojs/taro' import { shouldBeFunction } from 'src/api/apis/utils' +import nativeLocation from './NativeLocation' + /** * 取消监听持续定位接口返回失败时触发 * @@ -15,6 +17,5 @@ export const offLocationChangeError: typeof Taro.offLocationChangeError = (callb console.error(res.errMsg) return } - // @ts-ignore - native.offLocationChangeError(callback) + nativeLocation.offLocationChangeError(callback) } diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/location/onLocationChange.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/location/onLocationChange.ts index cc0f7aea604a..06528b0a2bb9 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/location/onLocationChange.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/location/onLocationChange.ts @@ -1,7 +1,7 @@ import Taro from '@tarojs/taro' import { shouldBeFunction } from 'src/api/apis/utils' -import native from '../NativeApi' +import nativeLocation from './NativeLocation' /** * 监听实时地理位置变化事件 @@ -18,7 +18,7 @@ export const onLocationChange: typeof Taro.onLocationChange = (callback) => { console.error(res.errMsg) return } - native.onLocationChange((res: any) => { + nativeLocation.onLocationChange((res: any) => { const result: Taro.onLocationChange.CallbackResult = { /** 位置的精确度 */ accuracy: res.accuracy, diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/location/onLocationChangeError.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/location/onLocationChangeError.ts index f64044d62b00..1708ae2650f9 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/location/onLocationChangeError.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/location/onLocationChangeError.ts @@ -1,6 +1,8 @@ import Taro from '@tarojs/taro' import { shouldBeFunction } from 'src/api/apis/utils' +import nativeLocation from './NativeLocation' + /** * 监听持续定位接口返回失败时触发 * @@ -16,6 +18,5 @@ export const onLocationChangeError: typeof Taro.onLocationChangeError = (callbac console.error(res.errMsg) return } - // @ts-ignore - native.onLocationChangeError(callback) + nativeLocation.onLocationChangeError(callback) } diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/location/openLocation.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/location/openLocation.ts index de0a7e91add9..62d7f6cf84c9 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/location/openLocation.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/location/openLocation.ts @@ -1,8 +1,8 @@ import Taro from '@tarojs/taro' -import native from '../NativeApi' import { shouldBeObject } from '../utils' import { MethodHandler } from '../utils/handler' +import nativeLocation from './NativeLocation' /** * 打开地图查看位置。(暂不支持scale入参) @@ -27,7 +27,7 @@ export const openLocation: typeof Taro.openLocation = (options) => { } = options const handle = new MethodHandler({ name: 'openLocation', success, fail, complete }) return new Promise((resolve, reject) => { - native.openLocation({ + nativeLocation.openLocation({ latitude, longitude, address, @@ -40,4 +40,4 @@ export const openLocation: typeof Taro.openLocation = (options) => { } }) }) -} +} \ No newline at end of file diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/location/startLocationUpdate.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/location/startLocationUpdate.ts index 72c1b5c24488..0aac4f48a794 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/location/startLocationUpdate.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/location/startLocationUpdate.ts @@ -2,6 +2,8 @@ import Taro from '@tarojs/taro' import { shouldBeObject } from 'src/api/apis/utils' import { MethodHandler } from 'src/api/apis/utils/handler' +import nativeLocation from './NativeLocation' + /** * 开启小程序进入前台时接收位置消息 * @@ -17,8 +19,7 @@ export const startLocationUpdate: typeof Taro.startLocationUpdate = (options) => } const { success, fail, complete } = options || {} const handle = new MethodHandler({ name, success, fail, complete }) - // @ts-ignore - native.startLocationUpdate({ + nativeLocation.startLocationUpdate({ success: (res: any) => { handle.success(res) }, diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/location/startLocationUpdateBackground.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/location/startLocationUpdateBackground.ts index a7210588c2c4..df130557e3b6 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/location/startLocationUpdateBackground.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/location/startLocationUpdateBackground.ts @@ -2,6 +2,8 @@ import Taro from '@tarojs/taro' import { shouldBeObject } from 'src/api/apis/utils' import { MethodHandler } from 'src/api/apis/utils/handler' +import nativeLocation from './NativeLocation' + /** * 开启小程序进入前后台时均接收位置消息 * @@ -17,8 +19,7 @@ export const startLocationUpdateBackground: typeof Taro.startLocationUpdateBackg } const { success, fail, complete } = options || {} const handle = new MethodHandler({ name, success, fail, complete }) - // @ts-ignore - native.startLocationUpdateBackground({ + nativeLocation.startLocationUpdateBackground({ success: (res: any) => { handle.success(res) }, diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/location/stopLocationUpdate.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/location/stopLocationUpdate.ts index 059188966bdc..48984f037fde 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/location/stopLocationUpdate.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/location/stopLocationUpdate.ts @@ -2,6 +2,8 @@ import Taro from '@tarojs/taro' import { shouldBeObject } from 'src/api/apis/utils' import { MethodHandler } from 'src/api/apis/utils/handler' +import nativeLocation from './NativeLocation' + /** * 关闭监听实时位置变化,前后台都停止消息接收 * @@ -17,8 +19,7 @@ export const stopLocationUpdate: typeof Taro.stopLocationUpdate = (options) => { } const { success, fail, complete } = options || {} const handle = new MethodHandler({ name, success, fail, complete }) - // @ts-ignore - native.stopLocationUpdate({ + nativeLocation.stopLocationUpdate({ success: (res: any) => { handle.success(res) }, diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/media/image/compressImage.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/media/image/compressImage.ts index 4703679cfe70..9adf900b336b 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/media/image/compressImage.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/media/image/compressImage.ts @@ -2,6 +2,8 @@ import Taro from '@tarojs/taro' import { getParameterError, shouldBeObject } from 'src/api/apis/utils' import { MethodHandler } from 'src/api/apis/utils/handler' +import native from '../../NativeApi' + /** * 压缩图片接口,可选压缩质量 * @@ -40,7 +42,6 @@ export const compressImage: typeof Taro.compressImage = (options) => { } return new Promise((resolve, reject) => { - // @ts-ignore native.compressImage({ src: src, quality: quality, diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/media/video/saveVideoToPhotosAlbum.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/media/video/saveVideoToPhotosAlbum.ts index bbac544e69eb..44d157b26a10 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/media/video/saveVideoToPhotosAlbum.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/media/video/saveVideoToPhotosAlbum.ts @@ -1,5 +1,6 @@ import Taro from '@tarojs/api' +import native from '../../NativeApi' import { getParameterError, shouldBeObject } from '../../utils' import { MethodHandler } from '../../utils/handler' @@ -33,7 +34,6 @@ export const saveVideoToPhotosAlbum: typeof Taro.saveVideoToPhotosAlbum = (optio } return new Promise((resolve, reject) => { - // @ts-ignore native.saveVideoToPhotosAlbum({ filePath: filePath, success: (res: any) => { diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/open-api/soter/checkIsSoterEnrolledInDevice.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/open-api/soter/checkIsSoterEnrolledInDevice.ts index 592461caaffb..105f79c2f9b2 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/open-api/soter/checkIsSoterEnrolledInDevice.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/open-api/soter/checkIsSoterEnrolledInDevice.ts @@ -1,5 +1,6 @@ import Taro from '@tarojs/api' +import native from '../../NativeApi' import { getParameterError, shouldBeObject } from '../../utils' import { MethodHandler } from '../../utils/handler' @@ -28,12 +29,12 @@ export const checkIsSoterEnrolledInDevice: typeof Taro.checkIsSoterEnrolledInDev errMsg?: string }>({ name, success, fail, complete }) - if (typeof checkAuthMode !== 'object') { + if (typeof checkAuthMode !== 'string') { return handle.fail( { errMsg: getParameterError({ para: 'checkAuthMode', - correct: 'object', + correct: 'string', wrong: checkAuthMode, }), }, @@ -41,15 +42,16 @@ export const checkIsSoterEnrolledInDevice: typeof Taro.checkIsSoterEnrolledInDev ) } - // @ts-ignore - const ret = native.checkIsSoterEnrolledInDevice({ - success: (res: any) => { - return handle.success(res) - }, - fail: (err: any) => { - return handle.fail(err) - }, + return new Promise((resolve, reject) => { + native.checkIsSupportSoterAuthentication({ + checkAuthMode: checkAuthMode, + success: (res: any) => { + handle.success(res, { resolve, reject }) + }, + fail: (err: any) => { + handle.fail(err, { resolve, reject }) + }, + }) }) - return ret }) } diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/open-api/soter/checkIsSupportSoterAuthentication.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/open-api/soter/checkIsSupportSoterAuthentication.ts index 0b12d9133c17..46265ced6f63 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/open-api/soter/checkIsSupportSoterAuthentication.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/open-api/soter/checkIsSupportSoterAuthentication.ts @@ -1,5 +1,6 @@ import Taro from '@tarojs/api' +import native from '../../NativeApi' import { shouldBeObject } from '../../utils' import { MethodHandler } from '../../utils/handler' @@ -26,14 +27,14 @@ export const checkIsSupportSoterAuthentication: typeof Taro.checkIsSupportSoterA errMsg?: string }>({ name, success, fail, complete }) - // @ts-ignore - const ret = native.checkIsSupportSoterAuthentication({ - success: (res: any) => { - return handle.success(res) - }, - fail: (err: any) => { - return handle.fail(err) - }, + return new Promise((resolve, reject) => { + native.checkIsSupportSoterAuthentication({ + success: (res: any) => { + handle.success(res, { resolve, reject }) + }, + fail: (err: any) => { + handle.fail(err, { resolve, reject }) + }, + }) }) - return ret } diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/open-api/soter/startSoterAuthentication.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/open-api/soter/startSoterAuthentication.ts index f425f32dbd33..0ceca95827cd 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/open-api/soter/startSoterAuthentication.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/open-api/soter/startSoterAuthentication.ts @@ -1,5 +1,6 @@ import Taro from '@tarojs/api' +import native from '../../NativeApi' import { getParameterError, shouldBeObject } from '../../utils' import { MethodHandler } from '../../utils/handler' @@ -50,17 +51,17 @@ export const startSoterAuthentication: typeof Taro.startSoterAuthentication = (o }) } - // @ts-ignore - const ret = native.startSoterAuthentication({ - phoneNumber: challenge, - requestAuthModes: requestAuthModes, - authContent: authContent, - success: (res: any) => { - return handle.success(res) - }, - fail: (err: any) => { - return handle.fail(err) - }, + return new Promise((resolve, reject) => { + native.startSoterAuthentication({ + challenge: challenge, + requestAuthModes: requestAuthModes, + authContent: authContent, + success: (res: any) => { + handle.success(res, { resolve, reject }) + }, + fail: (err: any) => { + handle.fail(err, { resolve, reject }) + }, + }) }) - return ret } diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/ui/navigation-bar/index.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/ui/navigation-bar/index.ts index da62f6f7d233..73bd5d1beb0c 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/ui/navigation-bar/index.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/ui/navigation-bar/index.ts @@ -41,7 +41,6 @@ export const showNavigationBarLoading: typeof Taro.showNavigationBarLoading = (o const { success, fail, complete } = (options || {}) as Exclude const handle = new MethodHandler({ name: 'showNavigationBarLoading', success, fail, complete }) - // @ts-ignore native.showNavigationBarLoading() return handle.success() } @@ -55,7 +54,6 @@ export const hideNavigationBarLoading: typeof Taro.hideNavigationBarLoading = (o const { success, fail, complete } = (options || {}) as Exclude const handle = new MethodHandler({ name: 'hideNavigationBarLoading', success, fail, complete }) - // @ts-ignore native.hideNavigationBarLoading() return handle.success() } diff --git a/packages/taro-platform-harmony-hybrid/src/components/components-react/Map/Map.tsx b/packages/taro-platform-harmony-hybrid/src/components/components-react/Map/Map.tsx index 4b3be67f64fc..769265b27939 100644 --- a/packages/taro-platform-harmony-hybrid/src/components/components-react/Map/Map.tsx +++ b/packages/taro-platform-harmony-hybrid/src/components/components-react/Map/Map.tsx @@ -1,5 +1,7 @@ import React from 'react' +import sameLayerRender, { clearJsObj } from '../SameLayerRender' + interface marker { latitude: number longitude: number @@ -45,12 +47,10 @@ interface IProps extends React.HTMLAttributes { class HosMap extends React.Component { private componentId: string + private nativeRenderArgs: object constructor (props: IProps) { super(props) this.componentId = `HosMap_${Math.floor(Math.random() * 100000)}_${Date.now()}` - } - - componentDidMount () { const { latitude, longitude, @@ -77,8 +77,7 @@ class HosMap extends React.Component { onError, onAnchorPointTap, } = this.props - - const args = { + this.nativeRenderArgs = { componentId: this.componentId, latitude, longitude, @@ -105,9 +104,12 @@ class HosMap extends React.Component { onError: onError, onMyLocationButtonClick: onAnchorPointTap, } + sameLayerRender.transferSameLayerArgs(this.nativeRenderArgs) + } - // @ts-ignore 调用JSB方法传递原生组件数据 - window.JSBridge && window.JSBridge.transferSameLayerArgs(args) + componentWillUnmount (): void { + // 释放JS侧存储的渲染参数 + clearJsObj(this.nativeRenderArgs) } render (): React.ReactNode { @@ -123,4 +125,4 @@ class HosMap extends React.Component { } } -export default HosMap +export default HosMap \ No newline at end of file diff --git a/packages/taro-platform-harmony-hybrid/src/components/components-react/SameLayerRender.ts b/packages/taro-platform-harmony-hybrid/src/components/components-react/SameLayerRender.ts new file mode 100644 index 000000000000..9727d585ae03 --- /dev/null +++ b/packages/taro-platform-harmony-hybrid/src/components/components-react/SameLayerRender.ts @@ -0,0 +1,16 @@ +// @ts-ignore +const asyncAndNotRelease = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: true, autoRelease: false }) || (target => target) + +// @ts-ignore 释放JS侧存储的参数对象 +export function clearJsObj (object: object) { + // @ts-ignore + window.MethodChannel && window.MethodChannel.unRegisterArgStub(object) +} + +class SameLayerRender { + @asyncAndNotRelease + transferSameLayerArgs (_options: object):void {} +} + +const sameLayerRender = new SameLayerRender() +export default sameLayerRender \ No newline at end of file