Skip to content

Commit 73f86b8

Browse files
committed
fix: [harmony-hybrid]修复部分API调用原生报错问题
1 parent 50bd2a9 commit 73f86b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+263
-248
lines changed

examples/mini-program-example/src/pages/api/media/camera/index.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22
import Taro from '@tarojs/taro'
3-
import { View, Button, Text } from '@tarojs/components'
3+
import { View } from '@tarojs/components'
44
import ButtonList from '@/components/buttonList'
55
import './index.scss'
66
import { TestConsole } from '@/util/util'
@@ -47,9 +47,6 @@ export default class Index extends React.Component {
4747
TestConsole.consoleComplete.call(this, res, apiIndex)
4848
},
4949
})
50-
.then((res) => {
51-
TestConsole.consoleResult.call(this, res, apiIndex)
52-
})
5350
},
5451
},
5552
{
@@ -71,9 +68,6 @@ export default class Index extends React.Component {
7168
TestConsole.consoleNormal('startRecord callback :', res)
7269
},
7370
})
74-
.then((res) => {
75-
TestConsole.consoleResult.call(this, res, apiIndex)
76-
})
7771
},
7872
},
7973
{
@@ -92,9 +86,6 @@ export default class Index extends React.Component {
9286
TestConsole.consoleComplete.call(this, res, apiIndex)
9387
},
9488
})
95-
.then((res) => {
96-
TestConsole.consoleResult.call(this, res, apiIndex)
97-
})
9889
},
9990
},
10091
{
@@ -114,9 +105,6 @@ export default class Index extends React.Component {
114105
TestConsole.consoleComplete.call(this, res, apiIndex)
115106
},
116107
})
117-
.then((res) => {
118-
TestConsole.consoleResult.call(this, res, apiIndex)
119-
})
120108
},
121109
},
122110
],

examples/mini-program-example/src/pages/api/openAPIS/biometricAuthorization/index.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22
import Taro from '@tarojs/taro'
3-
import { View, Text } from '@tarojs/components'
3+
import { View } from '@tarojs/components'
44
import ButtonList from '@/components/buttonList'
55
import './index.scss'
66

@@ -14,15 +14,21 @@ export default class Index extends React.Component {
1414
list: [
1515
{
1616
id: 'startSoterAuthentication 指纹',
17-
func: null,
17+
func: () => {
18+
this.startSoterAuthentication('fingerPrint')
19+
},
1820
},
1921
{
2022
id: 'startSoterAuthentication 人脸',
21-
func: null,
23+
func: () => {
24+
this.startSoterAuthentication('facial')
25+
},
2226
},
2327
{
2428
id: 'startSoterAuthentication 声纹',
25-
func: null,
29+
func: () => {
30+
this.startSoterAuthentication('speech')
31+
},
2632
},
2733
{
2834
id: 'checkIsSupportSoterAuthentication',

packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts

Lines changed: 32 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
// import {timeLog} from "./NativeApiLog";
22
import { syncApiCache } from './harmony-native/ApiCache'
3+
import { asyncAndNotRelease, asyncAndRelease, syncAndRelease } from './harmony-native/ApiDecorator'
34
import { storageCacheAndSyncProxy } from './harmony-native/StorageCacheAndSyncProxy'
45
import { NativeDataChangeListener, SyncCacheProxyHandler } from './NativeApiSyncCacheProxy'
5-
// @ts-ignore
6-
const syncAndRelease = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: false, autoRelease: true }) || (target => target)
7-
// @ts-ignore
8-
// const syncAndNotRelease = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: false, autoRelease: false }) || (target => target)
9-
// @ts-ignore
10-
const asyncAndRelease = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: true, autoRelease: true }) || (target => target)
11-
// @ts-ignore
12-
const asyncAndNotRelease = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: true, autoRelease: false }) || (target => target)
136

