当前位置:网站首页>开源一夏|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;
}
边栏推荐
猜你喜欢

I am 37 this year, and I was rushed by a big factory to...

v-model原理,在“radio”、“checkbox”、“select”、修饰符

MindSpore:【model_zoo】【resnet】尝试用THOR优化器运行时报cannot import name ‘THOR‘

HCIP 交换实验

ps如何换背景颜色,自学ps软件photoshop2022,3种不同的方式笔记记录

MySQL核心SQL:结构化查询语句SQL、库操作、表操作、CRUD

Qt:小的任务管理器(task)

Apache APISIX 2.15 版本发布,为插件增加更多灵活性

leetcode动态规划经典例题——53.最大子数组和
![Could you please talk about how the website is accessed?[Interview questions in the web field]](/img/06/5ecc617edc4131c31f71d5e019a64c.png)
Could you please talk about how the website is accessed?[Interview questions in the web field]
随机推荐
How Oracle for current library or certain library data on the same server number?
密码字典生成工具pydictor/john
Could you please talk about how the website is accessed?[Interview questions in the web field]
学习在微信小程序中判断url的文件后缀格式
Win7C盘不能扩大怎么办?Win7C盘扩展卷不能点怎么解决
架构设计杂谈
Detailed explanation of MSTP protocol configuration on Layer 3 switches [Huawei eNSP experiment]
MindSpore:mirrorpad算子速度过慢的问题
请问下Flink SQL如何写hologres分区表?我想要每天一个分区
SVG 的 path 属性绘制图形
【C补充】指向指针或函数的指针
移动端 开源低代码工具 beeware 和 kivy
gom登录器配置教程_谷歌浏览器如何使用谷歌搜索引擎
[代码阅读] CycleGAN: Unpaired Image-To-Image Translation Using Cycle-Consistent Adversarial Networks
nsq部署_andlua辅助源码
iMeta | 百度认证完成,搜索“iMeta”直达出版社主页和投稿链接
OAK-FFC-4P全网首次测试
leetcode单调栈经典例题——最大矩形
用匿名函数定义函数_c语言最先执行的函数是
《福格行为模型》:如何养成好习惯?