feat(AlertDialogView): expose customization attributes for better flexibility and reuse - #1621
feat(AlertDialogView): expose customization attributes for better flexibility and reuse #1621whysqwhw wants to merge 1 commit into
Conversation
KuiklyAI
left a comment
There was a problem hiding this comment.
🤖 KuiklyAI Code Review
基本信息
- PR:#1621 · feat(AlertDialogView): expose customization attributes for better flexibility and reuse
- 作者:whysqwhw main ← main
变更概述
- 干了什么:为
AlertDialog暴露一批自定义能力——titleCustomAttr/msgCustomAttr(覆盖标题/正文的 TextAttr)、dialogAttr(替换默认内容容器样式)、customMsgView(在内容区插入自定义 UI,如 RichText),并新增clickTitle/clickMsg点击回调。 - 解决什么:作者声明「expose customization attributes for better flexibility and reuse」,让业务在不替换整个前景 View 的前提下细粒度定制弹窗外观与正文内容。
- 方案 & 合理性:在既有
contentViewCreator框架内做条件分支(dialogAttr != null走自定义、否则走原默认色值),title/message 在默认样式后追加titleAttr/messageAttr?.invoke(this)形成「自定义覆盖」,新增msgViewCreator作为 message 之后的扩展槽。层级正确、与现有customContentView/customBackgroundView风格一致,二进制兼容(仅新增 public 成员 + typealias,无签名破坏)。增量改动幅度合理。
审查结论
- 功能正确性:跨文件追了
contentViewCreator提前 return、vif渲染顺序、actionButtonsCustomAttr+ 2 按钮 →size == 2分支、TextSpan继承TextAttr的click/fontWeight400/lineHeight等可用性,均符合预期;新click事件参数类型(ClickParams) -> Unit与既有clickBackgroundMask一致。未发现逻辑缺陷。 - 代码质量:边界/包名/API 可见性符合项目规则(新成员与既有同文件成员可见性一致);
typealias TextAttrBuilder与既有ActionButtonTitleAttr同为TextAttr.() -> Unit,存在重复定义,建议合并。其余见 inline。 - 文档同步:
docs/API/components/alert-dialog.md当前未收录本次新增的titleCustomAttr、msgCustomAttr、dialogAttr、customMsgView属性以及clickTitle、clickMsg事件,建议补充属性表/事件列表,保持对外文档与 API 同步。
| } | ||
|
|
||
| typealias ActionButtonTitleAttr = TextAttr.() -> Unit | ||
| typealias TextAttrBuilder = TextAttr.() -> Unit |
There was a problem hiding this comment.
这里新增的 TextAttrBuilder = TextAttr.() -> Unit 和上一行已有的 ActionButtonTitleAttr 是同一个类型,只是换了个名字。两者都在同一文件作用域里,外部引用时容易困惑该用哪个。建议直接复用 ActionButtonTitleAttr,或者把两者统一成一个语义更中心的命名(比如都叫 TextAttrBuilder),避免同一个函数类型出现两个等价别名。
There was a problem hiding this comment.
ActionButtonTitleAttr 是按钮的,老版本的 api 动了会导致一些使用的地方有兼容问题
| lineHeight(20f) | ||
| letterSpacing(-0.2f) | ||
|
|
||
| click { |
There was a problem hiding this comment.
这个 click { } 是空实现,留着会让 TextSpan.hasClickEvent() 返回 true、白白挂上点击命中区域但不做任何事。如果只是占位、暂时没交互,建议先注释掉或留个 TODO;否则补上实际逻辑。
| } | ||
| } | ||
| } | ||
| AlertDialog { |
There was a problem hiding this comment.
这个第二个 AlertDialog 没有注册 willDismiss,在系统返回键/右滑返回时无法关闭弹窗(第一个 AlertDialog 有处理)。作为 demo 建议补上与第一个一致的 willDismiss { ctx.showAgreeDialog = false },避免别人照抄时遇到返回键关不掉的问题。
There was a problem hiding this comment.
已解决:第二个 AlertDialog 已补上 willDismiss { ctx.showAgreeDialog = false },返回键/右滑关闭逻辑和第一个一致了。
| val colorHex: Long | ||
| val alpha: Float | ||
| if (getPager().isNightMode()) { | ||
| colorHex = 0x000000 |
KuiklyAI
left a comment
There was a problem hiding this comment.
🤖 KuiklyAI Code Review
增量回顾
上轮提了 3 点:
- 第二个 AlertDialog 缺
willDismiss— 已补上,已解决 ✅ TextAttrBuilder与ActionButtonTitleAttr是等价别名 — 仍并存,未处理Span的click {}空实现会让hasClickEvent()返回 true、挂上空点击区域 — 改成了click { //TODO },但空实现本身仍在,hasClickEvent()依旧为 true
这次新增了 dialogAttr / customMsgView / titleCustomAttr / msgCustomAttr / clickTitle / clickMsg 一组定制能力,API 均为新增、未破坏既有签名,整体方向 OK。新增能力里有一个用法上的注意点,见 inline。
…xibility and reuse
KuiklyAI
left a comment
There was a problem hiding this comment.
🤖 KuiklyAI Code Review
增量回顾
上轮(ee39613a → c3f682f)只改了 demo 第二个 AlertDialog 的 clickActionButton:ctx.showAgreeDialog = false 改成 ctx.showAgreeDialog = index == 1,core 没动。
上轮提的几点状态:
TextAttrBuilder与ActionButtonTitleAttr等价别名 — 仍在,未处理Span的click { //TODO }空实现 — 仍在- 第二个 AlertDialog 缺
willDismiss— 已解决(上轮已确认) dialogAttr?.invoke(this)覆盖夜间/blur 背景色 — 仍在,core 未改动
这轮新增改动里有一个按钮语义上的小问题,见 inline。core 侧无新增风险。
expose customization attributes for better flexibility and reuse