ant弹窗_基于AntDesign改造优化的Modal弹窗

本文探讨了在React Native应用中,当Modal弹窗过多导致代码可读性下降的问题,并介绍了如何基于AntDesign的Modal进行改造优化。通过分析AntDesign Modal的实现原理,特别是`Portal`组件的工作方式,提出了在项目中引入`Provider`组件包裹顶层视图,以实现类似AntDesign的静态方法调用弹窗的功能。同时,文章展示了如何创建一个工具类`DialogUtil`,简化弹窗的显示和隐藏操作,提高代码复用性和可维护性。
摘要由CSDN通过智能技术生成

一、前言

在日常开发中,Modal使用必不可少,但是如果一个页面Modal弹窗过多,Modal的使用又必须要在render()方法里声明,这无疑是一件很恐怖的事情,就像如下场景

render() {

if (this.state.isLoading) {

return (

);

} else {

return (

style={ {flex: 1, backgroundColor: StyleConfig.color_background}}

contentContainerStyle={ {paddingTop: 0, paddingBottom: 50 + Global.bottomOfSafeArea}}

automaticallyAdjustContentInsets={false}

keyboardShouldPersistTaps="handled"

showsHorizontalScrollIndicator={false}

removeClippedSubviews={true}

showsVerticalScrollIndicator={false}>

props={this.props}

isAdd={true}

relationSex={this.state.relationSex}

relation={this.state.relation}

imageUrl={this.state.imageUrl}

userInfo={this.state.userInfo}

isFamilyMemeber={RelationShipMap.isFamilyMember(this.state.relation)}

loginType={this.state.loginType}

uploadImgCallBack={(fileId, picUrl) => {

this.fileId = fileId;

this.setState({imageUrl: picUrl});

}}

selectRelationCallback={relation => {

this.isCheckMember = true;

if (relation != null) {

this.setState({relation: Number.parseInt(relation)});

this.setAddress(relation);

this.getFamilyMemberByRelation(relation);

}

}}

idCardChangeCallBack={idCardNo => {

this.setState({relationSex: Common.isMaleFromIdCard(idCardNo) ? 1 : 0});

let value = {};

value[FamilyMemberKey.IDCARD] = idCardNo;

this.props.form.setFieldsValue(value);

}}

/>

{/*是否加入安心管*/}

{RelationShipMap.isFamilyMember(this.state.relation) && (

style={ {marginTop: 15}}

isJoinAnxin={this.isJoinAnxin}

promptText={'如将该成员加入安心管,可能引起家庭抗风险能力值发生变化'}

joinAnxinChange={checked => {

this.isJoinAnxin = checked;

}}

/>

)}

onPress={() => {

if (!RelationShipMap.isFamilyMember(this.state.relation)) {

this.isJoinAnxin = false;

}

if (this.checkParams()) {

if (this.isCheckMember) {

this.checkMember();

} else {

let forms = this.props.form.getFieldsValue();

this.updateMember(this.insurantId, forms);

}

}

}}>

保存

style={ {

alignSelf: 'center',

marginTop: 15,

marginLeft: 20,

marginRight: 20,

marginBottom: 20,

color: '#666',

fontSize: 13,

}}>

以上信息仅用于新一站保险业务办理,我们会严格保密。

{/*操作是本人提示弹窗*/}

transparent={true}

visible={this.state.modalMeVisiable}

onRequestClose={() => {

this.setState({modalMeVisiable: false});

}}>

message={'身份号已被本人使用'}

isHideCancal

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你想了解有关 Ant Design Vue 中弹窗的内容吗?Ant Design Vue 是一个基于 Vue.js 的 UI 组件库,它提供了丰富的组件,包括弹窗Modal)组件。你可以使用 Modal 组件来创建弹窗窗口。 要使用 Ant Design Vue 的弹窗组件,首先确保你已经按照官方文档中的指导安装和引入了 Ant Design Vue。然后,你可以按照以下步骤来创建一个弹窗: 1. 在你的 Vue 组件中引入 Modal 组件: ```vue <template> <div> <a-button @click="showModal">打开弹窗</a-button> <a-modal v-model="visible" title="这是一个弹窗"> <p>这是弹窗的内容。</p> </a-modal> </div> </template> <script> import { Modal, Button } from 'ant-design-vue'; export default { components: { 'a-modal': Modal, 'a-button': Button, }, data() { return { visible: false, }; }, methods: { showModal() { this.visible = true; }, }, }; </script> ``` 在这个示例中,我们引入了 Modal 和 Button 组件,并在点击按钮时设置 `visible` 变量为 `true`,从而显示弹窗Modal 组件是一个带有标题和内容的弹窗容器,你可以在其中放置任意内容。 2. 根据你的需求,你可以自定义 Modal 组件的行为和样式。你可以在文档中查找更多关于 Modal 组件的信息,例如如何设置弹窗的宽度、高度、遮罩等。 这就是使用 Ant Design Vue 创建弹窗的基本步骤。你可以根据你的实际需求对弹窗进行进一步的定制和使用。希望这能帮到你!如果你还有其他问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值