Adopted Liquid Glass effect for the RecordingButtonStyle button style in the Recording package target.

This commit is contained in:
2026-07-04 10:04:41 +02:00
parent aa9ec01611
commit a9eff33e3e
@@ -2,8 +2,9 @@ import SwiftUI
/// The button style for the controls of a ``RecordingView``.
///
/// The style renders the button's label, filled with the background color of the label's color scheme, over a padded, circular red background, shrinks it
/// slightly while pressed, and dims it while disabled. Both the label and its padding scale relative to the current dynamic type size.
/// The style renders the button's label, filled with the background color of the label's color scheme, over a padded, circular red Liquid Glass
/// background that reacts fluidly to presses, and dims the button while disabled. Both the label and its padding scale relative to the current
/// dynamic type size.
///
/// By default, the label's color scheme is inverted from the environment's, so its fill contrasts with the surroundings; this behavior can be turned off
/// through the ``init(invertStyle:)`` initializer.
@@ -52,21 +53,18 @@ struct RecordingButtonStyle: ButtonStyle {
)
.padding(padding)
.scaledToFit()
.foregroundStyle(.background)
.foregroundStyle(.windowBackground)
.environment(
\.colorScheme,
colorSchemeLabel
)
.background(
Circle()
.fill(.red)
.glassEffect(
.regular
.tint(.red)
.interactive(),
in: .circle
)
.opacity(opacity)
.scaleEffect(scaleEffect(configuration.isPressed))
.animation(
.easeOut(duration: Constant.Animation.duration),
value: configuration.isPressed
)
}
}
@@ -94,21 +92,7 @@ private extension RecordingButtonStyle {
? Constant.Opacity.enabled
: Constant.Opacity.disabled
}
// MARK: Methods
/// Provides the scale of the button for a press state.
///
/// - Parameter isPressed: Whether the button is currently pressed.
/// - Returns: A slightly shrunken scale while pressed, the resting scale otherwise.
func scaleEffect(
_ isPressed: Bool
) -> CGFloat {
isPressed
? Constant.Scale.pressed
: Constant.Scale.idle
}
}
// MARK: - Styles
@@ -136,34 +120,20 @@ extension ButtonStyle where Self == RecordingButtonStyle {
/// The constant values used across the button style.
private enum Constant {
/// The animation constants.
enum Animation {
/// The duration of the press animation.
static let duration: TimeInterval = 0.15
}
/// The opacity constants.
enum Opacity {
/// The opacity of a disabled button.
static let disabled: Double = 0.4
static let disabled: Double = 0.5
/// The opacity of an enabled button.
static let enabled: Double = 1
}
/// The padding constants.
enum Padding {
/// The base padding between a button's label and its background, before dynamic type scaling.
static let button: CGFloat = 8
}
/// The scale constants.
enum Scale {
/// The scale of a button at rest.
static let idle: CGFloat = 1
/// The scale of a button while pressed.
static let pressed: CGFloat = 0.85
}
/// The size constants.
enum Size {
/// The base width and height of a button's label, before dynamic type scaling.