当前位置: 首页 > wzjs >正文

网站有什么广东网页设计

网站有什么,广东网页设计,网站网络营销平台,兰州做网络优化目录 生命周期 自定义弹出框的打开与关闭 更新自定义弹出框的内容 更新自定义弹出框的属性 为弹出框内容和蒙层设置不同的动画效果 设置弹出框避让软键盘的距离 完整示例 推荐使用UIContext中获取到的PromptAction对象提供的openCustomDialog接口在相对应用复杂的场景来实…

目录

生命周期

自定义弹出框的打开与关闭

更新自定义弹出框的内容

更新自定义弹出框的属性

为弹出框内容和蒙层设置不同的动画效果

设置弹出框避让软键盘的距离

 完整示例


推荐使用UIContext中获取到的PromptAction对象提供的openCustomDialog接口在相对应用复杂的场景来实现自定义弹出框,相较于CustomDialogController优势点在于页面解耦,支持动态刷新。

说明

弹出框(openCustomDialog)存在两种入参方式创建自定义弹出框:

  • openCustomDialog(传参为ComponentContent形式):通过ComponentContent封装内容可以与UI界面解耦,调用更加灵活,可以满足开发者的封装诉求。具有较高的灵活性,弹出框样式完全自定义,并且在弹出框打开后可以使用updateCustomDialog方法动态更新弹出框的参数。
  • openCustomDialog(传builder的形式):相对于ComponentContent,builder必须要与上下文做绑定,与UI存在一定耦合。此方法有用默认的弹出框样式,适合于开发者想要实现与系统弹窗默认风格一致的效果。

本文介绍通过入参形式为ComponentContent创建自定义弹出框,传builder形式的弹出框使用方法可参考openCustomDialog。

弹出框(openCustomDialog)默认为模态弹窗且有蒙层,不可与蒙层下方控件进行交互(不支持点击和手势等向下透传)。可以通过配置isModal来实现模态和非模态弹窗,详细说明可参考弹窗的种类。

当isModal为true时,弹出框为模态弹窗,且弹窗周围的蒙层区不支持透传。isModal为false时,弹出框为非模态弹窗,且弹窗周围的蒙层区可以透传。因此如果需要同时允许弹出框的交互和弹出框外页面的交互行为,需要将弹出框设置为非模态。

生命周期

弹出框提供了生命周期函数用于通知用户该弹出框的生命周期。生命周期的触发时序依次为:onWillAppear -> onDidAppear -> onWillDisappear -> onDidDisappear。

名称类型说明
onDidAppear() => void弹出框弹出时的事件回调。
onDidDisappear() => void弹出框消失时的事件回调。
onWillAppear() => void弹出框显示动效前的事件回调。
onWillDisappear() => void弹出框退出动效前的事件回调。

自定义弹出框的打开与关闭

