Skip to content

Commit

Permalink
fix: [harmony-hybrid]修复部分API调用原生报错问题
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyan428820 committed Jun 11, 2024
1 parent 50bd2a9 commit 73f86b8
Show file tree
Hide file tree
Showing 42 changed files with 263 additions and 248 deletions.
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)
})
},
},
{
Expand All @@ -71,9 +68,6 @@ export default class Index extends React.Component {
TestConsole.consoleNormal('startRecord callback :', res)
},
})
.then((res) => {
TestConsole.consoleResult.call(this, res, apiIndex)
})
},
},
{
Expand All @@ -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)
})
},
},
{
Expand All @@ -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)
})
},
},
],
Expand Down
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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',
Expand Down
82 changes: 32 additions & 50 deletions packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
// import {timeLog} from "./NativeApiLog";
import { syncApiCache } from './harmony-native/ApiCache'
import { asyncAndNotRelease, asyncAndRelease, syncAndRelease } from './harmony-native/ApiDecorator'
import { storageCacheAndSyncProxy } from './harmony-native/StorageCacheAndSyncProxy'
import { NativeDataChangeListener, SyncCacheProxyHandler } from './NativeApiSyncCacheProxy'
// @ts-ignore
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
const asyncAndRelease = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: true, autoRelease: true }) || (target => target)
// @ts-ignore
const asyncAndNotRelease = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: true, autoRelease: false }) || (target => target)

// export let judgeUseAxios = false
export class NativeApi {
Expand All @@ -20,18 +13,6 @@ export class NativeApi {
registerNativeListener (listener: NativeDataChangeListener | null): void {
}

// @ts-ignore
@(syncAndRelease)
openLocation (options: any): any {
return options
}

// @ts-ignore
@(syncAndRelease)
chooseLocation (options: any): any {
return options
}

@syncApiCache()
@(syncAndRelease)
getWindowInfo (): any {}
Expand Down Expand Up @@ -164,6 +145,37 @@ export class NativeApi {
return options
}

@(asyncAndRelease)
saveVideoToPhotosAlbum (options: any): any {
return options
}

@(asyncAndRelease)
compressImage (options: any): any {
return options
}

@(asyncAndRelease)
showNavigationBarLoading (): void {}

@(asyncAndRelease)
hideNavigationBarLoading (): void {}

@(asyncAndRelease)
startSoterAuthentication (options: any): any {
return options
}

@(asyncAndRelease)
checkIsSupportSoterAuthentication (options: any): any {
return options
}

@(asyncAndRelease)
checkIsSoterEnrolledInDevice (options: any): any {
return options
}

// @ts-ignore
@(syncAndRelease)
chooseMediaAssets (options: any): any {
Expand Down Expand Up @@ -194,12 +206,6 @@ export class NativeApi {
return options
}

// @ts-ignore
@(syncAndRelease)
getLocation (options: any): any {
return options
}

// @ts-ignore
@(syncAndRelease)
openDocument (options: any): any {
Expand Down Expand Up @@ -254,18 +260,6 @@ export class NativeApi {
return options
}

// @ts-ignore
@(asyncAndNotRelease)
onLocationChange (options: any): any {
return options
}

// @ts-ignore
@(syncAndRelease)
offLocationChange (options: any): any {
return options
}

// @ts-ignore
@(syncAndRelease)
setScreenBrightness (options: any): any {
Expand All @@ -278,18 +272,6 @@ export class NativeApi {
return options
}

// @ts-ignore
@(asyncAndNotRelease)
onMemoryWarning (options: any): any {
return options
}

// @ts-ignore
@(syncAndRelease)
offMemoryWarning (options: any): any {
return options
}

// @ts-ignore
@(syncAndRelease)
hideKeyboard (options?: any): any {
Expand Down
Original file line number Diff line number Diff line change
@@ -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) => {

}
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {

}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -63,8 +65,7 @@ export const connectWifi: typeof Taro.connectWifi = (options) => {
)
}

// @ts-ignore
native.connectWifi({
nativeWifi.connectWifi({
SSID: SSID,
password: password,
BSSID: BSSID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 信息
*
Expand All @@ -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 })
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 列表
*
Expand All @@ -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 })
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* 设置 wifiList 中 AP 的相关信息
*
* @canNotUse setWifiList
*/
export * from './connectWifi'
export * from './getConnectedWifi'
export * from './getWifiList'
Expand All @@ -14,7 +9,6 @@ export * from './onWifiConnected'
export * from './onWifiConnectedWithPartialInfo'
export * from './startWifi'
export * from './stopWifi'
export { setWifiList } from '@tarojs/taro-h5'

/**
* Wifi 信息(native 返回)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Taro from '@tarojs/taro'
import { shouldBeFunction } from 'src/api/apis/utils'

import nativeWifi from './NativeWifi'

/**
* 取消监听获取到 Wi-Fi 列表数据事件
*
Expand All @@ -17,6 +19,5 @@ export const offGetWifiList: typeof Taro.offGetWifiList = (callback) => {
return
}

// @ts-ignore
native.offGetWifiList(callback)
nativeWifi.offGetWifiList(callback)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Taro from '@tarojs/taro'
import { shouldBeFunction } from 'src/api/apis/utils'

import nativeWifi from './NativeWifi'

/**
* 取消监听连接上 Wi-Fi 的事件
*
Expand All @@ -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: {
Expand Down
Loading

0 comments on commit 73f86b8

Please sign in to comment.