Column() {XComponent({id: 'componentId',type: 'surface',controller: this.mXComponentController}).onLoad(async () => {hilog.info(0x0001, TAG, 'onLoad is called');// 获取XComponent组件的surfaceIdthis.surfaceId = this.mXComponentController.getXComponentSurfaceId();hilog.info(0x0001, TAG, 'surfaceId: %{public}s', this.surfaceId)let viewControl: customScan.ViewControl = {width: this.cameraWidth,height: this.cameraHeight,surfaceId: this.surfaceId};// 扫码结果放置到回调中处理try {customScan.start(viewControl, this.callback);this.isFlashLightEnable = true;} catch (error) {hilog.error(0x0001, TAG, 'start fail, error: %{public}s', JSON.stringify(error));}})// XComponent宽、高、位置偏移量默认使用单位:vp.width(this.cameraWidth).height(this.cameraHeight).position({ x: this.cameraOffsetX, y: this.cameraOffsetY })}.height('100%').width('100%').onAreaChange((oldValue: Area, newValue: Area) => {// 获取当前组件宽高,newValue返回width、height值,单位vp,计算XComponent组件大小hilog.info(0x0001, TAG, 'newValue : %{public}s, ', JSON.stringify(newValue));this.calcArea(newValue.width as number, newValue.height as number);})
评论