!262 swiper组件事件内部绑定

Merge pull request !262 from yongxinggong/master
This commit is contained in:
openharmony_ci 2022-08-31 07:10:43 +00:00 committed by Gitee
commit ec3ce8af2d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 79 additions and 93 deletions

View File

@ -78,6 +78,8 @@ class WindowAnimationControllerImpl implements windowAnimationManager.WindowAnim
finishCallback.onAnimationFinish();
}
onWindowAnimationTargetsUpdate(fullScreenWindowTarget: windowAnimationManager.WindowAnimationTarget, floatingWindowTargets: Array<windowAnimationManager.WindowAnimationTarget>): void {}
printfTarget(target: windowAnimationManager.WindowAnimationTarget): void {
if (CheckEmptyUtils.isEmpty(target) || CheckEmptyUtils.isEmpty(target.windowBounds)) {
Log.showInfo(TAG, `remote window animaion with invalid target`);

View File

@ -13,8 +13,13 @@
* limitations under the License.
*/
import { Log } from '@ohos/common';
import { StyleConstants } from '@ohos/common';
import {
Log,
Trace,
StyleConstants,
CommonConstants,
AppMenu,
MenuInfo} from '@ohos/common';
import SwiperPage from './SwiperPage';
const TAG = "GridSwiper";
@ -27,6 +32,7 @@ export default struct GridSwiper {
private mPageDesktopViewModel;
@State mAppGridInfo: [[]] = [[]];
private swiperController: SwiperController = new SwiperController();
private dialogController: CustomDialogController;
aboutToAppear(): void {
this.mPageDesktopViewModel.setSwiperController(this.swiperController);
@ -42,16 +48,68 @@ export default struct GridSwiper {
return isDesktopLoadFinished == true;
}
@Builder MenuBuilder() {
Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
AppMenu({
getMenuInfoList: this.getMenu.bind(this),
})
}
.width(StyleConstants.CONTEXT_MENU_WIDTH)
.borderRadius(StyleConstants.DEFAULT_12)
}
private getMenu(): MenuInfo[] {
let menuInfoList = new Array<MenuInfo>();
let setting = new MenuInfo();
setting.menuType = CommonConstants.MENU_TYPE_FIXED
setting.menuImgSrc = "/common/pics/ic_public_settings.svg"
setting.menuText = $r('app.string.into_settings')
setting.onMenuClick = () => {
Trace.start(Trace.CORE_METHOD_START_SETTINGS);
this.mPageDesktopViewModel.intoSetting();
}
menuInfoList.push(setting);
let addOrDeleteBlankPage = new MenuInfo();
addOrDeleteBlankPage.menuType = CommonConstants.MENU_TYPE_FIXED
addOrDeleteBlankPage.menuImgSrc = this.mPageDesktopViewModel.getBlankPageBtnIcon()
addOrDeleteBlankPage.menuText = this.mPageDesktopViewModel.getBlankPageBtnStr()
addOrDeleteBlankPage.onMenuClick = () => {
this.mPageDesktopViewModel.addOrDeleteBlankPage();
}
menuInfoList.push(addOrDeleteBlankPage);
return menuInfoList;
}
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
if (this.buildLog()) {
Swiper(this.swiperController) {
ForEach(this.mAppGridInfo, (item) => {
SwiperPage({
mAppListInfo: item,
gridConfig: this.gridConfig,
mPageDesktopViewModel: this.mPageDesktopViewModel
})
if (AppStorage.Get('deviceType') == CommonConstants.DEFAULT_DEVICE_TYPE) {
Column() {
SwiperPage({
mAppListInfo: item,
gridConfig: this.gridConfig,
mPageDesktopViewModel: this.mPageDesktopViewModel
})
}
.gesture(
LongPressGesture({ repeat: true })
.onAction((event: GestureEvent) => {
this.dialogController.open()
})
)
.bindContextMenu(this.MenuBuilder, ResponseType.RightClick)
} else {
SwiperPage({
mAppListInfo: item,
gridConfig: this.gridConfig,
mPageDesktopViewModel: this.mPageDesktopViewModel
})
.bindContextMenu(this.MenuBuilder, ResponseType.LongPress)
.bindContextMenu(this.MenuBuilder, ResponseType.RightClick)
}
})
}
.padding({

View File

@ -13,12 +13,12 @@
* limitations under the License.
*/
import { Log , CloseAppManager } from '@ohos/common';
import { Trace } from '@ohos/common';
import { AppMenu } from '@ohos/common';
import { MenuInfo } from '@ohos/common';
import { StyleConstants } from '@ohos/common';
import { CommonConstants } from '@ohos/common';
import {
Log,
Trace,
StyleConstants,
CommonConstants,
CloseAppManager } from '@ohos/common';
import GridSwiper from '../common/components/GridSwiper';
import { PageDesktopDragHandler } from '../common/PageDesktopDragHandler';
import PageDesktopViewModel from '../viewmodel/PageDesktopViewModel';
@ -103,89 +103,15 @@ export struct PageDesktopLayout {
return true;
}
private getMenu(): MenuInfo[] {
let menuInfoList = new Array<MenuInfo>();
let setting = new MenuInfo();
setting.menuType = CommonConstants.MENU_TYPE_FIXED
setting.menuImgSrc = "/common/pics/ic_public_settings.svg"
setting.menuText = $r('app.string.into_settings')
setting.onMenuClick = () => {
Trace.start(Trace.CORE_METHOD_START_SETTINGS);
mPageDesktopViewModel.intoSetting();
}
menuInfoList.push(setting);
let addOrDeleteBlankPage = new MenuInfo();
addOrDeleteBlankPage.menuType = CommonConstants.MENU_TYPE_FIXED
addOrDeleteBlankPage.menuImgSrc = mPageDesktopViewModel.getBlankPageBtnIcon()
addOrDeleteBlankPage.menuText = mPageDesktopViewModel.getBlankPageBtnStr()
addOrDeleteBlankPage.onMenuClick = () => {
mPageDesktopViewModel.addOrDeleteBlankPage();
}
menuInfoList.push(addOrDeleteBlankPage);
return menuInfoList;
}
private logId() {
Log.showInfo(TAG, `MenuBuilder build start ${this.menuId}`);
return true;
}
@Builder MenuBuilder() {
if (this.logId()) {
Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
AppMenu({
getMenuInfoList: this.getMenu,
})
}
.width(StyleConstants.CONTEXT_MENU_WIDTH)
.borderRadius(StyleConstants.DEFAULT_12)
}
}
build() {
if (this.deviceType == CommonConstants.DEFAULT_DEVICE_TYPE) {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
if (this.buildLog()) {
}
Column() {
GridSwiper({
mAppGridInfo: this.AppListInfo.appGridInfo,
gridConfig: this.gridConfig,
mPageDesktopViewModel: mPageDesktopViewModel
})
}
.width(StyleConstants.PERCENTAGE_100)
.height(StyleConstants.PERCENTAGE_100)
}
.gesture(
LongPressGesture({ repeat: true })
.onAction((event: GestureEvent) => {
this.dialogController.open()
})
)
.bindContextMenu(this.MenuBuilder, ResponseType.RightClick)
GridSwiper({
mAppGridInfo: this.AppListInfo.appGridInfo,
gridConfig: this.gridConfig,
mPageDesktopViewModel: mPageDesktopViewModel,
dialogController: this.deviceType == CommonConstants.PAD_DEVICE_TYPE ? null : this.dialogController
})
.width(StyleConstants.PERCENTAGE_100)
.height(StyleConstants.PERCENTAGE_100)
} else {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
if (this.buildLog()) {
}
Column() {
GridSwiper({
mAppGridInfo: this.AppListInfo.appGridInfo,
gridConfig: this.gridConfig,
mPageDesktopViewModel: mPageDesktopViewModel
})
}
.width(StyleConstants.PERCENTAGE_100)
.height(StyleConstants.PERCENTAGE_100)
}
.bindContextMenu(this.MenuBuilder, ResponseType.LongPress)
.bindContextMenu(this.MenuBuilder, ResponseType.RightClick)
.width(StyleConstants.PERCENTAGE_100)
.height(StyleConstants.PERCENTAGE_100)
}
}
}