当前位置:网站首页>开源一夏|ArkUI如何自定义弹窗(eTS)
开源一夏|ArkUI如何自定义弹窗(eTS)
2022-08-04 10:05:00 【InfoQ】

import CustomDialogExample from './customdialog'
@Entry
@Component
struct Index {
// 方式一:使用箭头函数
onAccept = () => {
console.info('确定')
this.dialogController.close();
}
dialogController: CustomDialogController = new CustomDialogController({
builder: CustomDialogExample({ cancel: this.onCancel, confirm: this.onAccept }),
alignment: DialogAlignment.Center,
cancel: () => {
console.log("cancel") // 点击蒙层的回调
},
autoCancel: true, // 允许点击蒙层关闭弹窗
customStyle: false // 使用自定义样式
})
onCancel() {
console.info('取消')
}
build() {
Column({}) {
Button(' 自定义弹窗')
.onClick(() => {
//打开弹窗
this.dialogController.open();
})
}.width("100%").height("100%").alignItems(HorizontalAlign.Center).justifyContent(FlexAlign.Center)
}
}
/*
* Copyright (c) 2021 JianGuo Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//通过CustomDialogController类显示自定义弹窗。
@CustomDialog
struct CustomDialogExample {
controller: CustomDialogController
cancel: () => void
confirm: () => void
build() {
Flex({ justifyContent: FlexAlign.Center ,alignItems:ItemAlign.Center,alignContent:FlexAlign.Center}) {
Button('取消').fontSize(36)
.onClick(() => {
//方式二:关闭弹窗
this.controller.close()
this.cancel()
}).backgroundColor(0xffffff).fontColor(Color.Black)
Button('确定').fontSize(36)
.onClick(() => {
// this.controller.close()
this.confirm()
}).backgroundColor(0xffffff).fontColor(Color.Red)
}.margin({ bottom: 10 }).width("100%").height(200)
}
}
export default CustomDialogExample
CustomDialogControlleropen()close()- open:打开对话框,如果对话框已经打开,则再次打开无效。
- close:关闭对话框,如果对话框已经关闭,则再次关闭无效。
- value:创建控制器需要的配置参数,
CustomDialogControllerOptions
- builder:创建自定义弹窗的构造器。
- cancel:点击蒙层的事件回调。
- autoCancel:是否允许点击遮障层退出。
- alignment:弹窗在竖直方向上的对齐方式。
- offset:弹窗相对
alignment所在位置的偏移量。
- customStyle:弹窗容器样式是否自定义。
declare interface CustomDialogControllerOptions {
/**
* Custom builder function.
* @since 7
*/
builder: any;
/**
* Defines the cancel function.
* @since 7
*/
cancel?: () => void;
/**
* Defines if use auto cancel when click on the outside of the dialog.
* @since 7
*/
autoCancel?: boolean;
/**
* Defines the dialog alignment of the screen.
* @since 7
*/
alignment?: DialogAlignment;
/**
* Defines the dialog offset.
* @since 7
*/
offset?: Offset;
/**
* Defines if use costom style.
* @since 7
*/
customStyle?: boolean;
/**
* Grid count of dialog.
* @since 8
*/
gridCount?: number;
}
边栏推荐
- MindSpore:Ascend运行出现问题
- MindSpore:【mindinsight】【Profiler】用execution_time推导出来的训练耗时远小于真实的耗时
- Libtomcrypt AES 加密及解密
- MindSpore:Batchnorm only support nchw input!
- redis解决分布式session问题
- 双重for循环案例以及while循环和do while循环案例
- 暴力破解ssh/rdp/mysql/smb服务
- bash shell数组详解
- The difference between Mysql application log time and system time is eight hours
- 【COS 加码福利】COS 用户实践有奖征文,等你来投稿!
猜你喜欢

【c】操作符详解(二)

LVS-DR集群部署

XCTF-reverse-signin

XCTF-easy_Maze
![[Punctuality Atom STM32 Serial] Chapter 3 Development Environment Construction Excerpted from [Punctual Atom] MiniPro STM32H750 Development Guide_V1.1](/img/6f/c736a3404377961e92b3bd1b5ea90e.png)
[Punctuality Atom STM32 Serial] Chapter 3 Development Environment Construction Excerpted from [Punctual Atom] MiniPro STM32H750 Development Guide_V1.1

开源一夏 | 查询分页不只有limit,这四种分页方法值得掌握

Win10电脑经常发出叮咚声音怎么关闭

什么是元宇宙?

使用ClickHouse分析COS的清单和访问日志

2022-08-03 第六小组 瞒春 学习笔记
随机推荐
低代码是开发的未来吗?浅谈低代码开发平台的发展现状及未来趋势
No module named 'flask_misaka' has been resolved [BUG solution]
nsq部署_andlua辅助源码
【cookie 临时存储数据,WebStorage ,sessionStorage】
各位大佬,请问mysql数据的cdc,能指定存量数据同步的zone为utc 吗
OAK-FFC-4P全网首次测试
The difference between Mysql application log time and system time is eight hours
bash shell数组详解
2022 Cloud Native Computing代表厂商 | 灵雀云第三次入选Gartner中国ICT技术成熟度曲线报告
Post-94 Byte P7 posted the salary slip: It's really good to make up for this...
MindSpore:model.train中的dataset_sink_mode该如何理解?
陈春花发布声明,这场流量狂欢该到了收尾的时候
MySQL核心SQL:结构化查询语句SQL、库操作、表操作、CRUD
IDEA启动热部署
leetcode动态规划系列(求路径篇)
学习使用php把stdClass Object转array的方法整理
Detailed explanation of telnet remote login aaa mode [Huawei eNSP]
safe-point(safepoint 安全点) 和 safe-region(安全区域)「建议收藏」
Inheritance and the static keyword
菲沃泰科创板上市:市值123亿 宗坚赵静艳夫妇身价76亿