当前位置:网站首页>开源一夏|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
CustomDialogController
open()
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;
}
边栏推荐
猜你喜欢
Multimedia and Internet of Things technology make the version "live" 129 vinyl records "Centennial Voice"
菲沃泰科创板上市:市值123亿 宗坚赵静艳夫妇身价76亿
【C补充】指向指针或函数的指针
IDEA启动热部署
ps抠图怎么抠出来,自学ps软件photoshop2022,ps怎么抠出想要的部分-笔记记录
EastWave应用:自动计算光子晶体透反率
Detailed explanation of switch link aggregation [Huawei eNSP]
Post-94 Byte P7 posted the salary slip: It's really good to make up for this...
无代码平台描述文字入门教程
超宽带UWB实时精准定位,短距离无缝交互应用,物联网厘米级精度方案
随机推荐
被Win11安全中心误删除的文件怎么恢复?
暴力破解ssh/rdp/mysql/smb服务
[论文翻译] Unpaired Image-to-Image Translation using Adversarial Consistency Loss
Could you please talk about how the website is accessed?[Interview questions in the web field]
视频加密怎么播放_win播放器加密视频
云计算适合什么企业_当前全球云计算处于发展
redis解决分布式session问题
江西发布紧急通知:全面开展涉校涉生安全隐患大排查
Producer and Consumer Problems in Concurrent Programming
leetcode经典例题——49.字母异位词分组
DOM简述
多媒体和物联网技术让版本“活”起来 129张黑胶唱片“百年留声”
LVGL's multi-language conversion tool -- a good assistant for font settings
《福格行为模型》:如何养成好习惯?
HCIP 交换实验
【C补充】指针相关知识点收集01
Post-94 Byte P7 posted the salary slip: It's really good to make up for this...
张朝阳对话俞敏洪:谈宇宙、谈焦虑、谈创业、谈退休、谈人生
safe-point(safepoint 安全点) 和 safe-region(安全区域)「建议收藏」
iMeta | 德国国家肿瘤中心顾祖光发表复杂热图(ComplexHeatmap)可视化方法