Skip to content

Commit e58af0d

Browse files
authored
[ohos] add features & fix bugs for OpenHarmony (#3367)
1、Weex支持一键登录。 2、Weex medialibrary断代接口替换。 3、Weex的BroadCastChannel跨页面通信特性增强。 4、增加virtual-loader插件,list组件实现虚拟列表功能。 bugfix: 1、修复使用gesture-loader方案之后,picker组件内无法滑动问题。 2、修复通用事件gesture-loader方案无法感知组件生命周期问题。 3、修复weex-list的scroll事件,滑动时底部的筛选tab一直闪问题。 Signed-off-by: xczaixian <xuchang@openvalley.net>
1 parent f1a274c commit e58af0d

269 files changed

Lines changed: 7963 additions & 2882 deletions

File tree

Some content is hidden

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

ohos/AdvancedAPI_OHOS/src/advancedApi/as/device/system.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
import Result from '../../../base/util/Result'
22

3+
export function getSystemInfo (...args) {
4+
console.debug('[AdvancedAPI] start getSystemInfo')
5+
const callback = args.pop()
6+
const device = requireAPI('ASDevice')
7+
device.getSystemInfo().then(
8+
systemInfo => {
9+
callback.invoke(Result.success(systemInfo))
10+
}
11+
)
12+
}
13+
314
export function getSystemInfoSync(...args) {
415
console.debug('[AdvancedAPI] start getSystemInfoSync')
516
const device = requireAPI('ASDevice')

ohos/AdvancedAPI_OHOS/src/advancedApi/module/ASDevice/index.js

Lines changed: 104 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -9,100 +9,108 @@ import wifiManager from '@ohos.wifiManager'
99
import window from '@ohos.window'
1010

1111
export default class ASDevice {
12+
async getSystemInfo () {
13+
return this.getSystemInfoSync()
14+
}
15+
1216
getSystemInfoSync () {
13-
const {
14-
brand: deviceBrand,
15-
productModel: deviceModel,
16-
osFullName,
17-
deviceType,
18-
udid: deviceId,
19-
sdkApiVersion: ohosAPILevel
20-
} = DeivceBase.getDeviceInfo()
21-
const romName = osFullName.split('-')[0]
22-
const osName = romName
23-
const romVersion = osFullName.split('-')[1]
24-
const osVersion = romVersion
25-
26-
const osLanguage = I18n.System.getSystemLanguage()
27-
const displayInfo = DisplayBase.ohosGetDisplay()
28-
const { rotation, densityPixels: devicePixelRatio } = displayInfo
29-
let { width: screenWidth, height: screenHeight } = displayInfo
30-
screenWidth = Math.round(screenWidth / devicePixelRatio)
31-
screenHeight = Math.round(screenHeight / devicePixelRatio)
32-
const deviceOrientation = (rotation === 1 || rotation === 3) ? 'landscape' : 'portrait'
33-
34-
const {
35-
signatureInfo,
36-
versionName: appVersion,
37-
versionCode: appVersionCode,
38-
appInfo
39-
} = globalThis.bundleInfoForSelf
40-
const appName = context.resourceManager.getStringSync(appInfo.labelId)
41-
const appId = signatureInfo.appId
42-
43-
const {
44-
language: appLanguage
45-
} = context.config
46-
47-
let {
48-
width: windowWidth,
49-
height: windowHeight,
50-
top: windowTop
51-
} = globalThis.lastWindow.getWindowProperties()?.windowRect
52-
const {
53-
isFullScreen, isLayoutFullScreen
54-
} = globalThis.lastWindow.getWindowProperties()
55-
const systemCutout = globalThis.lastWindow.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM)
56-
const statusBarHeight = Math.round((systemCutout?.topRect?.height || 0) / devicePixelRatio)
57-
const windowBottom = (isFullScreen || isLayoutFullScreen) ? Math.round(windowHeight / devicePixelRatio) :
58-
Math.round((windowHeight + statusBarHeight) / devicePixelRatio)
59-
windowTop = Math.round(windowTop / devicePixelRatio)
60-
windowWidth = Math.round(windowWidth / devicePixelRatio)
61-
windowHeight = Math.round(windowHeight / devicePixelRatio)
62-
63-
const brand = deviceBrand
64-
const model = deviceModel
65-
const pixelRatio = devicePixelRatio
66-
const system = osFullName
67-
const language = osLanguage
68-
const platform = osName
69-
const version = osVersion
70-
const result = {
71-
deviceType,
72-
deviceBrand,
73-
brand,
74-
deviceModel,
75-
platform,
76-
model,
77-
deviceOrientation,
78-
devicePixelRatio,
79-
pixelRatio,
80-
system,
81-
osName,
82-
osVersion,
83-
version,
84-
osLanguage,
85-
language,
86-
ohosAPILevel,
87-
romName,
88-
romVersion,
89-
appId,
90-
appName,
91-
appVersion,
92-
appVersionCode,
93-
appLanguage,
94-
screenWidth,
95-
screenHeight,
96-
windowWidth,
97-
windowHeight,
98-
windowTop,
99-
windowBottom,
100-
statusBarHeight
101-
}
102-
if (deviceId) {
103-
result.deviceId = deviceId
17+
try {
18+
const {
19+
brand,
20+
productModel,
21+
osFullName,
22+
deviceType,
23+
// udid,
24+
sdkApiVersion
25+
} = DeivceBase.getDeviceInfo()
26+
const romName = osFullName.split('-')[0]
27+
const osName = romName
28+
const romVersion = osFullName.split('-')[1]
29+
const osVersion = romVersion
30+
31+
const osLanguage = I18n.System.getSystemLanguage()
32+
const displayInfo = DisplayBase.ohosGetDisplay()
33+
const { rotation, densityPixels: devicePixelRatio } = displayInfo
34+
let { width: screenWidth, height: screenHeight } = displayInfo
35+
screenWidth = Math.round(screenWidth / devicePixelRatio)
36+
screenHeight = Math.round(screenHeight / devicePixelRatio)
37+
const deviceOrientation = (rotation === 1 || rotation === 3) ? 'landscape' : 'portrait'
38+
39+
const appVersion = globalThis.bundleInfoForSelf.versionName
40+
const appVersionCode = globalThis.bundleInfoForSelf.versionCode
41+
const appInfo = globalThis.bundleInfoForSelf.appInfo
42+
const signatureInfo = globalThis.bundleInfoForSelf.signatureInfo
43+
const appName = context.resourceManager.getStringSync(appInfo.labelId)
44+
const appId = signatureInfo.appId
45+
46+
const appLanguage = context.config.language
47+
48+
let {
49+
width: windowWidth,
50+
height: windowHeight,
51+
top: windowTop
52+
} = globalThis.lastWindow.getWindowProperties()?.windowRect
53+
const {
54+
isFullScreen, isLayoutFullScreen
55+
} = globalThis.lastWindow.getWindowProperties()
56+
const systemCutout = globalThis.lastWindow.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM)
57+
const statusBarHeight = Math.round((systemCutout?.topRect?.height || 0) / devicePixelRatio)
58+
const windowBottom = (isFullScreen || isLayoutFullScreen) ? Math.round(windowHeight / devicePixelRatio) :
59+
Math.round((windowHeight + statusBarHeight) / devicePixelRatio)
60+
windowTop = Math.round(windowTop / devicePixelRatio)
61+
windowWidth = Math.round(windowWidth / devicePixelRatio)
62+
windowHeight = Math.round(windowHeight / devicePixelRatio)
63+
64+
const deviceBrand = brand
65+
const deviceModel = productModel
66+
// const deviceId = udid
67+
const model = deviceModel
68+
const pixelRatio = devicePixelRatio
69+
const system = osFullName
70+
const language = osLanguage
71+
const platform = osName
72+
const version = osVersion
73+
const ohosAPILevel = sdkApiVersion
74+
const result = {
75+
deviceType,
76+
deviceBrand,
77+
brand,
78+
deviceModel,
79+
platform,
80+
model,
81+
deviceOrientation,
82+
devicePixelRatio,
83+
pixelRatio,
84+
system,
85+
osName,
86+
osVersion,
87+
version,
88+
osLanguage,
89+
language,
90+
ohosAPILevel,
91+
romName,
92+
romVersion,
93+
appId,
94+
appName,
95+
appVersion,
96+
appVersionCode,
97+
appLanguage,
98+
screenWidth,
99+
screenHeight,
100+
windowWidth,
101+
windowHeight,
102+
windowTop,
103+
windowBottom,
104+
statusBarHeight
105+
}
106+
// if (deviceId) {
107+
// result.deviceId = deviceId
108+
// }
109+
console.info(`[AdvancedAPI] result: ${JSON.stringify(result)}`)
110+
return result
111+
} catch (error) {
112+
console.error(`Failed to return result. Cause code: ${error.code}, message: ${error.message}`);
104113
}
105-
return result
106114
}
107115

108116
getDeviceInfo () {
@@ -113,7 +121,7 @@ export default class ASDevice {
113121
osFullName: system,
114122
deviceType,
115123
osFullName,
116-
udid: deviceId
124+
// udid: deviceId
117125
} = DeivceBase.getDeviceInfo()
118126
const deviceBrand = brand
119127
const model = deviceModel
@@ -134,9 +142,9 @@ export default class ASDevice {
134142
brand,
135143
model
136144
}
137-
if (deviceId) {
138-
result.deviceId = deviceId
139-
}
145+
// if (deviceId) {
146+
// result.deviceId = deviceId
147+
// }
140148
return result
141149
}
142150

ohos/AdvancedAPI_OHOS/src/advancedApi/module/ASVideo/index.js

Lines changed: 6 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -8,111 +8,26 @@ import {
88
} from '../../util/index'
99
import fs from '@ohos.file.fs'
1010
import { ErrorCode } from '../../../base/util/ErrorCode'
11-
// import { MediaLibraryBase } from '../../../base/bridge/mediaLibraryBase'
1211
import { FileioBase } from '../../../base/bridge/fileioBase'
1312
import photoAccessHelper from '@ohos.file.photoAccessHelper'
14-
// import { context } from '../../../base/bridge/abilityBase'
1513
import fileUri from '@ohos.file.fileuri'
1614

17-
// const ORI = {
18-
// 0: 'left',
19-
// 90: 'up',
20-
// 180: 'right',
21-
// 270: 'down',
22-
// }
2315

2416
export default class ASViedo {
2517
getVideoInfo(params) {
2618
return new Promise(async (resolve, reject) => {
2719
return reject(['getVideoInfo is not support!'])
28-
// const permission = await MediaLibraryBase.getPermissions()
29-
// if (permission.perNum === -1) {
30-
// return reject(['permission fail', ErrorCode.USER_REJECT, permission.perNum, permission.dialogShownResults])
31-
// }
32-
// try {
33-
// let uri = params.src
34-
// if (isFileUri(uri)) {
35-
// const asset = await getFileAssetFromUri(uri)
36-
// const orientation = ORI[asset.orientation]
37-
// return resolve({
38-
// width: asset.width,
39-
// height: asset.height,
40-
// path: uri,
41-
// orientation,
42-
// type: asset.displayName.split('.').pop(),
43-
// duration: asset.duration / 1000,
44-
// size: Math.round(asset.size / 1024),
45-
// bitrate: Math.round((asset.size * 8 * 1000) / (asset.duration * 1024)),
46-
// })
47-
// } else if (isSandboxPath(uri)) {
48-
// uri = switchInternalToHapSandBox(uri)
49-
// const fileType = uri.split('.').pop()
50-
// const fileName = uri.split('/').pop()
51-
// if (!fs.accessSync(uri)) {
52-
// reject(['getVideoInfo fail, src not exist.', ErrorCode.PARAMETER_ERROR])
53-
// return
54-
// }
55-
// const file = fs.openSync(uri, fs.OpenMode.READ_WRITE)
56-
// if (!file) {
57-
// reject(['saveVideoToPhotosAlbum fail, src not exist.', ErrorCode.PARAMETER_ERROR])
58-
// return
59-
// }
60-
// // await new Promise(res => setTimeout(res, 500))
61-
// // const fileResult = await media.getFileAssets(videosfetchOp)
62-
// // const asset = await fileResult.getFirstObject()
63-
// const fd = file.fd
64-
// const stat = fs.statSync(fd)
65-
// const sizes = stat.size
66-
// const buf = new ArrayBuffer(sizes)
67-
// FileioBase.ohosReadSync(fd, buf)
68-
// const videoUri = await saveMedia(fileName, buf)
69-
// // const media = MediaLibraryBase.getMedia()
70-
// const asset = await getFileAssetFromUri(videoUri)
71-
// const width = Number(asset.get(photoAccessHelper.PhotoKeys.WIDTH))
72-
// const height = Number(asset.get(photoAccessHelper.PhotoKeys.HEIGHT))
73-
// const orientation = ORI[asset.get(photoAccessHelper.PhotoKeys.ORIENTATION)]
74-
// const duration = Number(asset.get(photoAccessHelper.PhotoKeys.DURATION)) / 1000
75-
// const size = Math.round(Number(asset.get(photoAccessHelper.PhotoKeys.SIZE)) / 1024)
76-
// const bitrate = Math.round((Number(asset.get(photoAccessHelper.PhotoKeys.SIZE)) * 8 * 1000) / (Number(asset.get(photoAccessHelper.PhotoKeys.DURATION)) * 1024))
77-
// const result = {
78-
// width,
79-
// height,
80-
// path: params.src,
81-
// orientation,
82-
// type: fileType,
83-
// duration,
84-
// size,
85-
// bitrate,
86-
// }
87-
// try {
88-
// await asset.trash(true)
89-
// await photoAccessHelper.MediaAssetChangeRequest.deleteAssets(context, [asset.uri])
90-
// } catch (error) {
91-
// console.debug('[AdvancedAPI] delete tempFile fail: %s', error.message)
92-
// }
93-
// // fileResult.close()
94-
// return resolve(result)
95-
// } else {
96-
// return reject(['get uri fail', ErrorCode.SERVICE_UNAVIALABLE])
97-
// }
98-
// } catch (err) {
99-
// console.debug(`[AdvancedAPI] getVideoInfo err %s`, JSON.stringify(err))
100-
// reject([err.message, err.code])
101-
// }
10220
})
10321
}
10422

10523
saveVideoToPhotosAlbum(params) {
10624
return new Promise(async (resolve, reject) => {
10725
const filePath = params.filePath
108-
// const permission = await MediaLibraryBase.getPermissions()
109-
// if (permission.perNum === -1) {
110-
// return reject(['permission fail', ErrorCode.USER_REJECT, permission.perNum, permission.dialogShownResults])
111-
// }
26+
11227
if (typeof filePath !== 'string') {
11328
return reject(['filePath format is not supported.', ErrorCode.PARAMETER_ERROR])
11429
}
115-
console.debug('[AdvancedAPI] filePath:', filePath)
30+
11631
if (isFileUri(filePath)) {
11732
const uri = filePath
11833
const fd = getFdFromUriOrSandBoxPath(uri)
@@ -153,7 +68,10 @@ export default class ASViedo {
15368
FileioBase.ohosReadSync(fd, buf)
15469

15570
// 获取文件显示名
156-
const displayName = 'VIDEO_' + new Date().getTime() + '_' + filePath.split('/').splice(-1, 1).toString()
71+
let displayName = 'VIDEO_' + new Date().getTime() + '_' + filePath.split('/').splice(-1, 1).toString()
72+
if (!displayName.includes('.')) {
73+
displayName += '.mp4'
74+
}
15775
uri = fileUri.getUriFromPath(uri)
15876
const imageUri = await saveMedia(photoAccessHelper.PhotoType.VIDEO, displayName, uri, buf)
15977
resolve({ path: imageUri })

ohos/AdvancedAPI_OHOS/src/advancedApi/module/interface.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { interceptCallback } from '../callback/callback-intercept'
22
import JSCallback, { jsCallbackMap } from '../callback/JSCallback'
33

44
import {
5+
getSystemInfo,
56
getSystemInfoSync,
67
getDeviceInfo,
78
getWindowInfo,
@@ -109,6 +110,7 @@ import { scanCode } from '../as/scan/scan'
109110
*/
110111
export const asInterfaceList = {
111112
// 设备系统
113+
getSystemInfo: { method: getSystemInfo },
112114
getSystemInfoSync: { method: getSystemInfoSync, needPromise: false, needCallback: false },
113115
getDeviceInfo: { method: getDeviceInfo, needPromise: false },
114116
getWindowInfo: { method: getWindowInfo, needPromise: false },

ohos/AdvancedAPI_OHOS/src/base/bridge/deviceBase.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
import deviceInfo from '@ohos.deviceInfo'
1010
export class DeivceBase {
1111
static getDeviceInfo () {
12-
return deviceInfo
12+
const resultInfo = {
13+
brand: deviceInfo.brand,
14+
productModel: deviceInfo.productModel,
15+
osFullName: deviceInfo.osFullName,
16+
deviceType: deviceInfo.deviceType,
17+
// udid: deviceInfo.udid,
18+
sdkApiVersion: deviceInfo.sdkApiVersion
19+
}
20+
return resultInfo
1321
}
1422
}

0 commit comments

Comments
 (0)