arkts适配

Signed-off-by: gengzhengxing <gengzhengxing1@h-partners.com>
This commit is contained in:
gengzhengxing 2023-11-07 10:14:53 +08:00
parent 4ff6ba1802
commit 5b429bedaa
7 changed files with 61 additions and 57 deletions

View File

@ -62,9 +62,9 @@ export class AppItemInfo {
*/
badgeNumber: number | undefined;
checked: boolean | undefined;
checked?: boolean | undefined;
installTime: string | undefined;
installTime?: string | undefined;
moduleName: string | undefined;
@ -94,5 +94,5 @@ export class AppItemInfo {
* GridLayoutItemInfo: row of positions
*/
row: number | undefined;
bundleType: number | undefined;
bundleType?: number | undefined;
}

View File

@ -31,4 +31,5 @@ export class DockItemInfo extends AppItemInfo {
* true if this item is editable
*/
editable: boolean | undefined;
isDragging?: boolean;
}

View File

@ -24,34 +24,36 @@ export class LauncherDragItemInfo {
this.isDragging = isDragging ? isDragging : false;
}
cardId: number | undefined;
folderId: string | undefined;
folderName: string | undefined;
appList: string[] | undefined;
cardId?: number | undefined;
folderId?: string | undefined;
folderName?: string | undefined;
appList?: string[] | undefined;
keyName: string | undefined;
bundleName: string | undefined;
abilityName: string | undefined;
moduleName: string | undefined;
cardName: string | undefined;
cardDimension: number | undefined;
cardName?: string | undefined;
cardDimension?: number | undefined;
area: number[] | undefined;
description = '';
formConfigAbility: string | undefined;
description?: string = '';
formConfigAbility?: string | undefined;
appLabelId: number | undefined;
appName: string | undefined;
supportDimensions: number[] | undefined;
supportDimensions?: number[] | undefined;
appId: string | undefined;
appIconId: number | undefined;
isSystemApp: boolean | undefined;
isUninstallAble: boolean | undefined;
badgeNumber: number | undefined;
checked: boolean | undefined;
installTime: string | undefined;
checked?: boolean | undefined;
installTime?: string | undefined;
typeId: number | undefined;
page: number | undefined;
column: number | undefined;
row: number | undefined;
bundleType: number | undefined;
totalDimensionCount: number | undefined;
layoutInfo?: AppItemInfo[][]
bundleType?: number | undefined;
totalDimensionCount?: number | undefined;
layoutInfo?: AppItemInfo[][];
itemType?: number;
editable?: boolean;
}

View File

