Adopted Liquid Glass effect for the RecordingButtonStyle button style in the Recording package target.
This commit is contained in:
@@ -2,8 +2,9 @@ import SwiftUI
|
|||||||
|
|
||||||
/// The button style for the controls of a ``RecordingView``.
|
/// 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
|
/// 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
|
||||||
/// slightly while pressed, and dims it while disabled. Both the label and its padding scale relative to the current dynamic type size.
|
/// 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
|
/// 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.
|
/// through the ``init(invertStyle:)`` initializer.
|
||||||
@@ -52,21 +53,18 @@ struct RecordingButtonStyle: ButtonStyle {
|
|||||||
)
|
)
|
||||||
.padding(padding)
|
.padding(padding)
|
||||||
.scaledToFit()
|
.scaledToFit()
|
||||||
.foregroundStyle(.background)
|
.foregroundStyle(.windowBackground)
|
||||||
.environment(
|
.environment(
|
||||||
\.colorScheme,
|
\.colorScheme,
|
||||||
colorSchemeLabel
|
colorSchemeLabel
|
||||||
)
|
)
|
||||||
.background(
|
.glassEffect(
|
||||||
Circle()
|
.regular
|
||||||
.fill(.red)
|
.tint(.red)
|
||||||
|
.interactive(),
|
||||||
|
in: .circle
|
||||||
)
|
)
|
||||||
.opacity(opacity)
|
.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.enabled
|
||||||
: Constant.Opacity.disabled
|
: 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
|
// MARK: - Styles
|
||||||
@@ -136,34 +120,20 @@ extension ButtonStyle where Self == RecordingButtonStyle {
|
|||||||
|
|
||||||
/// The constant values used across the button style.
|
/// The constant values used across the button style.
|
||||||
private enum Constant {
|
private enum Constant {
|
||||||
/// The animation constants.
|
|
||||||
enum Animation {
|
|
||||||
/// The duration of the press animation.
|
|
||||||
static let duration: TimeInterval = 0.15
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The opacity constants.
|
/// The opacity constants.
|
||||||
enum Opacity {
|
enum Opacity {
|
||||||
/// The opacity of a disabled button.
|
/// The opacity of a disabled button.
|
||||||
static let disabled: Double = 0.4
|
static let disabled: Double = 0.5
|
||||||
/// The opacity of an enabled button.
|
/// The opacity of an enabled button.
|
||||||
static let enabled: Double = 1
|
static let enabled: Double = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The padding constants.
|
/// The padding constants.
|
||||||
enum Padding {
|
enum Padding {
|
||||||
/// The base padding between a button's label and its background, before dynamic type scaling.
|
/// The base padding between a button's label and its background, before dynamic type scaling.
|
||||||
static let button: CGFloat = 8
|
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.
|
/// The size constants.
|
||||||
enum Size {
|
enum Size {
|
||||||
/// The base width and height of a button's label, before dynamic type scaling.
|
/// The base width and height of a button's label, before dynamic type scaling.
|
||||||
|
|||||||
Reference in New Issue
Block a user