147
// export let judgeUseAxios = false
158
export class NativeApi {
@@ -20,18 +13,6 @@ export class NativeApi {
2013
registerNativeListener (listener: NativeDataChangeListener | null): void {
2114
}
2215

23-
// @ts-ignore
24-
@(syncAndRelease)
25-
openLocation (options: any): any {
26-
return options
27-
}
28-
29-
// @ts-ignore
30-
@(syncAndRelease)
31-
chooseLocation (options: any): any {
32-
return options
33-
}
34-
3516
@syncApiCache()
3617
@(syncAndRelease)
3718
getWindowInfo (): any {}
@@ -164,6 +145,37 @@ export class NativeApi {
164145
return options
165146
}
166147

148+
@(asyncAndRelease)
149+
saveVideoToPhotosAlbum (options: any): any {
150+
return options
151+
}
152+
153+
@(asyncAndRelease)
154+
compressImage (options: any): any {
155+
return options
156+
}
157+
158+
@(asyncAndRelease)
159+
showNavigationBarLoading (): void {}
160+
161+
@(asyncAndRelease)
162+
hideNavigationBarLoading (): void {}
163+
164+
@(asyncAndRelease)
165+
startSoterAuthentication (options: any): any {
166+
return options
167+
}
168+
169+
@(asyncAndRelease)
170+
checkIsSupportSoterAuthentication (options: any): any {
171+
return options
172+
}
173+
174+
@(asyncAndRelease)
175+
checkIsSoterEnrolledInDevice (options: any): any {
176+
return options
177+
}
178+
167179
// @ts-ignore
168180
@(syncAndRelease)
169181
chooseMediaAssets (options: any): any {
@@ -194,12 +206,6 @@ export class NativeApi {
194206
return options
195207
}
196208

197-
// @ts-ignore
198-
@(syncAndRelease)
199-
getLocation (options: any): any {
200-
return options
201-
}
202-
203209
// @ts-ignore
204210
@(syncAndRelease)
205211
openDocument (options: any): any {
@@ -254,18 +260,6 @@ export class NativeApi {
254260
return options
255261
}
256262

257-
// @ts-ignore
258-
@(asyncAndNotRelease)
259-
onLocationChange (options: any): any {
260-
return options
261-
}
262-
263-
// @ts-ignore
264-
@(syncAndRelease)
265-
offLocationChange (options: any): any {
266-
return options
267-
}
268-
269263
// @ts-ignore
270264
@(syncAndRelease)
271265
setScreenBrightness (options: any): any {
@@ -278,18 +272,6 @@ export class NativeApi {
278272
return options
279273
}
280274

281-
// @ts-ignore
282-
@(asyncAndNotRelease)
283-
onMemoryWarning (options: any): any {
284-
return options
285-
}
286-
287-
// @ts-ignore
288-
@(syncAndRelease)
289-
offMemoryWarning (options: any): any {
290-
return options
291-
}
292-
293275
// @ts-ignore
294276
@(syncAndRelease)
295277
hideKeyboard (options?: any): any {
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
import Taro from '@tarojs/taro'
22

3-
import native from '../../NativeApi'
4-
53
/**
64
* 取消监听内存不足告警事件
75
*
86
* @canUse offMemoryWarning
97
* @null_implementation
108
*/
11-
export const offMemoryWarning: typeof Taro.offMemoryWarning = (callback) => {
12-
// @ts-ignore
13-
if (native[offMemoryWarning]) {
14-
// @ts-ignore
15-
native.offMemoryWarning(callback)
16-
}
9+
export const offMemoryWarning: typeof Taro.offMemoryWarning = (_callback) => {
10+
1711
}

packages/taro-platform-harmony-hybrid/src/api/apis/device/memory/onMemoryWarning.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ import Taro from '@tarojs/taro'
66
* @canUse onMemoryWarning
77
* @null_implementation
88
*/
9-
export const onMemoryWarning: typeof Taro.onMemoryWarning = (callback) => {
10-
// @ts-ignore
11-
if (native[onMemoryWarning]) {
12-
// @ts-ignore
13-
native.onMemoryWarning((res: any) => {
14-
const ret: Taro.onMemoryWarning.CallbackResult = {
15-
level: res.level,
16-
}
17-
callback(ret)
18-
})
19-
}
9+
export const onMemoryWarning: typeof Taro.onMemoryWarning = (_callback) => {
10+
2011
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { asyncAndNotRelease, asyncAndRelease } from '../../harmony-native/ApiDecorator'
2+
3+
class NativeWifi {
4+
@asyncAndRelease
5+
connectWifi (_options: any):void {}
6+
7+
@asyncAndRelease
8+
getConnectedWifi (_options: any):void {}
9+
10+
@asyncAndRelease
11+
getWifiList (_options: any):void {}
12+
13+
@asyncAndRelease
14+
offGetWifiList (_options: any):void {}
15+
16+
@asyncAndRelease
17+
offWifiConnected (_options: any):void {}
18+
19+
@asyncAndRelease
20+
offWifiConnectedWithPartialInfo (_options: any):void {}
21+
22+
@asyncAndNotRelease
23+
onGetWifiList (_options: any):void {}
24+
25+
@asyncAndNotRelease
26+
onWifiConnected (_options: any):void {}
27+
28+
@asyncAndNotRelease
29+
onWifiConnectedWithPartialInfo (_options: any):void {}
30+
31+
@asyncAndRelease
32+
startWifi (_options: any):void {}
33+
34+
@asyncAndRelease
35+
stopWifi (_options: any):void {}
36+
}
37+
38+
const nativeWifi = new NativeWifi()
39+
40+
export default nativeWifi

packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/connectWifi.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import Taro from '@tarojs/taro'
22
import { getParameterError, shouldBeObject } from 'src/api/apis/utils'
33
import { MethodHandler } from 'src/api/apis/utils/handler'
44

5+
import nativeWifi from './NativeWifi'
6+
57
/**
68
* 连接 Wi-Fi
79
*
@@ -63,8 +65,7 @@ export const connectWifi: typeof Taro.connectWifi = (options) => {
6365
)
6466
}
6567

66-
// @ts-ignore
67-
native.connectWifi({
68+
nativeWifi.connectWifi({
6869
SSID: SSID,
6970
password: password,
7071
BSSID: BSSID,

packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/getConnectedWifi.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import Taro from '@tarojs/taro'
22
import { shouldBeObject } from 'src/api/apis/utils'
33
import { MethodHandler } from 'src/api/apis/utils/handler'
44

5+
import nativeWifi from './NativeWifi'
6+
57
/**
68
* 获取已连接中的 Wi-Fi 信息
79
*
@@ -20,8 +22,7 @@ export const getConnectedWifi: typeof Taro.getConnectedWifi = (options) => {
2022
const handle = new MethodHandler({ name, success, fail, complete })
2123

2224
return new Promise((resolve, reject) => {
23-
// @ts-ignore
24-
native.getConnectedWifi({
25+
nativeWifi.getConnectedWifi({
2526
success: (res: any) => {
2627
handle.success(res, { resolve, reject })
2728
},

packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/getWifiList.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import Taro from '@tarojs/taro'
22
import { shouldBeObject } from 'src/api/apis/utils'
33
import { MethodHandler } from 'src/api/apis/utils/handler'
44

5+
import nativeWifi from './NativeWifi'
6+
57
/**
68
* 请求获取 Wi-Fi 列表
79
*
@@ -19,8 +21,7 @@ export const getWifiList: typeof Taro.getWifiList = (options) => {
1921
const handle = new MethodHandler({ name, success, fail, complete })
2022

2123
return new Promise((resolve, reject) => {
22-
// @ts-ignore
23-
native.getWifiList({
24+
nativeWifi.getWifiList({
2425
success: (res: any) => {
2526
handle.success(res, { resolve, reject })
2627
},

packages/taro-platform-harmony-hybrid/src/api/apis/device/wifi/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/**
2-
* 设置 wifiList 中 AP 的相关信息
3-
*
4-
* @canNotUse setWifiList
5-
*/
61
export * from './connectWifi'
72
export * from './getConnectedWifi'
83
export * from './getWifiList'
@@ -14,7 +9,6 @@ export * from './onWifiConnected'
149
export * from './onWifiConnectedWithPartialInfo'
1510
export * from './startWifi'
1611
export * from './stopWifi'
17-
export { setWifiList } from '@tarojs/taro-h5'
1812

1913
/**
2014
* Wifi 信息(native 返回)

0 commit comments

Comments
 (0)