fix:新增IOS小组件
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
//
|
||||
// AppIntent.swift
|
||||
// 情绪小组件
|
||||
//
|
||||
// Created by jojo on 2026/1/28.
|
||||
//
|
||||
|
||||
import WidgetKit
|
||||
import AppIntents
|
||||
|
||||
struct ConfigurationAppIntent: WidgetConfigurationIntent {
|
||||
static var title: LocalizedStringResource { "Configuration" }
|
||||
static var description: IntentDescription { "This is an example widget." }
|
||||
|
||||
// An example configurable parameter.
|
||||
@Parameter(title: "Favorite Emoji", default: "😃")
|
||||
var favoriteEmoji: String
|
||||
}
|
||||
@@ -46,20 +46,63 @@ struct EmotionWidgetView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private func smallView() -> some View {
|
||||
// 统一的“卡片背景”风格(iOS 15 兼容)
|
||||
private func cardBackground(colors: [Color]) -> some View {
|
||||
ZStack {
|
||||
LinearGradient(
|
||||
colors: [Color(red: 0.07, green: 0.09, blue: 0.13), Color(red: 0.15, green: 0.18, blue: 0.26)],
|
||||
colors: colors,
|
||||
startPoint: .topLeading,
|
||||
endPoint: .bottomTrailing
|
||||
)
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text(title).font(.headline).foregroundStyle(.white)
|
||||
// 轻微光斑,增加层次
|
||||
RadialGradient(
|
||||
gradient: Gradient(colors: [Color.white.opacity(0.16), Color.white.opacity(0.0)]),
|
||||
center: .topTrailing,
|
||||
startRadius: 10,
|
||||
endRadius: 180
|
||||
)
|
||||
}
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 18, style: .continuous)
|
||||
.stroke(Color.white.opacity(0.14), lineWidth: 1)
|
||||
)
|
||||
.cornerRadius(18)
|
||||
}
|
||||
|
||||
private func chip(_ text: String) -> some View {
|
||||
Text(text)
|
||||
.font(.system(size: 12, weight: .semibold))
|
||||
.foregroundColor(Color.white.opacity(0.9))
|
||||
.padding(.horizontal, 10)
|
||||
.padding(.vertical, 6)
|
||||
.background(Color.white.opacity(0.14))
|
||||
.cornerRadius(999)
|
||||
}
|
||||
|
||||
private func smallView() -> some View {
|
||||
ZStack {
|
||||
cardBackground(colors: [
|
||||
Color(red: 0.06, green: 0.08, blue: 0.12),
|
||||
Color(red: 0.13, green: 0.16, blue: 0.22),
|
||||
])
|
||||
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
HStack {
|
||||
chip(title)
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
|
||||
Text(text)
|
||||
.font(.system(size: 14, weight: .semibold))
|
||||
.foregroundStyle(Color.white.opacity(0.92))
|
||||
.font(.system(size: 15, weight: .semibold))
|
||||
.foregroundColor(Color.white.opacity(0.92))
|
||||
.lineSpacing(2)
|
||||
.lineLimit(4)
|
||||
|
||||
Spacer(minLength: 0)
|
||||
|
||||
Text("点我回到 App")
|
||||
.font(.system(size: 11, weight: .medium))
|
||||
.foregroundColor(Color.white.opacity(0.65))
|
||||
}
|
||||
.padding(14)
|
||||
}
|
||||
@@ -68,21 +111,37 @@ struct EmotionWidgetView: View {
|
||||
|
||||
private func mediumView() -> some View {
|
||||
ZStack {
|
||||
LinearGradient(
|
||||
colors: [Color(red: 0.07, green: 0.09, blue: 0.13), Color(red: 0.10, green: 0.12, blue: 0.18)],
|
||||
startPoint: .topLeading,
|
||||
endPoint: .bottomTrailing
|
||||
)
|
||||
HStack(spacing: 14) {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text(title).font(.headline).foregroundStyle(.white)
|
||||
cardBackground(colors: [
|
||||
Color(red: 0.06, green: 0.08, blue: 0.12),
|
||||
Color(red: 0.09, green: 0.11, blue: 0.17),
|
||||
])
|
||||
|
||||
HStack(alignment: .top, spacing: 14) {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
chip(title)
|
||||
Text(text)
|
||||
.font(.system(size: 16, weight: .semibold))
|
||||
.foregroundStyle(Color.white.opacity(0.92))
|
||||
.font(.system(size: 17, weight: .semibold))
|
||||
.foregroundColor(Color.white.opacity(0.92))
|
||||
.lineSpacing(3)
|
||||
.lineLimit(5)
|
||||
|
||||
Spacer(minLength: 0)
|
||||
|
||||
Text("轻轻呼吸,回到当下")
|
||||
.font(.system(size: 12, weight: .medium))
|
||||
.foregroundColor(Color.white.opacity(0.7))
|
||||
}
|
||||
|
||||
// 右侧装饰区:让版面更饱满
|
||||
VStack(alignment: .trailing, spacing: 8) {
|
||||
Text(entry.date, style: .time)
|
||||
.font(.system(size: 12, weight: .semibold))
|
||||
.foregroundColor(Color.white.opacity(0.8))
|
||||
Spacer(minLength: 0)
|
||||
Text("今日")
|
||||
.font(.system(size: 28, weight: .bold))
|
||||
.foregroundColor(Color.white.opacity(0.12))
|
||||
}
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
.padding(16)
|
||||
}
|
||||
@@ -91,24 +150,37 @@ struct EmotionWidgetView: View {
|
||||
|
||||
private func largeView() -> some View {
|
||||
ZStack {
|
||||
LinearGradient(
|
||||
colors: [Color(red: 0.07, green: 0.09, blue: 0.13), Color(red: 0.17, green: 0.22, blue: 0.32)],
|
||||
startPoint: .topLeading,
|
||||
endPoint: .bottomTrailing
|
||||
)
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text(title)
|
||||
.font(.title3)
|
||||
.foregroundStyle(.white)
|
||||
.bold()
|
||||
cardBackground(colors: [
|
||||
Color(red: 0.06, green: 0.08, blue: 0.12),
|
||||
Color(red: 0.14, green: 0.18, blue: 0.28),
|
||||
])
|
||||
|
||||
VStack(alignment: .leading, spacing: 14) {
|
||||
HStack {
|
||||
chip(title)
|
||||
Spacer(minLength: 0)
|
||||
Text(entry.date, style: .time)
|
||||
.font(.system(size: 12, weight: .semibold))
|
||||
.foregroundColor(Color.white.opacity(0.78))
|
||||
}
|
||||
|
||||
Text(text)
|
||||
.font(.system(size: 18, weight: .semibold))
|
||||
.foregroundStyle(Color.white.opacity(0.92))
|
||||
.lineLimit(7)
|
||||
.font(.system(size: 20, weight: .semibold))
|
||||
.foregroundColor(Color.white.opacity(0.92))
|
||||
.lineSpacing(4)
|
||||
.lineLimit(8)
|
||||
|
||||
Spacer(minLength: 0)
|
||||
Text("轻轻呼吸,回到当下")
|
||||
.font(.footnote)
|
||||
.foregroundStyle(Color.white.opacity(0.7))
|
||||
|
||||
HStack {
|
||||
Text("点我回到 Home")
|
||||
.font(.system(size: 12, weight: .medium))
|
||||
.foregroundColor(Color.white.opacity(0.7))
|
||||
Spacer(minLength: 0)
|
||||
Text("🌿")
|
||||
.font(.system(size: 18))
|
||||
.opacity(0.9)
|
||||
}
|
||||
}
|
||||
.padding(18)
|
||||
}
|
||||
@@ -116,6 +188,7 @@ struct EmotionWidgetView: View {
|
||||
}
|
||||
}
|
||||
|
||||
@main
|
||||
struct EmotionWidget: Widget {
|
||||
let kind: String = "EmotionWidget"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user