Skip to content

Commit 0838266

Browse files
dongluaclaude
andcommitted
build(release): prepare 1.3.0
- Add ViewFactory runtime extension point - Support custom view creation hooks - Update version to 1.3.0 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent ad5a734 commit 0838266

3 files changed

Lines changed: 103 additions & 2 deletions

File tree

‎build.gradle.kts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ buildscript {
1313
extra["targetSdk"] = 36
1414
extra["compileSdk"] = 36
1515
extra["groupId"] = "io.github.donglua.layoutx2c"
16-
extra["versionName"] = "1.2.0"
16+
extra["versionName"] = "1.3.0"
1717
}
1818

1919
plugins {

‎docs/RELEASE_NOTES_1_3_0.md‎

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# LayoutX2C 1.3.0
2+
3+
## 中文
4+
5+
LayoutX2C 1.3.0 是 1.2.0 之后的兼容 minor 版本,新增自定义 View 创建扩展点。它让生成代码在创建业务自定义 View 时,可以先交给运行时注册的 `ViewFactory`,用于接入换肤框架、自定义 View 替换或业务侧 View 创建策略。
6+
7+
这个版本不引入 breaking change。未注册 `ViewFactory`,或 `ViewFactory` 返回 `null` 时,生成代码继续使用默认构造函数创建 View。
8+
9+
### 主要变化
10+
11+
- 新增 `ViewFactory` 接口,允许业务侧按 XML tag name 接管自定义 View 创建。
12+
- 新增 `ViewFactoryRegistry`,支持运行时注册和重置 View 创建工厂。
13+
- 新增 `ViewFactoryCompat`,供生成代码统一调用自定义 View 创建 hook。
14+
- 对 `cn.xxx`、`com.example.xxx` 等非 framework 全限定名 View,生成代码会先尝试 `ViewFactoryCompat.createView(...)`。
15+
- 普通 `android.*`、`androidx.*`、Material 控件继续走原有直接构造路径,避免影响已验证的平台控件语义。
16+
- README 新增运行时扩展点说明,覆盖 `ResourceLoader` 和 `ViewFactory` 的用法与边界。
17+
18+
### 接入方式
19+
20+
```kotlin
21+
plugins {
22+
id("io.github.donglua.layoutx2c") version "1.3.0"
23+
}
24+
```
25+
26+
手动依赖配置:
27+
28+
```kotlin
29+
dependencies {
30+
implementation("io.github.donglua.layoutx2c:runtime:1.3.0")
31+
ksp("io.github.donglua.layoutx2c:ksp-processor:1.3.0")
32+
}
33+
```
34+
35+
自定义 View 创建 hook:
36+
37+
```kotlin
38+
ViewFactoryRegistry.setViewFactory { context, name, attrs ->
39+
when (name) {
40+
"com.example.widget.PriceView" -> PriceView(context, attrs)
41+
else -> null
42+
}
43+
}
44+
```
45+
46+
### 已知边界
47+
48+
- 当前生成路径不会重放平台 XML parser,因此传给 `ViewFactory` 的 `attrs` 可能为 `null`。
49+
- 强依赖非空 `AttributeSet` 的第三方 inflater,应在 `attrs == null` 时返回 `null`,避免破坏默认创建路径。
50+
- 完全等价复用强依赖 `AttributeSet` 的 inflater,还需要后续 synthetic `AttributeSet` 支持。
51+
52+
---
53+
54+
## English
55+
56+
LayoutX2C 1.3.0 is a compatible minor release after 1.2.0. It adds a custom View creation extension point so generated code can delegate business custom View creation to a runtime-registered `ViewFactory` before falling back to the default constructor.
57+
58+
This release does not introduce breaking changes. If no `ViewFactory` is registered, or if the registered factory returns `null`, generated code keeps using the default View constructor.
59+
60+
### Highlights
61+
62+
- Added the `ViewFactory` interface for custom View creation by XML tag name.
63+
- Added `ViewFactoryRegistry` to install and reset the runtime View factory.
64+
- Added `ViewFactoryCompat` as the generated-code entry point for custom View creation hooks.
65+
- Generated code now tries `ViewFactoryCompat.createView(...)` for non-framework fully qualified View names such as `cn.xxx` and `com.example.xxx`.
66+
- Platform and framework widgets such as `android.*`, `androidx.*`, and Material components keep the existing direct-constructor path.
67+
- Updated README runtime extension documentation for `ResourceLoader` and `ViewFactory`.
68+
69+
### Setup
70+
71+
```kotlin
72+
plugins {
73+
id("io.github.donglua.layoutx2c") version "1.3.0"
74+
}
75+
```
76+
77+
Manual dependency setup:
78+
79+
```kotlin
80+
dependencies {
81+
implementation("io.github.donglua.layoutx2c:runtime:1.3.0")
82+
ksp("io.github.donglua.layoutx2c:ksp-processor:1.3.0")
83+
}
84+
```
85+
86+
Custom View creation hook:
87+
88+
```kotlin
89+
ViewFactoryRegistry.setViewFactory { context, name, attrs ->
90+
when (name) {
91+
"com.example.widget.PriceView" -> PriceView(context, attrs)
92+
else -> null
93+
}
94+
}
95+
```
96+
97+
### Known boundaries
98+
99+
- The generated path does not replay the platform XML parser yet, so `attrs` passed to `ViewFactory` may be `null`.
100+
- Third-party inflaters that require a non-null `AttributeSet` should return `null` when `attrs == null`, preserving the default creation path.
101+
- Fully equivalent reuse of `AttributeSet`-dependent inflaters requires future synthetic `AttributeSet` support.

‎gradle-plugin/src/main/kotlin/com/github/donglua/layoutx2c/plugin/LayoutX2CPlugin.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class LayoutX2CPlugin : Plugin<Project> {
2626
companion object {
2727
const val EXTENSION_NAME = "layoutX2C"
2828
const val GROUP = "io.github.donglua.layoutx2c"
29-
const val VERSION = "1.2.0"
29+
const val VERSION = "1.3.0"
3030
}
3131

3232
override fun apply(project: Project) {

0 commit comments

Comments
 (0)