APP-PUSH和纯色小组件
This commit is contained in:
@@ -237,48 +237,22 @@ struct EmotionWidgetView: View {
|
||||
var entry: EmotionProvider.Entry
|
||||
@Environment(\.widgetFamily) var family
|
||||
private let deepLink = URL(string: "client:///(app)/home")
|
||||
private let widgetBackgroundColor = Color(red: 1.0, green: 250.0 / 255.0, blue: 229.0 / 255.0) // #FFFAE5
|
||||
private let widgetTextColor = Color(red: 98.0 / 255.0, green: 59.0 / 255.0, blue: 59.0 / 255.0) // #623B3B
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
cardBackground(colors: [
|
||||
Color(red: 0.06, green: 0.08, blue: 0.12),
|
||||
Color(red: 0.14, green: 0.18, blue: 0.28),
|
||||
])
|
||||
|
||||
// 只显示一句话(不显示标题/提示/时间等装饰元素)
|
||||
Text(entry.text)
|
||||
.font(fontForFamily())
|
||||
.foregroundColor(Color.white.opacity(0.92))
|
||||
.multilineTextAlignment(.leading)
|
||||
.lineSpacing(lineSpacingForFamily())
|
||||
.lineLimit(lineLimitForFamily())
|
||||
.minimumScaleFactor(0.78)
|
||||
.padding(paddingForFamily())
|
||||
}
|
||||
.widgetURL(deepLink)
|
||||
}
|
||||
|
||||
// 统一的“卡片背景”风格(iOS 15 兼容)
|
||||
private func cardBackground(colors: [Color]) -> some View {
|
||||
ZStack {
|
||||
LinearGradient(
|
||||
colors: colors,
|
||||
startPoint: .topLeading,
|
||||
endPoint: .bottomTrailing
|
||||
)
|
||||
// 轻微光斑,增加层次
|
||||
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)
|
||||
// 只显示一句话(不显示标题/提示/时间等装饰元素)
|
||||
Text(entry.text)
|
||||
.font(fontForFamily())
|
||||
.foregroundColor(widgetTextColor)
|
||||
.multilineTextAlignment(.leading)
|
||||
.lineSpacing(lineSpacingForFamily())
|
||||
.lineLimit(lineLimitForFamily())
|
||||
.minimumScaleFactor(0.78)
|
||||
.padding(paddingForFamily())
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
|
||||
.widgetSolidBackground(widgetBackgroundColor)
|
||||
.widgetURL(deepLink)
|
||||
}
|
||||
|
||||
private func fontForFamily() -> Font {
|
||||
@@ -330,6 +304,26 @@ struct EmotionWidgetView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private struct WidgetSolidBackgroundModifier: ViewModifier {
|
||||
let color: Color
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
if #available(iOSApplicationExtension 17.0, *) {
|
||||
content.containerBackground(for: .widget) { color }
|
||||
} else {
|
||||
content
|
||||
.background(color)
|
||||
.ignoresSafeArea()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension View {
|
||||
func widgetSolidBackground(_ color: Color) -> some View {
|
||||
modifier(WidgetSolidBackgroundModifier(color: color))
|
||||
}
|
||||
}
|
||||
|
||||
@main
|
||||
struct EmotionWidget: Widget {
|
||||
let kind: String = "EmotionWidget"
|
||||
|
||||
Reference in New Issue
Block a user