77 lines
2.6 KiB
Swift
77 lines
2.6 KiB
Swift
//
|
|
// ClockDisplayContainer.swift
|
|
// TheNoiseClock
|
|
//
|
|
// Created by Matt Bruce on 9/8/25.
|
|
//
|
|
|
|
import SwiftUI
|
|
import Bedrock
|
|
|
|
/// Container component that handles the main clock display layout and scaling
|
|
struct ClockDisplayContainer: View {
|
|
|
|
// MARK: - Properties
|
|
let currentTime: Date
|
|
let style: ClockStyle
|
|
let isFullScreenMode: Bool
|
|
|
|
// MARK: - Body
|
|
var body: some View {
|
|
GeometryReader { geometry in
|
|
let isPortrait = geometry.size.height >= geometry.size.width
|
|
let hasOverlay = style.showBattery || style.showDate || style.showNextAlarm || style.showNoiseControls
|
|
let topSpacing = hasOverlay ? (isPortrait ? Design.Spacing.xxLarge : Design.Spacing.large) : 0
|
|
|
|
// Time display - fills all available space
|
|
TimeDisplayView(
|
|
date: currentTime,
|
|
use24Hour: style.use24Hour,
|
|
showSeconds: style.showSeconds,
|
|
showAmPm: style.showAmPm,
|
|
digitColor: style.effectiveDigitColor,
|
|
glowIntensity: style.glowIntensity,
|
|
clockOpacity: style.clockOpacity,
|
|
fontFamily: style.fontFamily,
|
|
fontWeight: style.fontWeight,
|
|
fontDesign: style.fontDesign,
|
|
forceHorizontalMode: style.forceHorizontalMode,
|
|
isDisplayMode: isFullScreenMode,
|
|
animationStyle: style.digitAnimationStyle
|
|
)
|
|
.padding(.top, topSpacing)
|
|
.frame(width: geometry.size.width, height: geometry.size.height)
|
|
.transition(.opacity)
|
|
.animation(.smooth(duration: Design.Animation.standard), value: isFullScreenMode)
|
|
.accessibilityElement(children: .ignore)
|
|
.accessibilityIdentifier("clock.timeDisplay")
|
|
.accessibilityLabel(String(localized: "clock.accessibility.current_time", defaultValue: "Current time"))
|
|
.accessibilityValue(accessibilityTimeValue)
|
|
}
|
|
}
|
|
|
|
private var accessibilityTimeValue: String {
|
|
let format: String
|
|
if style.use24Hour {
|
|
format = style.showSeconds ? "HH:mm:ss" : "HH:mm"
|
|
} else if style.showAmPm {
|
|
format = style.showSeconds ? "h:mm:ss a" : "h:mm a"
|
|
} else {
|
|
format = style.showSeconds ? "h:mm:ss" : "h:mm"
|
|
}
|
|
|
|
return currentTime.formattedForOverlay(format: format)
|
|
}
|
|
}
|
|
|
|
// MARK: - Preview
|
|
#Preview {
|
|
ClockDisplayContainer(
|
|
currentTime: Date(),
|
|
style: ClockStyle(),
|
|
isFullScreenMode: false
|
|
)
|
|
.frame(width: 400, height: 600)
|
|
.background(Color.black)
|
|
}
|