@ -147,7 +147,7 @@ export default class SmartDockDragHandler extends BaseDragHandler {
}
}
protected onDragDrop(x: number, y: number): boolean {
onDragDrop(x: number, y: number): boolean {
const dragItemInfo: LauncherDragItemInfo = AppStorage.get<LauncherDragItemInfo>('dragItemInfo');
if (!dragItemInfo.isDragging) {
return false;

View File

@ -1,4 +1,3 @@
// @ts-nocheck
/**
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
@ -28,23 +27,26 @@ import {
MenuInfo
} from '@ohos/common';
import { SmartDockStyleConfig } from '../config/SmartDockStyleConfig';
import SmartDockDragHandler from '../common/SmartDockDragHandler';
let mSmartDockStyleConfig: SmartDockStyleConfig = null;
let mSmartDockStyleConfig: SmartDockStyleConfig | null = null;
const TAG = 'ResidentLayout';
interface DockPadding {
right: number;
left: number;
top: number;
bottom: number;
}
@Component
export default struct ResidentLayout {
@StorageLink('dockPadding') dockPadding: {
right: number,
left: number,
top: number,
bottom: number
} = { right: 0, left: 0, top: 0, bottom: 0 };
@StorageLink('dockPadding') dockPadding: DockPadding = { right: 0, left: 0, top: 0, bottom: 0 };
@StorageLink('residentList') @Watch('onDockListChange') appList: Array<DockItemInfo> = [];
mSmartDockStyleConfig: SmartDockStyleConfig;
onItemClick: Function = null;
@Link mSmartDockStyleConfig: SmartDockStyleConfig;
onItemClick: (event: ClickEvent, item: DockItemInfo) => void = (event: ClickEvent, item: DockItemInfo) => {};
buildMenu: (item: DockItemInfo) => MenuInfo[] = (item: DockItemInfo): MenuInfo[] => [];
onDockListChangeFunc: Function = null;
onDockListChangeFunc: () => void = () => {};
aboutToAppear(): void {
mSmartDockStyleConfig = this.mSmartDockStyleConfig;
@ -52,9 +54,6 @@ export default struct ResidentLayout {
}
aboutToDisappear(): void {
this.onItemClick = null;
this.buildMenu = null;
this.onDockListChangeFunc = null;
}
getListWidth(): number {
@ -85,7 +84,7 @@ export default struct ResidentLayout {
if (this.getListWidth && this.getListWidth() !== 0) {
Row() {
List({ space: this.appList.length == 0 ? 0 : this.mSmartDockStyleConfig.mListItemGap }) {
ForEach(this.appList, (item) => {
ForEach(this.appList, (item: DockItemInfo) => {
ListItem() {
AppItem({
appInfo: item,
@ -93,7 +92,7 @@ export default struct ResidentLayout {
onItemClick: this.onItemClick
})
}
}, (item) => JSON.stringify(item))
}, (item: DockItemInfo) => JSON.stringify(item))
}
.height('100%')
.animation({
@ -120,7 +119,7 @@ export default struct ResidentLayout {
})
.onDrop((event: DragEvent, extraParams: string) => {
Log.showInfo(TAG, `onDrop event: [${event.getWindowX()}, ${event.getWindowY()}]`);
const dragResult = globalThis.SmartDockDragHandler.onDragDrop(event.getWindowX(), event.getWindowY());
const dragResult = SmartDockDragHandler.getInstance().onDragDrop(event.getWindowX(), event.getWindowY());
AppStorage.setOrCreate('selectAppIndex', null);
if (!dragResult) {
AppStorage.setOrCreate<LauncherDragItemInfo>('dragItemInfo', new LauncherDragItemInfo());
@ -140,25 +139,22 @@ struct AppItem {
@StorageLink('dragItemInfo') smartDragItemInfo: LauncherDragItemInfo = new LauncherDragItemInfo();
@StorageLink('dragItemType') dragItemType: number = CommonConstants.DRAG_FROM_DOCK;
@State isShow: boolean = false;
onItemClick: Function = null;
appInfo: DockItemInfo = null;
buildMenu: Function = null;
private menuInfo;
onItemClick: (event: ClickEvent, item: DockItemInfo) => void = (event: ClickEvent, item: DockItemInfo) => {};
appInfo: DockItemInfo = new DockItemInfo();
buildMenu: (item: DockItemInfo) => MenuInfo[] = (item: DockItemInfo): MenuInfo[] => [];
private menuInfo: MenuInfo[] = [];
aboutToAppear(): void {
this.menuInfo = this.buildMenu(this.appInfo);
}
aboutToDisappear(): void {
this.buildMenu = null;
this.onItemClick = null;
this.isShow = false;
this.appInfo = null;
this.menuInfo = null;
this.menuInfo = [];
}
private getLongPress(): boolean {
return AppStorage.get('isLongPress');
return AppStorage.get('isLongPress') as boolean;
}
@Builder MenuBuilder() {
@ -179,7 +175,7 @@ struct AppItem {
build() {
Column() {
AppIcon({
iconSize: mSmartDockStyleConfig.mIconSize,
iconSize: mSmartDockStyleConfig?.mIconSize as number,
iconId: this.appInfo.appIconId,
bundleName: this.appInfo.bundleName,
moduleName: this.appInfo.moduleName,
@ -190,10 +186,10 @@ struct AppItem {
}
.visibility(this.dragItemType === CommonConstants.DRAG_FROM_DOCK && this.smartDragItemInfo.keyName === this.appInfo.keyName ?
Visibility.Hidden : Visibility.Visible)
.width(mSmartDockStyleConfig.mListItemWidth)
.height(mSmartDockStyleConfig.mListItemHeight)
.backgroundColor(mSmartDockStyleConfig.mItemBackgroundColor)
.borderRadius(mSmartDockStyleConfig.mItemBorderRadius)
.width(mSmartDockStyleConfig?.mListItemWidth as number)
.height(mSmartDockStyleConfig?.mListItemHeight as number)
.backgroundColor(mSmartDockStyleConfig?.mItemBackgroundColor as string)
.borderRadius(mSmartDockStyleConfig?.mItemBorderRadius as number)
.parallelGesture(
LongPressGesture({ repeat: false })
.onAction((event: GestureEvent) => {
@ -206,7 +202,9 @@ struct AppItem {
builder: this.MenuBuilder,
placement: Placement.Top,
popupColor: Color.White,
arrowOffset: AppStorage.get('deviceType') == CommonConstants.DEFAULT_DEVICE_TYPE ? null : 3 * (mSmartDockStyleConfig.mIconSize / 2) + mSmartDockStyleConfig.mListItemGap, // Avoid the popup offset problem in phone form
arrowOffset: AppStorage.get('deviceType') == CommonConstants.DEFAULT_DEVICE_TYPE
? null
: 3 * ((mSmartDockStyleConfig?.mIconSize as number) / 2) + (mSmartDockStyleConfig?.mListItemGap as number), // Avoid the popup offset problem in phone form
onStateChange: (e) => {
if (!e.isVisible) {
this.isShow = false;
@ -218,7 +216,7 @@ struct AppItem {
.onTouch((event: TouchEvent) => {
Log.showInfo(TAG, `onTouch event type: ${event.type}`);
if (event.type === CommonConstants.TOUCH_TYPE_UP && this.smartDragItemInfo.isDragging) {
let mIsDragEffectArea = globalThis.SmartDockDragHandler.isDragEffectArea(event.touches[0].windowX, event.touches[0].windowY);
let mIsDragEffectArea = SmartDockDragHandler.getInstance().isDragEffectArea(event.touches[0].windowX, event.touches[0].windowY);
if (!mIsDragEffectArea) {
AppStorage.setOrCreate<LauncherDragItemInfo>('dragItemInfo', new LauncherDragItemInfo());
AppStorage.setOrCreate('selectAppIndex', null);
@ -243,9 +241,10 @@ struct AppItem {
.onDragStart((event: DragEvent, extraParams: string) => {
Log.showInfo(TAG, `DragStart`);
this.dragItemType = CommonConstants.DRAG_FROM_DOCK;
this.smartDragItemInfo = Object.assign(new LauncherDragItemInfo(true), this.appInfo);
this.appInfo.isDragging = true;
this.smartDragItemInfo = this.appInfo as LauncherDragItemInfo;
Log.showInfo(TAG, `smartDragItemInfo: ${JSON.stringify(this.smartDragItemInfo)}`);
const selectAppIndex = globalThis.SmartDockDragHandler.getDragItemIndexByCoordinates(event.getWindowX(), event.getWindowY());
const selectAppIndex = SmartDockDragHandler.getInstance().getDragItemIndexByCoordinates(event.getWindowX(), event.getWindowY());
AppStorage.setOrCreate('selectAppIndex', selectAppIndex);
})
.onDragEnd((event: DragEvent, extraParams: string) => {

View File

@ -49,12 +49,14 @@ export struct SmartDock {
private mSelectedItem: DockItemInfo | null = null;
private mSelectedDockType = 0;
private dialogName = "";
@State mSmartDockStyleConfig?: SmartDockStyleConfig = undefined;
aboutToAppear(): void {
Log.showInfo(TAG, 'aboutToAppear start!');
this.deviceType = AppStorage.get('deviceType') as string;
try {
this.mSmartDockViewModel = SmartDockViewModel.getInstance();
this.mSmartDockStyleConfig = this.mSmartDockViewModel.getStyleConfig() as SmartDockStyleConfig;
} catch (error) {
Log.showError(TAG, `catch error ${JSON.stringify(error)}`);
}
@ -147,9 +149,9 @@ export struct SmartDock {
}
ListItem() {
ResidentLayout({
mSmartDockStyleConfig: this.mSmartDockViewModel?.getStyleConfig() as SmartDockStyleConfig,
mSmartDockStyleConfig: $mSmartDockStyleConfig,
onItemClick: (event: ClickEvent, item: DockItemInfo) => {
this.mSmartDockViewModel?.residentOnClick(event, item, this.showAppCenter)
this.mSmartDockViewModel?.residentOnClick(event, item, this.showAppCenter);
},
buildMenu: (item: DockItemInfo): MenuInfo[] => {
return this.mSmartDockViewModel?.buildMenuInfoList(item, SmartDockConstants.RESIDENT_DOCK_TYPE,

View File

@ -15,7 +15,7 @@
import Prompt from '@ohos.promptAction';
import missionManager from '@ohos.app.ability.missionManager';
import { CloseAppManager, windowManager } from '@ohos/common';
import { CloseAppManager, LauncherDragItemInfo, windowManager } from '@ohos/common';
import { Log } from '@ohos/common';
import { CheckEmptyUtils } from '@ohos/common';
import { EventConstants } from '@ohos/common';
@ -212,7 +212,7 @@ export default class SmartDockModel {
* @param appInfo
* @param index
*/
addToSmartdock(appInfo: AppItemInfo, index?: number): boolean {
addToSmartdock(appInfo: LauncherDragItemInfo, index?: number): boolean {
if (appInfo.typeId != CommonConstants.TYPE_APP) {
return false;
}