Complication editor preview is blank when a Title/Value slot uses a Template token different from the Display name template

未关闭 适合新手
#5,844 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
86/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
ios, swift
领域
mobile

调研方向

先从 AllFamiliesComplicationPreview.swift 第 266 行附近和 WatchComplicationLivePreview.swift 第 216 行附近开始,然后将它们的渲染上下文与 WatchWidgetComplicationSnapshot.swift 和 WidgetComplicationResolver.swift 进行比较。跟踪 ComplicationFormulaResolver.swift 第 52-63 行附近的代码,并验证编辑器预览使用不同于显示名称的模板来渲染插槽,其中包括相邻的静态文本。

由索引模型根据 Issue 内容生成。

描述

bug ios

iOS device model, version and app version

Model Name: iPhone 16 Pro Max
Software Version: 27.0
App version: 2026.9.1 (2026.2985)
Apple Watch / watchOS: Apple Watch Series 7 (GPS), watchOS 26.6 (23U67)

Home Assistant Core Version

2026.9.2

Describe the bug

In the Apple Watch complication editor, for a complication with Source: Template, the Customize sheet lets a Title or Value slot be set to Custom and contain "Template" tokens. When such a token holds a template that is different from the complication's Display name template, the live preview shows that slot as empty. The result row under the tokens still shows the correct rendered value, and static text tokens in the same slot also disappear. On the actual Apple Watch face, the same configuration renders correctly.

From reading the code (permalinks at the release/2026.9.1/2026.2985 tag, the build I'm running), this looks like a preview-only mismatch. The preview builds its render context with only the main template:
https://github.com/home-assistant/iOS/blob/f02aa89660db509e654f65608b57f98f86b775d8/Sources/App/Settings/AppleWatch/Complications/Preview/AllFamiliesComplicationPreview.swift#L266
(same pattern in WatchComplicationLivePreview.swift#L216), while the watch renders the extra templates used by customized slots:
https://github.com/home-assistant/iOS/blob/f02aa89660db509e654f65608b57f98f86b775d8/Sources/WatchApp/Complication/WatchWidgetComplicationSnapshot.swift#L112
and so does the iPhone widget resolver:
https://github.com/home-assistant/iOS/blob/f02aa89660db509e654f65608b57f98f86b775d8/Sources/Extensions/AppIntents/Widget/Complication/WidgetComplicationResolver.swift#L109-L115

ComplicationFormulaResolver resolves a template missing from renderedTemplates as an empty string and drops static text next to an empty dynamic part, so the whole slot ends up blank:
https://github.com/home-assistant/iOS/blob/f02aa89660db509e654f65608b57f98f86b775d8/Sources/HAModels/Sources/ComplicationFormulaResolver.swift#L52-L63

To Reproduce

  1. Create a complication with Source: Template and a Display name template, e.g. {{ states('sensor.a') }}.
  2. Open Customize and set the Value slot to Custom.
  3. Set the slot's Template token to a different template, e.g. {{ states('sensor.b') }}.
  4. The row under the tokens shows the correct result, but the preview shows no value text (and no static text tokens from that slot).
  5. Save and check the watch face: the value is displayed correctly.

Expected behavior

The preview renders every template referenced by the slot formulas, like the watch and the widget resolver do.

Screenshots

Image

Additional context

The gauge and gauge color templates are unaffected; only text slots with extra Template tokens.

Not a duplicate of #5831: that one is about the Corner family on the watch face with the progress bar on, while this one is only about the editor preview (the watch face renders correctly).

主要语言
Swift
星标
2.4k
派生
521
平均合并
8 小时 4 分钟
30 天内合并 PR
252

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

home-assistant/iOS 的其他 Issue

查看 home-assistant/iOS 的全部 Issue

相似的 Issue

更多 Swift Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。