详细变量定义请参考完整示例。

  • 创建ComponentContent。 
  1. ComponentContent用于定义自定义弹出框的内容。其中,wrapBuilder(buildText)封装自定义组件,new Params(this.message)是自定义组件的入参,可以缺省,也可以传入基础数据类型。

    private contentNode: ComponentContent<Object> = new ComponentContent(this.ctx, wrapBuilder(buildText), new Params(this.message));
    
  • 打开自定义弹出框。 
  • 调用openCustomDialog接口打开的弹出框默认customStyle为true,即弹出框的内容样式完全按照contentNode自定义样式显示。

    PromptActionClass.ctx.getPromptAction().openCustomDialog(PromptActionClass.contentNode, PromptActionClass.options).then(() => {console.info('OpenCustomDialog complete.');}).catch((error: BusinessError) => {let message = (error as BusinessError).message;let code = (error as BusinessError).code;console.error(`OpenCustomDialog args error code is ${code}, message is ${message}`);})
    
  • 关闭自定义弹出框。
  • 由于closeCustomDialog接口需要传入待关闭弹出框对应的ComponentContent。因此,如果需要在弹出框中设置关闭方法,则可参考完整示例封装静态方法来实现。

    关闭弹出框之后若需要释放对应的ComponentContent,则需要调用ComponentContent的dispose方法。

    PromptActionClass.ctx.getPromptAction().closeCustomDialog(PromptActionClass.contentNode).then(() => {console.info('CloseCustomDialog complete.');if (this.contentNode !== null) {this.contentNode.dispose();   // 释放contentNode}}).catch((error: BusinessError) => {let message = (error as BusinessError).message;let code = (error as BusinessError).code;console.error(`CloseCustomDialog args error code is ${code}, message is ${message}`);})
    

更新自定义弹出框的内容

ComponentContent与BuilderNode有相同的使用限制,不支持自定义组件使用@Reusable、@Link、@Provide、@Consume等装饰器,来同步弹出框弹出的页面与ComponentContent中自定义组件的状态。因此,若需要更新弹出框中自定义组件的内容可以通过ComponentContent提供的update方法来实现。

this.contentNode.update(new Params('update'))

更新自定义弹出框的属性

通过updateCustomDialog可以动态更新弹出框的属性。目前支持更新弹出框的对齐方式、基于对齐方式的偏移量、是否点击蒙层自动关闭以及蒙层颜色,对应的属性分别为alignment、offset、autoCancel、maskColor。

更新属性时,未设置的属性会恢复为默认值。例如,初始设置{ alignment: DialogAlignment.Top, offset: { dx: 0, dy: 50 } },更新时设置{ alignment: DialogAlignment.Bottom },则初始设置的offset: { dx: 0, dy: 50 }不会保留,会恢复为默认值。

PromptActionClass.ctx.getPromptAction().updateCustomDialog(PromptActionClass.contentNode, options).then(() => {console.info('UpdateCustomDialog complete.');}).catch((error: BusinessError) => {let message = (error as BusinessError).message;let code = (error as BusinessError).code;console.error(`UpdateCustomDialog args error code is ${code}, message is ${message}`);})

为弹出框内容和蒙层设置不同的动画效果

当弹出框出现时,内容与蒙层显示动效一致。若开发者希望为弹出框内容及蒙层设定不同动画效果,从API version 19开始,可通过BaseDialogOptions中dialogTransition和maskTransition属性单独配置弹窗内容与蒙层的动画。具体的动画效果请参考组件内转场 (transition)。

当isModal为true时,蒙层将显示,此时可以设置蒙层的动画效果;否则,maskTransition将不生效。

import { BusinessError } from '@kit.BasicServicesKit';@Entry
@Component
struct Index {private customDialogComponentId: number = 0@BuildercustomDialogComponent() {Row({ space: 50 }) {Button("这是一个弹窗")}.height(200).padding(5)}build() {Row() {Row({ space: 20 }) {Text('打开弹窗').fontSize(30).onClick(() => {this.getUIContext().getPromptAction().openCustomDialog({builder: () => {this.customDialogComponent()},isModal:true,showInSubWindow:false,maskColor: Color.Pink,maskRect:{ x: 20, y: 20, width: '90%', height: '90%' },dialogTransition: // 设置弹窗内容显示的过渡效果TransitionEffect.translate({ x: 0, y: 290, z: 0 }).animation({ duration: 4000, curve: Curve.Smooth }),// 四秒钟的偏移渐变动画maskTransition: // 设置蒙层显示的过渡效果TransitionEffect.opacity(0).animation({ duration: 4000, curve: Curve.Smooth }) // 四秒钟的透明渐变动画}).then((dialogId: number) => {this.customDialogComponentId = dialogId}).catch((error: BusinessError) => {console.error(`openCustomDialog error code is ${error.code}, message is ${error.message}`)})})}.width('100%')}.height('100%')}
}

设置弹出框避让软键盘的距离

为显示弹出框的独立性,弹出框弹出时会与周边进行避让,包括状态栏、导航条以及键盘等留有间距。故当软键盘弹出时,默认情况下,弹出框会自动避开软键盘,并与之保持16vp的距离。从API version 15开始,开发者可以利用BaseDialogOptions中的keyboardAvoidMode和keyboardAvoidDistance这两个配置项,来设置弹出框在软键盘弹出时的行为,包括是否需要避开软键盘以及与软键盘之间的距离。

设置软键盘间距时,需要将keyboardAvoidMode值设为KeyboardAvoidMode.DEFAULT。

import { BusinessError } from '@kit.BasicServicesKit';
import { LengthMetrics } from '@kit.ArkUI'@Entry
@Component
struct Index {@BuildercustomDialogComponent() {Column() {Text('keyboardAvoidDistance: 0vp').fontSize(20).margin({ bottom: 36 })TextInput({ placeholder: '' })}.backgroundColor('#FFF0F0F0')}build() {Row() {Row({ space: 20 }) {Text('打开弹窗').fontSize(30).onClick(() => {this.getUIContext().getPromptAction().openCustomDialog({builder: () => {this.customDialogComponent()},alignment:DialogAlignment.Bottom,keyboardAvoidMode: KeyboardAvoidMode.DEFAULT, // 软键盘弹出时,弹出框自动避让keyboardAvoidDistance: LengthMetrics.vp(0) // 软键盘弹出时与弹出框的距离为0vp}).catch((error: BusinessError) => {console.error(`openCustomDialog error code is ${error.code}, message is ${error.message}`)})})}.width('100%')}.height('100%')}
}

 完整示例

// PromptActionClass.ets
import { BusinessError } from '@kit.BasicServicesKit';
import { ComponentContent, promptAction, UIContext } from '@kit.ArkUI';export class PromptActionClass {static ctx: UIContext;static contentNode: ComponentContent<Object>;static options: promptAction.BaseDialogOptions;static setContext(context: UIContext) {PromptActionClass.ctx = context;}static setContentNode(node: ComponentContent<Object>) {PromptActionClass.contentNode = node;}static setOptions(options: promptAction.BaseDialogOptions) {PromptActionClass.options = options;}static openDialog() {if (PromptActionClass.contentNode !== null) {PromptActionClass.ctx.getPromptAction().openCustomDialog(PromptActionClass.contentNode, PromptActionClass.options).then(() => {console.info('OpenCustomDialog complete.');}).catch((error: BusinessError) => {let message = (error as BusinessError).message;let code = (error as BusinessError).code;console.error(`OpenCustomDialog args error code is ${code}, message is ${message}`);})}}static closeDialog() {if (PromptActionClass.contentNode !== null) {PromptActionClass.ctx.getPromptAction().closeCustomDialog(PromptActionClass.contentNode).then(() => {console.info('CloseCustomDialog complete.');}).catch((error: BusinessError) => {let message = (error as BusinessError).message;let code = (error as BusinessError).code;console.error(`CloseCustomDialog args error code is ${code}, message is ${message}`);})}}static updateDialog(options: promptAction.BaseDialogOptions) {if (PromptActionClass.contentNode !== null) {PromptActionClass.ctx.getPromptAction().updateCustomDialog(PromptActionClass.contentNode, options).then(() => {console.info('UpdateCustomDialog complete.');}).catch((error: BusinessError) => {let message = (error as BusinessError).message;let code = (error as BusinessError).code;console.error(`UpdateCustomDialog args error code is ${code}, message is ${message}`);})}}
}

// Index.ets
import { ComponentContent } from '@kit.ArkUI';
import { PromptActionClass } from './PromptActionClass';class Params {text: string = "";constructor(text: string) {this.text = text;}
}@Builder
function buildText(params: Params) {Column() {Text(params.text).fontSize(50).fontWeight(FontWeight.Bold).margin({ bottom: 36 })Button('Close').onClick(() => {PromptActionClass.closeDialog();})}.backgroundColor('#FFF0F0F0')
}@Entry
@Component
struct Index {@State message: string = "hello";private ctx: UIContext = this.getUIContext();private contentNode: ComponentContent<Object> =new ComponentContent(this.ctx, wrapBuilder(buildText), new Params(this.message));aboutToAppear(): void {PromptActionClass.setContext(this.ctx);PromptActionClass.setContentNode(this.contentNode);PromptActionClass.setOptions({ alignment: DialogAlignment.Top, offset: { dx: 0, dy: 50 } });}build() {Row() {Column() {Button("open dialog and update options").margin({ top: 50 }).onClick(() => {PromptActionClass.openDialog();setTimeout(() => {PromptActionClass.updateDialog({alignment: DialogAlignment.Bottom,offset: { dx: 0, dy: -50 }});}, 1500)})Button("open dialog and update content").margin({ top: 50 }).onClick(() => {PromptActionClass.openDialog();setTimeout(() => {this.contentNode.update(new Params('update'));}, 1500)})}.width('100%').height('100%')}.height('100%')}
}


文章转载自:

http://KpYnvttV.Lcbgf.cn
http://UtcSDpvb.Lcbgf.cn
http://5SVH9H67.Lcbgf.cn
http://frDLSfre.Lcbgf.cn
http://Iubj53cM.Lcbgf.cn
http://u8lsQEya.Lcbgf.cn
http://6TqGb3rl.Lcbgf.cn
http://VgxJCMkE.Lcbgf.cn
http://o1PLPfp1.Lcbgf.cn
http://0Pr6kp1u.Lcbgf.cn
http://G8J2Qys0.Lcbgf.cn
http://V2Narwz8.Lcbgf.cn
http://DnUr0wzC.Lcbgf.cn
http://ONECZfHT.Lcbgf.cn
http://9P9E0qFi.Lcbgf.cn
http://d5YHL4Ni.Lcbgf.cn
http://Vfphz6rh.Lcbgf.cn
http://8pRZrXZE.Lcbgf.cn
http://ecfKeoWg.Lcbgf.cn
http://WkrPvQt8.Lcbgf.cn
http://28tIvcdU.Lcbgf.cn
http://eSdhsXNN.Lcbgf.cn
http://bSw6Pxe3.Lcbgf.cn
http://bd4EX29e.Lcbgf.cn
http://lyZE7Mwq.Lcbgf.cn
http://5ucpDE9i.Lcbgf.cn
http://LmZQdgWO.Lcbgf.cn
http://XjSnGfRh.Lcbgf.cn
http://E4Jyx2WZ.Lcbgf.cn
http://OnVy72Zq.Lcbgf.cn
http://www.dtcms.com/wzjs/683995.html

相关文章:

  • 怎么把网站做的好看燕莎做网站
  • 网站建设销售一个月开几个单单页营销网站设计
  • 预付的网站开发费用怎么入账嘉兴快速建站模板
  • 注册一个网站要多少钱wordpress 的主题在哪个文件夹
  • 网站不备案可以吗郓城菏泽网站建设
  • 北京网站优化提供商wordpress nginx gzip
  • 怀柔区企业网站设计机构提供长治网站公司
  • asp网站助手500云空间网站
  • 在哪找专业做淘宝网站wordpress 程序员博客主题
  • 济宁网站建设第一品牌wordpress 网络图片不显示图片
  • 竞价网站做seo一般通过
  • 成品网站软件网站系统怎么做
  • 海口网站建设优化公司广州网站建设公司网站
  • 简述创建网站的步骤网站建设 锋云科技
  • 做网站上传图片多大合适网络营销产品的概念举例
  • 类似淘宝网站模板郑州网站seo诊断
  • 网站做不做备案有什么区别农产品网络营销策划方案
  • 中英繁网站新网站建设
  • 网站项目运营方案视觉asp网站源码
  • 局域网做网站医疗网站备案要怎么做 需要准备什么材料
  • 产品网站设计理念网站贸易表格怎么做
  • 临沂做网站多少钱网页编程培训
  • 网站正常打开速度做一个自适应网站多少钱
  • 公众号和网站ps里面怎么做网站对联广告
  • 南京做网站建设搭建的公司seo优化软件有哪些
  • 建设部网站技术负责人业绩表痘痘该如何去除效果好
  • 外贸网站建设平台有哪些网站seo优化徐州百度网络
  • 那个网站直接回做二手发电机网片式防护围栏
  • 昆山建设局网站查预售个人网站的备案
  • 做网站 被谷歌收录如何选择丹徒网站建设