Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,11 @@ jobs:
run: |
for bundle in "$RUNNER_TEMP"/xcresult/*.xcresult; do
[ -d "$bundle" ] || continue
xcrun xcresulttool get test-results summary --path "$bundle" | python3 -c '
if [ ! -f "$bundle/Info.plist" ] || ! summary=$(xcrun xcresulttool get test-results summary --path "$bundle"); then
echo "::warning::StoreKit did not finish writing $(basename "$bundle"); see the archived test logs."
continue
fi
printf '%s\n' "$summary" | python3 -c '
import json, sys
for failure in json.load(sys.stdin).get("testFailures", []):
name = failure.get("testName", "")
Expand Down
79 changes: 51 additions & 28 deletions apps/ios/Cook/Views/KitchenStepGuidanceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import SwiftUI
/// Local guidance surface attached below the current step and outside its completion button.
struct RecipeStepGuidancePanel: View {
@Environment(CookAISettings.self) private var ai
@Environment(\.accessibilityReduceMotion) private var reduceMotion
@Environment(\.dynamicTypeSize) private var dynamicTypeSize
let step: RecipePresentation.Step
let guidance: KitchenStepGuidanceModel
Expand All @@ -14,6 +15,7 @@ struct RecipeStepGuidancePanel: View {
@State private var question = ""
@State private var lastKind: StepGuidanceKind = .explain
@State private var lastQuestion: String?
@State private var panBounce = false
@FocusState private var questionFocused: Bool

private var response: StepGuidanceResponse? {
Expand All @@ -30,18 +32,7 @@ struct RecipeStepGuidancePanel: View {

var body: some View {
VStack(alignment: .leading, spacing: 12) {
Group {
if dynamicTypeSize.isAccessibilitySize {
VStack(alignment: .leading, spacing: 10) {
guidanceActionButtons
}
} else {
HStack(spacing: 10) {
guidanceActionButtons
}
.fixedSize(horizontal: false, vertical: true)
}
}
guidanceActions

if asking {
VStack(alignment: .leading, spacing: 8) {
Expand Down Expand Up @@ -122,12 +113,14 @@ struct RecipeStepGuidancePanel: View {
}
}
}
.padding(14)
.background(Color(uiColor: .secondarySystemGroupedBackground), in: RoundedRectangle(cornerRadius: 16))
.overlay {
RoundedRectangle(cornerRadius: 16)
.strokeBorder(Color.accentColor.opacity(0.18), lineWidth: 1)
.accessibilityHidden(true)
.padding(.horizontal, 14)
.padding(.vertical, 10)
.frame(maxWidth: .infinity, alignment: .leading)
.background {
if showsDetails {
RoundedRectangle(cornerRadius: 16)
.fill(Color(uiColor: .secondarySystemGroupedBackground))
}
}
.accessibilityElement(children: .contain)
.accessibilityIdentifier("recipe.guidance.panel")
Expand Down Expand Up @@ -183,21 +176,52 @@ struct RecipeStepGuidancePanel: View {
return !trimmed.isEmpty && trimmed.count <= StepGuidanceRequest.maximumQuestionLength && !guidance.isLoading
}

private var showsDetails: Bool {
asking || guidance.isLoading || guidance.phase == .error || response != nil || !ai.canUseRemote
}

@ViewBuilder
private var guidanceActions: some View {
if dynamicTypeSize.isAccessibilitySize {
stackedGuidanceActions
} else {
ViewThatFits(in: .horizontal) {
HStack(spacing: 12) {
guidanceActionButtons
}
stackedGuidanceActions
}
}
}

private var stackedGuidanceActions: some View {
VStack(alignment: .leading, spacing: 8) {
guidanceActionButtons
}
}

@ViewBuilder
private var guidanceActionButtons: some View {
guidanceButton("本步讲解", systemImage: "sparkles", identifier: "recipe.guidance.explain") {
guidanceButton("本步讲解", identifier: "recipe.guidance.explain") {
Image(systemName: "frying.pan")
.foregroundStyle(.orange)
.symbolEffect(.bounce, options: .nonRepeating, value: panBounce)
} action: {
if !reduceMotion { panBounce.toggle() }
lastKind = .explain
lastQuestion = nil
explain()
}
guidanceButton(asking ? "收起提问" : "问这一步",
systemImage: asking ? "chevron.up" : "questionmark.bubble",
identifier: "recipe.guidance.question") {
.buttonStyle(.bordered)
guidanceButton(asking ? "收起提问" : "问这一步", identifier: "recipe.guidance.question") {
Image(systemName: asking ? "chevron.up" : "questionmark.bubble")
} action: {
withAnimation(.easeInOut(duration: 0.2)) {
asking.toggle()
}
if !asking { questionFocused = false }
}
.buttonStyle(.borderless)
}

private func sendQuestion() {
Expand All @@ -209,16 +233,15 @@ struct RecipeStepGuidancePanel: View {
ask(trimmed)
}

private func guidanceButton(_ title: String, systemImage: String, identifier: String,
action: @escaping () -> Void) -> some View {
private func guidanceButton<Icon: View>(_ title: String, identifier: String, @ViewBuilder icon: () -> Icon,
action: @escaping () -> Void) -> some View {
Button(action: action) {
Label(title, systemImage: systemImage)
Label { Text(title) } icon: { icon().accessibilityHidden(true) }
.font(.subheadline.weight(.medium))
.frame(minHeight: 44)
.fixedSize(horizontal: false, vertical: true)
.frame(minWidth: 44, minHeight: 44)
.contentShape(Rectangle())
}
.buttonStyle(.bordered)
.frame(maxWidth: dynamicTypeSize.isAccessibilitySize ? .infinity : nil, alignment: .leading)
.disabled(guidance.isLoading)
.accessibilityIdentifier(identifier)
}
Expand Down
35 changes: 22 additions & 13 deletions apps/ios/Cook/Views/KitchenWorkbenchView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@ struct KitchenWorkbenchView: View {
ZStack(alignment: .top) {
// 紧凑模式的两块面板重叠以保留阅读位置;可见面板也需位于无障碍命中层级最上方。
KitchenPaneLayout(frames: frames) {
instructions
.scrollEdgeBar(edge: .bottom) {
if compact, !dynamicTypeSize.isAccessibilitySize { timerShortcut }
VStack(spacing: 0) {
instructions
.frame(maxWidth: .infinity, maxHeight: .infinity)
.clipped()
if compact, !dynamicTypeSize.isAccessibilitySize {
Divider()
timerShortcut
}
.clipped()
.opacity(!compact || pane == .recipe ? 1 : 0)
.allowsHitTesting(!compact || pane == .recipe)
.accessibilityHidden(compact && pane != .recipe)
.zIndex(!compact || pane == .recipe ? 1 : 0)
}
.opacity(!compact || pane == .recipe ? 1 : 0)
.allowsHitTesting(!compact || pane == .recipe)
.accessibilityHidden(compact && pane != .recipe)
.zIndex(!compact || pane == .recipe ? 1 : 0)
preparation(tabletop: frames.mode == .tabletop)
.clipped()
.opacity(!compact || pane == .preparation ? 1 : 0)
Expand Down Expand Up @@ -104,8 +108,6 @@ struct KitchenWorkbenchView: View {
if let text = store.text(for: recipe) {
RecipeTextContent(recipe: recipe, text: text, preparationInSidebar: true,
showsStepGuidance: true, dietaryGoal: dietaryGoal)
.accessibilityLabel("菜谱做法")
.accessibilityIdentifier("kitchen.instructions")
} else {
ContentUnavailableView {
Label("暂未收录图文做法", systemImage: "book.closed")
Expand All @@ -132,15 +134,22 @@ struct KitchenWorkbenchView: View {
HStack {
Label(timer.phase(at: context.date) == .finished ? "计时结束" : "计时器", systemImage: "timer")
Spacer()
Text(timer.display(at: context.date)).monospacedDigit()
Image(systemName: "chevron.right").font(.caption)
Text(timer.display(at: context.date))
.font(.body.weight(.semibold).monospacedDigit())
Image(systemName: "chevron.right")
.font(.caption)
.foregroundStyle(.secondary)
.accessibilityHidden(true)
}
.padding()
.padding(.horizontal, 20)
.padding(.vertical, 12)
.frame(minHeight: 52)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.accessibilityIdentifier("kitchen.timerShortcut")
}
.background(Color(uiColor: .secondarySystemGroupedBackground), ignoresSafeAreaEdges: .bottom)
}
}

Expand Down
32 changes: 30 additions & 2 deletions apps/ios/Cook/Views/RecipeCookingComponents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ struct RecipeStepCard: View {
let toggle: () -> Void

var body: some View {
let stepText = recipeStepMarkdown(instruction?.text ?? step.text)
VStack(spacing: 0) {
Button(action: toggle) {
HStack(alignment: .top, spacing: 12) {
Expand All @@ -198,7 +199,7 @@ struct RecipeStepCard: View {
.accessibilityHidden(true)

VStack(alignment: .leading, spacing: 6) {
Text(recipeMarkdown(instruction?.text ?? step.text))
Text(stepText)
.font(.body)
.foregroundStyle(completed ? Color.secondary : Color.primary)
.lineSpacing(3)
Expand Down Expand Up @@ -235,7 +236,7 @@ struct RecipeStepCard: View {
.contentShape(RoundedRectangle(cornerRadius: 16))
}
.buttonStyle(RecipeStepButtonStyle())
.accessibilityLabel(Text("第 \(step.number) 步,") + Text(recipeMarkdown(instruction?.text ?? step.text)))
.accessibilityLabel(Text("第 \(step.number) 步,") + Text(stepText))
.accessibilityValue(completed ? "已完成" : "未完成")
.accessibilityHint(completed ? "轻点撤销完成" : current ? "轻点完成并前往下一步" : "轻点标记完成")
.accessibilityIdentifier("recipe.step.\(step.number)")
Expand Down Expand Up @@ -328,6 +329,33 @@ func recipeMarkdown(_ text: String) -> AttributedString {
return (try? AttributedString(markdown: text, options: options)) ?? AttributedString(text)
}

private func recipeStepMarkdown(_ text: String) -> AttributedString {
let quantity = #"(?<![A-Za-z0-9.])([0-9]+(?:\.[0-9]+)?(?:[–~/-][0-9]+(?:\.[0-9]+)?)?)[ \u00A0\u202F]*(kg|g|mL|ml|L|cm|mm)(?![A-Za-z0-9])"#
let parsed = recipeMarkdown(text)
var display = AttributedString()
for run in parsed.runs {
let segment = parsed[run.range]
guard run.link == nil else {
display += AttributedString(segment)
continue
}
let original = String(segment.characters)
var attributes = run.attributes
if var intent = run.inlinePresentationIntent, intent.contains(.code) {
// 换算后只剩数值和单位时,用正文字体;未换算的公式仍按原文显示。
guard original.range(of: "\\A\(quantity)\\z", options: .regularExpression) != nil else {
display += AttributedString(segment)
continue
}
intent.remove(.code)
attributes.inlinePresentationIntent = intent.isEmpty ? nil : intent
}
let formatted = original.replacingOccurrences(of: quantity, with: "$1\u{202F}$2", options: .regularExpression)
display += AttributedString(formatted, attributes: attributes)
}
return display
}

private struct RecipeStepCardsPreview: View {
private let steps = RecipePresentation(text: RecipeText(blocks: [
.heading("操作"),
Expand Down
71 changes: 36 additions & 35 deletions apps/ios/Cook/Views/RecipeTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,47 +98,48 @@ struct RecipeTextContent: View {
proxy.scrollTo(StepAnchor(id: step.id), anchor: .top)
}
}
ScrollView {
VStack(alignment: .leading, spacing: 16) {
if dynamicTypeSize.isAccessibilitySize {
stepProgress(jump: jump)
}
if let dietaryGoal, let entry = store.dietaryCatalog?.entry(for: recipe, goal: dietaryGoal) {
DietaryReviewSummary(goal: dietaryGoal, entry: entry)
}
RecipeMetricsView(presentation: presentation, difficulty: recipe.difficulty, showsCalories: dietaryGoal == nil)
if let description = presentation.servingDescription {
Text(description).font(.footnote).foregroundStyle(.secondary)
}
if !presentation.supplementalQuantities.isEmpty {
if canAdjustServings {
RecipeServingControl(recipeID: recipe.id, rows: presentation.allQuantities, identifier: "recipe.servings")
VStack(spacing: 0) {
if !dynamicTypeSize.isAccessibilitySize, !presentation.steps.isEmpty {
stepProgress(jump: jump)
Divider()
}
ScrollView {
VStack(alignment: .leading, spacing: 16) {
if dynamicTypeSize.isAccessibilitySize {
stepProgress(jump: jump)
}
Text("按原文整理的用量").font(.headline)
RecipeQuantityTable(rows: presentation.supplementalQuantities, amounts: amounts)
}
ForEach(Array(text.blocks.enumerated()), id: \.offset) { offset, block in
if !presentation.metadataBlocks.contains(offset),
!(preparationInSidebar && presentation.ingredientBlocks.contains(offset)) {
presentedBlock(block, at: offset, amounts: amounts, usage: usage, jump: jump)
if let dietaryGoal, let entry = store.dietaryCatalog?.entry(for: recipe, goal: dietaryGoal) {
DietaryReviewSummary(goal: dietaryGoal, entry: entry)
}
RecipeMetricsView(presentation: presentation, difficulty: recipe.difficulty, showsCalories: dietaryGoal == nil)
if let description = presentation.servingDescription {
Text(description).font(.footnote).foregroundStyle(.secondary)
}
if !presentation.supplementalQuantities.isEmpty {
if canAdjustServings {
RecipeServingControl(recipeID: recipe.id, rows: presentation.allQuantities, identifier: "recipe.servings")
}
Text("按原文整理的用量").font(.headline)
RecipeQuantityTable(rows: presentation.supplementalQuantities, amounts: amounts)
}
ForEach(Array(text.blocks.enumerated()), id: \.offset) { offset, block in
if !presentation.metadataBlocks.contains(offset),
!(preparationInSidebar && presentation.ingredientBlocks.contains(offset)) {
presentedBlock(block, at: offset, amounts: amounts, usage: usage, jump: jump)
}
}
footer
.padding(.top, 12)
}
footer
.padding(.top, 12)
.padding()
// iPad 上行太长不好读
.frame(maxWidth: 680, alignment: .leading)
.frame(maxWidth: .infinity)
}
.padding()
// iPad 上行太长不好读
.frame(maxWidth: 680, alignment: .leading)
.frame(maxWidth: .infinity)
.accessibilityLabel("菜谱做法")
.accessibilityIdentifier(preparationInSidebar ? "kitchen.instructions" : "recipe.textContent")
}
.accessibilityIdentifier("recipe.textContent")
.background(Color(uiColor: .systemGroupedBackground))
.softScrollEdges(enabled: preparationInSidebar && !dynamicTypeSize.isAccessibilitySize)
.scrollEdgeBar(edge: .top) {
if !dynamicTypeSize.isAccessibilitySize {
stepProgress(jump: jump)
}
}
// 大图里翻到别的图时,正文跟着滚过去,收起时缩回那张图的位置
.onChange(of: photoSelection) { _, id in
if showsPhotos {
Expand Down
Loading
Loading