mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
Update Third Party stuff
This commit is contained in:
parent
94a612f327
commit
27b16a3d15
8 changed files with 636 additions and 99 deletions
|
|
@ -9,18 +9,20 @@ struct ExtensionStandaloneLayout {
|
|||
let leadingWidth: CGFloat
|
||||
let centerWidth: CGFloat
|
||||
let trailingWidth: CGFloat
|
||||
let suppressingCenterText: Bool
|
||||
}
|
||||
|
||||
struct ExtensionLiveActivityStandaloneView: View {
|
||||
let payload: ExtensionLiveActivityPayload
|
||||
let layout: ExtensionStandaloneLayout
|
||||
let isHovering: Bool
|
||||
let notchState: NotchState
|
||||
|
||||
private var descriptor: AtollLiveActivityDescriptor { payload.descriptor }
|
||||
private var contentHeight: CGFloat { layout.contentHeight }
|
||||
private var accentColor: Color { descriptor.accentColor.swiftUIColor }
|
||||
private var resolvedLeadingContent: AtollTrailingContent {
|
||||
descriptor.leadingContent ?? .icon(descriptor.leadingIcon)
|
||||
resolvedExtensionLeadingContent(for: descriptor)
|
||||
}
|
||||
private var resolvedCenterStyle: ExtensionCenterContentView.Style {
|
||||
switch descriptor.centerTextStyle {
|
||||
|
|
@ -33,6 +35,10 @@ struct ExtensionLiveActivityStandaloneView: View {
|
|||
}
|
||||
}
|
||||
|
||||
private var shouldSuppressCenterText: Bool {
|
||||
layout.suppressingCenterText
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 0) {
|
||||
ExtensionLeadingContentView(
|
||||
|
|
@ -40,7 +46,8 @@ struct ExtensionLiveActivityStandaloneView: View {
|
|||
badge: descriptor.badgeIcon,
|
||||
accent: accentColor,
|
||||
frameWidth: layout.leadingWidth,
|
||||
frameHeight: contentHeight
|
||||
frameHeight: contentHeight,
|
||||
defaultIcon: descriptor.leadingIcon
|
||||
)
|
||||
.frame(width: layout.leadingWidth, height: contentHeight)
|
||||
|
||||
|
|
@ -48,12 +55,16 @@ struct ExtensionLiveActivityStandaloneView: View {
|
|||
.fill(Color.black)
|
||||
.frame(width: layout.centerWidth, height: contentHeight)
|
||||
.overlay(
|
||||
ExtensionCenterContentView(
|
||||
descriptor: descriptor,
|
||||
accent: accentColor,
|
||||
width: layout.centerWidth,
|
||||
style: resolvedCenterStyle
|
||||
)
|
||||
Group {
|
||||
if !shouldSuppressCenterText {
|
||||
ExtensionCenterContentView(
|
||||
descriptor: descriptor,
|
||||
accent: accentColor,
|
||||
width: layout.centerWidth,
|
||||
style: resolvedCenterStyle
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
ExtensionMusicWingView(
|
||||
|
|
@ -64,6 +75,10 @@ struct ExtensionLiveActivityStandaloneView: View {
|
|||
.frame(width: layout.trailingWidth, height: contentHeight)
|
||||
}
|
||||
.frame(width: layout.totalWidth, height: layout.outerHeight + (isHovering ? 8 : 0))
|
||||
.transition(.asymmetric(
|
||||
insertion: .scale(scale: 0.95).combined(with: .opacity).animation(.spring(response: 0.4, dampingFraction: 0.8)),
|
||||
removal: .scale(scale: 0.95).combined(with: .opacity).animation(.spring(response: 0.3, dampingFraction: 0.9))
|
||||
))
|
||||
.animation(.smooth(duration: 0.25), value: payload.id)
|
||||
.onAppear {
|
||||
logExtensionDiagnostics("Displaying extension live activity \(payload.descriptor.id) for \(payload.bundleIdentifier) as standalone view")
|
||||
|
|
@ -82,32 +97,37 @@ struct ExtensionMusicWingView: View {
|
|||
|
||||
private var descriptor: AtollLiveActivityDescriptor { payload.descriptor }
|
||||
private var accentColor: Color { descriptor.accentColor.swiftUIColor }
|
||||
private var trailingRenderable: ExtensionTrailingRenderable {
|
||||
resolvedExtensionTrailingRenderable(for: descriptor)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .trailing, spacing: 6) {
|
||||
if case .none = descriptor.trailingContent {
|
||||
EmptyView()
|
||||
} else {
|
||||
ExtensionEdgeContentView(
|
||||
content: descriptor.trailingContent,
|
||||
accent: accentColor,
|
||||
availableWidth: trailingWidth,
|
||||
alignment: .trailing
|
||||
)
|
||||
switch trailingRenderable {
|
||||
case let .content(content):
|
||||
if case .none = content {
|
||||
EmptyView()
|
||||
} else {
|
||||
ExtensionEdgeContentView(
|
||||
content: content,
|
||||
accent: accentColor,
|
||||
availableWidth: trailingWidth,
|
||||
alignment: .trailing
|
||||
)
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
}
|
||||
|
||||
if let indicator = descriptor.progressIndicator, indicator != .none {
|
||||
}
|
||||
case let .indicator(indicator):
|
||||
ExtensionProgressIndicatorView(
|
||||
indicator: indicator,
|
||||
progress: descriptor.progress,
|
||||
accent: accentColor,
|
||||
estimatedDuration: descriptor.estimatedDuration
|
||||
estimatedDuration: descriptor.estimatedDuration,
|
||||
maxVisualHeight: notchHeight
|
||||
)
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
} else {
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
|
||||
.padding(.trailing, 8)
|
||||
|
|
@ -127,23 +147,39 @@ struct ExtensionLeadingContentView: View {
|
|||
let accent: Color
|
||||
let frameWidth: CGFloat
|
||||
let frameHeight: CGFloat
|
||||
let defaultIcon: AtollIconDescriptor
|
||||
|
||||
var body: some View {
|
||||
if case let .icon(iconDescriptor) = content {
|
||||
ExtensionCompositeIconView(
|
||||
leading: iconDescriptor,
|
||||
badge: badge,
|
||||
accent: accent,
|
||||
size: frameHeight
|
||||
)
|
||||
} else {
|
||||
ExtensionEdgeContentView(
|
||||
content: content,
|
||||
accent: accent,
|
||||
availableWidth: frameWidth,
|
||||
alignment: .leading
|
||||
)
|
||||
Group {
|
||||
switch content {
|
||||
case let .icon(iconDescriptor):
|
||||
ExtensionCompositeIconView(
|
||||
leading: iconDescriptor,
|
||||
badge: badge,
|
||||
accent: accent,
|
||||
size: frameHeight
|
||||
)
|
||||
case let .animation(data, size):
|
||||
let resolvedSize = CGSize(
|
||||
width: min(size.width, frameHeight),
|
||||
height: min(size.height, frameHeight)
|
||||
)
|
||||
ExtensionLottieView(data: data, size: resolvedSize)
|
||||
.frame(width: frameHeight, height: frameHeight)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: frameHeight * 0.18, style: .continuous)
|
||||
.fill(Color.white.opacity(0.08))
|
||||
)
|
||||
default:
|
||||
ExtensionCompositeIconView(
|
||||
leading: defaultIcon,
|
||||
badge: badge,
|
||||
accent: accent,
|
||||
size: frameHeight
|
||||
)
|
||||
}
|
||||
}
|
||||
.frame(width: frameWidth, height: frameHeight)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -202,3 +238,125 @@ private func logExtensionDiagnostics(_ message: String) {
|
|||
guard Defaults[.extensionDiagnosticsLoggingEnabled] else { return }
|
||||
Logger.log(message, category: .extensions)
|
||||
}
|
||||
|
||||
struct ExtensionInlineSneakPeekView: View {
|
||||
let payload: ExtensionLiveActivityPayload?
|
||||
let title: String
|
||||
let subtitle: String
|
||||
let accentColor: Color
|
||||
let notchHeight: CGFloat
|
||||
let closedNotchWidth: CGFloat
|
||||
let isHovering: Bool
|
||||
let gestureProgress: CGFloat
|
||||
|
||||
private var descriptor: AtollLiveActivityDescriptor? { payload?.descriptor }
|
||||
private var resolvedAccent: Color { descriptor?.accentColor.swiftUIColor ?? accentColor }
|
||||
|
||||
private var contentHeight: CGFloat {
|
||||
max(0, notchHeight - (isHovering ? 0 : 12))
|
||||
}
|
||||
|
||||
private var leadingWidth: CGFloat {
|
||||
let base = max(contentHeight, 44)
|
||||
return max(base * 0.85, base + gestureProgress / 2)
|
||||
}
|
||||
|
||||
private var centerWidth: CGFloat {
|
||||
max(closedNotchWidth + (isHovering ? 8 : 0), 120)
|
||||
}
|
||||
|
||||
private var trailingWidth: CGFloat {
|
||||
guard let payload else { return max(leadingWidth, 120) }
|
||||
return ExtensionLayoutMetrics.trailingWidth(
|
||||
for: payload,
|
||||
baseWidth: leadingWidth,
|
||||
maxWidth: leadingWidth + centerWidth * 0.6
|
||||
)
|
||||
}
|
||||
|
||||
private var marqueeFrameWidth: CGFloat {
|
||||
max(48, centerWidth - 24)
|
||||
}
|
||||
|
||||
private var resolvedTitle: String {
|
||||
title.isEmpty ? "Extension" : title
|
||||
}
|
||||
|
||||
private var resolvedSubtitle: String {
|
||||
subtitle.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 0) {
|
||||
leadingWing
|
||||
.frame(width: leadingWidth, height: contentHeight)
|
||||
|
||||
Rectangle()
|
||||
.fill(Color.black)
|
||||
.frame(width: centerWidth, height: contentHeight)
|
||||
.overlay(alignment: .bottomLeading) {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
if !resolvedTitle.isEmpty {
|
||||
MarqueeText(
|
||||
.constant(resolvedTitle),
|
||||
font: .system(size: 12, weight: .semibold),
|
||||
nsFont: .subheadline,
|
||||
textColor: .white,
|
||||
minDuration: 0.4,
|
||||
frameWidth: marqueeFrameWidth
|
||||
)
|
||||
}
|
||||
if !resolvedSubtitle.isEmpty {
|
||||
Text(resolvedSubtitle)
|
||||
.font(.system(size: 11, weight: .regular))
|
||||
.foregroundStyle(Color.white.opacity(0.75))
|
||||
.lineLimit(1)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 12)
|
||||
.padding(.bottom, 6)
|
||||
}
|
||||
|
||||
trailingWing
|
||||
.frame(width: trailingWidth, height: contentHeight)
|
||||
}
|
||||
.frame(height: notchHeight + (isHovering ? 8 : 0), alignment: .center)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var leadingWing: some View {
|
||||
if let descriptor {
|
||||
ExtensionLeadingContentView(
|
||||
content: resolvedExtensionLeadingContent(for: descriptor),
|
||||
badge: descriptor.badgeIcon,
|
||||
accent: resolvedAccent,
|
||||
frameWidth: leadingWidth,
|
||||
frameHeight: contentHeight,
|
||||
defaultIcon: descriptor.leadingIcon
|
||||
)
|
||||
} else {
|
||||
RoundedRectangle(cornerRadius: contentHeight * 0.25, style: .continuous)
|
||||
.fill(resolvedAccent.gradient)
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var trailingWing: some View {
|
||||
if let payload {
|
||||
ExtensionMusicWingView(
|
||||
payload: payload,
|
||||
notchHeight: contentHeight,
|
||||
trailingWidth: trailingWidth
|
||||
)
|
||||
} else {
|
||||
Rectangle()
|
||||
.fill(resolvedAccent.gradient)
|
||||
.mask {
|
||||
AudioSpectrumView(isPlaying: .constant(true))
|
||||
.frame(width: 18, height: 12)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
import SwiftUI
|
||||
import AppKit
|
||||
import AtollExtensionKit
|
||||
import Lottie
|
||||
import LottieUI
|
||||
import CryptoKit
|
||||
|
||||
// MARK: - Color Conversion
|
||||
|
||||
|
|
@ -130,7 +133,15 @@ struct ExtensionIconView: View {
|
|||
} else {
|
||||
fallbackSymbol
|
||||
}
|
||||
case .lottie, .none:
|
||||
case let .lottie(animationData, targetSize):
|
||||
let resolvedSize = CGSize(width: min(targetSize.width, size.width), height: min(targetSize.height, size.height))
|
||||
ExtensionLottieView(data: animationData, size: resolvedSize)
|
||||
.frame(width: size.width, height: size.height)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: cornerRadius(for: descriptor), style: .continuous)
|
||||
.fill(Color.white.opacity(0.08))
|
||||
)
|
||||
case .none:
|
||||
fallbackSymbol
|
||||
}
|
||||
}
|
||||
|
|
@ -187,6 +198,69 @@ struct ExtensionCompositeIconView: View {
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: - Lottie Rendering
|
||||
|
||||
struct ExtensionLottieView: View {
|
||||
let data: Data
|
||||
let size: CGSize
|
||||
var loopMode: LottieLoopMode = .loop
|
||||
@State private var cachedURL: URL?
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
if let cachedURL {
|
||||
LottieView(
|
||||
state: LUStateData(
|
||||
type: .loadedFrom(cachedURL),
|
||||
speed: 1.0,
|
||||
loopMode: loopMode
|
||||
)
|
||||
)
|
||||
} else {
|
||||
ProgressView()
|
||||
.controlSize(.small)
|
||||
.tint(.white.opacity(0.7))
|
||||
}
|
||||
}
|
||||
.frame(width: size.width, height: size.height)
|
||||
.task {
|
||||
if cachedURL == nil {
|
||||
cachedURL = ExtensionLottieCache.shared.url(for: data)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class ExtensionLottieCache {
|
||||
static let shared = ExtensionLottieCache()
|
||||
private let queue = DispatchQueue(label: "com.atoll.extension-lottie-cache")
|
||||
private var cache: [String: URL] = [:]
|
||||
|
||||
func url(for data: Data) -> URL? {
|
||||
queue.sync {
|
||||
let key = Self.hash(data: data)
|
||||
if let existing = cache[key], FileManager.default.fileExists(atPath: existing.path) {
|
||||
return existing
|
||||
}
|
||||
|
||||
let url = FileManager.default.temporaryDirectory.appendingPathComponent("extension-lottie-\(key).json", conformingTo: .json)
|
||||
do {
|
||||
try data.write(to: url, options: .atomic)
|
||||
cache[key] = url
|
||||
return url
|
||||
} catch {
|
||||
cache.removeValue(forKey: key)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static func hash(data: Data) -> String {
|
||||
let digest = SHA256.hash(data: data)
|
||||
return digest.map { String(format: "%02x", $0) }.joined()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Progress Rendering
|
||||
|
||||
struct ExtensionProgressIndicatorView: View {
|
||||
|
|
@ -194,39 +268,59 @@ struct ExtensionProgressIndicatorView: View {
|
|||
let progress: Double
|
||||
let accent: Color
|
||||
let estimatedDuration: TimeInterval?
|
||||
let maxVisualHeight: CGFloat?
|
||||
|
||||
init(
|
||||
indicator: AtollProgressIndicator,
|
||||
progress: Double,
|
||||
accent: Color,
|
||||
estimatedDuration: TimeInterval?,
|
||||
maxVisualHeight: CGFloat? = nil
|
||||
) {
|
||||
self.indicator = indicator
|
||||
self.progress = progress
|
||||
self.accent = accent
|
||||
self.estimatedDuration = estimatedDuration
|
||||
self.maxVisualHeight = maxVisualHeight
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
switch indicator {
|
||||
case let .ring(diameter, strokeWidth):
|
||||
case let .ring(diameter, strokeWidth, color):
|
||||
let ringColor = color?.swiftUIColor ?? accent
|
||||
let resolvedDiameter = resolvedRingDiameter(requested: diameter)
|
||||
ZStack {
|
||||
Circle()
|
||||
.stroke(Color.white.opacity(0.15), lineWidth: strokeWidth)
|
||||
Circle()
|
||||
.trim(from: 0, to: CGFloat(max(0, min(progress, 1))))
|
||||
.stroke(accent, style: StrokeStyle(lineWidth: strokeWidth, lineCap: .round))
|
||||
.stroke(ringColor, style: StrokeStyle(lineWidth: strokeWidth, lineCap: .round))
|
||||
.rotationEffect(.degrees(-90))
|
||||
.animation(.smooth(duration: 0.25), value: progress)
|
||||
}
|
||||
.frame(width: diameter, height: diameter)
|
||||
case let .bar(width, height, cornerRadius):
|
||||
.frame(width: resolvedDiameter, height: resolvedDiameter)
|
||||
case let .bar(width, height, cornerRadius, color):
|
||||
let barColor = color?.swiftUIColor ?? accent
|
||||
Capsule()
|
||||
.fill(Color.white.opacity(0.18))
|
||||
.frame(width: width ?? 80, height: height)
|
||||
.overlay(alignment: .leading) {
|
||||
Capsule()
|
||||
.fill(accent)
|
||||
.fill(barColor)
|
||||
.frame(width: (width ?? 80) * CGFloat(max(0, min(progress, 1))), height: height)
|
||||
.animation(.smooth(duration: 0.25), value: progress)
|
||||
}
|
||||
case let .percentage(font):
|
||||
case let .percentage(font, color):
|
||||
let textColor = color?.swiftUIColor ?? accent
|
||||
Text("\(Int(progress * 100))%")
|
||||
.font(font.swiftUIFont())
|
||||
.foregroundStyle(accent)
|
||||
.foregroundStyle(textColor)
|
||||
.monospacedDigit()
|
||||
case let .countdown(font):
|
||||
case let .countdown(font, color):
|
||||
let textColor = color?.swiftUIColor ?? accent
|
||||
Text(countdownText)
|
||||
.font(font.swiftUIFont())
|
||||
.foregroundStyle(accent)
|
||||
.foregroundStyle(textColor)
|
||||
.monospacedDigit()
|
||||
case .lottie:
|
||||
Image(systemName: "sparkles")
|
||||
|
|
@ -252,6 +346,12 @@ struct ExtensionProgressIndicatorView: View {
|
|||
private var formatPercent: String {
|
||||
"\(Int(progress * 100))%"
|
||||
}
|
||||
|
||||
private func resolvedRingDiameter(requested: CGFloat) -> CGFloat {
|
||||
guard let maxVisualHeight else { return requested }
|
||||
let clamped = min(requested, max(maxVisualHeight - 6, 18))
|
||||
return max(18, clamped)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Edge Content Rendering
|
||||
|
|
@ -264,23 +364,23 @@ struct ExtensionEdgeContentView: View {
|
|||
|
||||
var body: some View {
|
||||
switch content {
|
||||
case let .text(value, font: font):
|
||||
case let .text(value, font: font, color: color):
|
||||
Text(value)
|
||||
.font(font.swiftUIFont())
|
||||
.foregroundStyle(accent)
|
||||
.foregroundStyle(resolvedColor(color))
|
||||
.lineLimit(1)
|
||||
.frame(maxWidth: .infinity, alignment: alignment)
|
||||
case let .marquee(value, font: font, minDuration: duration):
|
||||
case let .marquee(value, font: font, minDuration: duration, color: color):
|
||||
MarqueeText(
|
||||
.constant(value),
|
||||
font: font.swiftUIFont(),
|
||||
nsFont: .body,
|
||||
textColor: accent,
|
||||
textColor: resolvedColor(color),
|
||||
minDuration: duration,
|
||||
frameWidth: max(24, availableWidth - 12)
|
||||
)
|
||||
case let .countdownText(targetDate, font: font):
|
||||
ExtensionCountdownTextView(targetDate: targetDate, font: font, accent: accent)
|
||||
case let .countdownText(targetDate, font: font, color: color):
|
||||
ExtensionCountdownTextView(targetDate: targetDate, font: font, accent: accent, customColor: color?.swiftUIColor)
|
||||
.frame(maxWidth: .infinity, alignment: alignment)
|
||||
case let .icon(descriptor):
|
||||
ExtensionIconView(
|
||||
|
|
@ -297,26 +397,30 @@ struct ExtensionEdgeContentView: View {
|
|||
AudioSpectrumView(isPlaying: .constant(true))
|
||||
.frame(width: 16, height: 12)
|
||||
}
|
||||
case .animation:
|
||||
Image(systemName: "sparkles")
|
||||
.font(.system(size: 14, weight: .medium))
|
||||
.foregroundStyle(accent)
|
||||
case let .animation(data, size):
|
||||
let resolvedWidth = min(size.width, availableWidth)
|
||||
ExtensionLottieView(data: data, size: CGSize(width: resolvedWidth, height: size.height))
|
||||
case .none:
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
|
||||
private func resolvedColor(_ descriptorColor: AtollColorDescriptor?) -> Color {
|
||||
descriptorColor?.swiftUIColor ?? accent
|
||||
}
|
||||
}
|
||||
|
||||
struct ExtensionCountdownTextView: View {
|
||||
let targetDate: Date
|
||||
let font: AtollFontDescriptor
|
||||
let accent: Color
|
||||
let customColor: Color?
|
||||
|
||||
var body: some View {
|
||||
TimelineView(.periodic(from: .now, by: 1)) { context in
|
||||
Text(formattedRemaining(since: context.date))
|
||||
.font(font.swiftUIFont())
|
||||
.foregroundStyle(accent)
|
||||
.foregroundStyle(customColor ?? accent)
|
||||
.monospacedDigit()
|
||||
}
|
||||
}
|
||||
|
|
@ -337,8 +441,13 @@ struct ExtensionCountdownTextView: View {
|
|||
|
||||
enum ExtensionLayoutMetrics {
|
||||
static func trailingWidth(for payload: ExtensionLiveActivityPayload, baseWidth: CGFloat, maxWidth: CGFloat? = nil) -> CGFloat {
|
||||
var width = edgeWidth(for: payload.descriptor.trailingContent, baseWidth: baseWidth, maxWidth: maxWidth)
|
||||
if let indicator = payload.descriptor.progressIndicator {
|
||||
let renderable = resolvedExtensionTrailingRenderable(for: payload.descriptor)
|
||||
var width: CGFloat
|
||||
switch renderable {
|
||||
case let .content(content):
|
||||
width = edgeWidth(for: content, baseWidth: baseWidth, maxWidth: maxWidth)
|
||||
case let .indicator(indicator):
|
||||
width = edgeWidth(for: .none, baseWidth: baseWidth, maxWidth: maxWidth)
|
||||
width = max(width, widthForProgress(indicator))
|
||||
}
|
||||
if let maxWidth {
|
||||
|
|
@ -357,13 +466,13 @@ enum ExtensionLayoutMetrics {
|
|||
|
||||
private static func widthForContent(_ content: AtollTrailingContent, baseWidth: CGFloat) -> CGFloat {
|
||||
switch content {
|
||||
case let .text(text, font: font):
|
||||
case let .text(text, font: font, color: _):
|
||||
let measured = ExtensionTextMeasurer.width(for: text, font: font.nsFont())
|
||||
return max(baseWidth, measured + 32)
|
||||
case let .marquee(text, font: font, _):
|
||||
case let .marquee(text, font: font, minDuration: _, color: _):
|
||||
let measured = ExtensionTextMeasurer.width(for: text, font: font.nsFont())
|
||||
return max(baseWidth, min(measured + 40, baseWidth * 2))
|
||||
case let .countdownText(targetDate, font: font):
|
||||
case let .countdownText(targetDate, font: font, color: _):
|
||||
let sample = targetDate.timeIntervalSinceNow >= 3600 ? "00:00:00" : "00:00"
|
||||
let measured = ExtensionTextMeasurer.width(for: sample, font: font.nsFont())
|
||||
return max(baseWidth, measured + 24)
|
||||
|
|
@ -380,13 +489,13 @@ enum ExtensionLayoutMetrics {
|
|||
|
||||
private static func widthForProgress(_ indicator: AtollProgressIndicator) -> CGFloat {
|
||||
switch indicator {
|
||||
case let .ring(diameter, _):
|
||||
case let .ring(diameter, _, _):
|
||||
return diameter + 20
|
||||
case let .bar(width, _, _):
|
||||
case let .bar(width, _, _, _):
|
||||
return (width ?? 72) + 12
|
||||
case .percentage:
|
||||
case .percentage(_, _):
|
||||
return 60
|
||||
case .countdown:
|
||||
case .countdown(_, _):
|
||||
return 74
|
||||
case let .lottie(_, size):
|
||||
return size.width + 16
|
||||
|
|
@ -402,3 +511,41 @@ enum ExtensionTextMeasurer {
|
|||
return max(1, text.size(withAttributes: attributes).width)
|
||||
}
|
||||
}
|
||||
|
||||
enum ExtensionTrailingRenderable {
|
||||
case content(AtollTrailingContent)
|
||||
case indicator(AtollProgressIndicator)
|
||||
}
|
||||
|
||||
func resolvedExtensionLeadingContent(for descriptor: AtollLiveActivityDescriptor) -> AtollTrailingContent {
|
||||
guard let override = descriptor.leadingContent else {
|
||||
return .icon(descriptor.leadingIcon)
|
||||
}
|
||||
|
||||
switch override {
|
||||
case .icon, .animation:
|
||||
return override
|
||||
default:
|
||||
return .icon(descriptor.leadingIcon)
|
||||
}
|
||||
}
|
||||
|
||||
func resolvedExtensionTrailingRenderable(for descriptor: AtollLiveActivityDescriptor) -> ExtensionTrailingRenderable {
|
||||
if let indicator = descriptor.progressIndicator,
|
||||
indicator.isRenderable,
|
||||
descriptor.trailingContent == .none {
|
||||
return .indicator(indicator)
|
||||
}
|
||||
return .content(descriptor.trailingContent)
|
||||
}
|
||||
|
||||
private extension AtollProgressIndicator {
|
||||
var isRenderable: Bool {
|
||||
switch self {
|
||||
case .none:
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue