feat: 新增列表页与新 Activity 跳转,修复切页后点击失效

- 服务端:新增列表页(8 条数据 + 页内滚动),点击目标与 actionId 均由文档下发
- Android:新增 RemoteDocumentActivity,actionId=2 时在新 Activity 中打开指定页面
- 修复:文档缓存改为缓存原始字节、每次渲染重新解析;复用同一个 CoreDocument 时
  旧点击回调会残留在 idActionListeners 中,导致守卫跳过注册,切页后点击完全失效
- 部署:k8s 镜像更新为 composeremote/server:1.0.0-list
This commit is contained in:
tongtong committed 2026-11-24 18:36:27 +08:00
1 parent 8a5d0375a6
commit 0b27edcbea
6 files changed
+193 -34

No files matched your search

@@ -18,6 +18,7 @@ import androidx.compose.remote.creation.dsl.fillMaxWidth
import androidx.compose.remote.creation.dsl.height
import androidx.compose.remote.creation.dsl.onClick
import androidx.compose.remote.creation.dsl.padding
import androidx.compose.remote.creation.dsl.verticalScroll
import androidx.compose.remote.creation.profile.Profile
import androidx.compose.remote.creation.profile.RemoteComposeWriterFactory
@@ -33,6 +34,12 @@ private const val CANVAS_HEIGHT_DP = 900
/** 服务端与播放端约定的 action id:跳转到 metadata 里指定的页面。 */
private const val ACTION_NAVIGATE = 1
/** 服务端与播放端约定的 action id:在新 Activity 中打开 metadata 指定的页面。 */
private const val ACTION_OPEN_ACTIVITY = 2
/** 列表页的数据条数(当前为演示数据,真实场景可替换为业务查询结果)。 */
private const val LIST_ITEM_COUNT = 8
fun buildRemoteDocument(page: String): ByteArray {
lateinit var profile: Profile
profile = Profile(
@@ -56,19 +63,21 @@ fun buildRemoteDocument(page: String): ByteArray {
// 跳转目标以文本形式随文档下发,播放端只负责把 metadata 当作页面 id 使用。
val homeTarget = remoteText("home")
val detailTarget = remoteText("detail")
val listTarget = remoteText("list")
Column(
Modifier.fillMaxSize().background(WINDOW_BG).padding(RcDp(16f))
) {
when (page) {
"detail" -> detailContent(homeTarget)
else -> homeContent(detailTarget)
"list" -> listContent(homeTarget)
else -> homeContent(detailTarget, listTarget)
}
}
}
}
private fun RcScope.homeContent(detailTarget: RcText) {
private fun RcScope.homeContent(detailTarget: RcText, listTarget: RcText) {
Text(
text = "Remote Compose",
fontSize = RcSp(28f),
@@ -94,6 +103,21 @@ private fun RcScope.homeContent(detailTarget: RcText) {
hint = "点击查看详情 →",
target = detailTarget
)
Spacer(Modifier.height(RcDp(12f)))
card(
title = "列表",
body = "列表页由后端下发 8 条数据,可上下滚动查看。",
hint = "点击查看列表 →",
target = listTarget
)
Spacer(Modifier.height(RcDp(12f)))
card(
title = "新 Activity",
body = "这张卡片会在一个新的 Activity 中打开详情页。",
hint = "打开新 Activity →",
target = detailTarget,
actionId = ACTION_OPEN_ACTIVITY
)
}
private fun RcScope.detailContent(homeTarget: RcText) {
@@ -124,13 +148,69 @@ private fun RcScope.detailContent(homeTarget: RcText) {
)
}
private fun RcScope.card(title: String, body: String, hint: String, target: RcText) {
/**
* 列表页:内容全部由服务端生成,条目较多时可在页内上下滚动。
*/
private fun RcScope.listContent(homeTarget: RcText) {
Column(Modifier.fillMaxSize().verticalScroll()) {
Text(
text = "列表",
fontSize = RcSp(28f),
color = TITLE_COLOR
)
Spacer(Modifier.height(RcDp(4f)))
Text(
text = "服务端下发的 ${LIST_ITEM_COUNT} 条数据",
fontSize = RcSp(14f),
color = BODY_COLOR
)
Spacer(Modifier.height(RcDp(16f)))
repeat(LIST_ITEM_COUNT) { index ->
listItem(index + 1)
Spacer(Modifier.height(RcDp(8f)))
}
Spacer(Modifier.height(RcDp(4f)))
card(
title = "返回",
body = "回到首页。",
hint = "点击返回首页 →",
target = homeTarget
)
}
}
private fun RcScope.listItem(index: Int) {
Box(
Modifier
.fillMaxWidth()
.background(CARD_BG)
.padding(RcDp(12f))
) {
Column(Modifier.fillMaxWidth()) {
Text(text = "条目 $index", fontSize = RcSp(16f), color = TITLE_COLOR)
Spacer(Modifier.height(RcDp(4f)))
Text(
text = "这里是第 $index 条由后端下发的列表数据。",
fontSize = RcSp(13f),
color = BODY_COLOR
)
}
}
}
private fun RcScope.card(
title: String,
body: String,
hint: String,
target: RcText,
actionId: Int = ACTION_NAVIGATE,
) {
Box(
Modifier
.fillMaxWidth()
.background(CARD_BG)
.padding(RcDp(16f))
.onClick { hostAction(ACTION_NAVIGATE, target) }
.onClick { hostAction(actionId, target) }
) {
Column(Modifier.fillMaxWidth()) {
Text(text = title, fontSize = RcSp(18f), color = TITLE_COLOR)