Updated the Sample app and Widget targets in the Xcode project to make the app works for visionOS.
This commit is contained in:
@@ -45,10 +45,14 @@ public struct NotificationLabelStyle: LabelStyle {
|
||||
}
|
||||
.padding(.vertical, Constant.Padding.vertical)
|
||||
.padding(.horizontal, Constant.Padding.horizontal)
|
||||
#if os(visionOS)
|
||||
.glassBackgroundEffect(in: .capsule)
|
||||
#else
|
||||
.glassEffect(
|
||||
.regular,
|
||||
in: .capsule
|
||||
)
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@ import SwiftUI
|
||||
/// The button style for the controls of a ``RecordingView``.
|
||||
///
|
||||
/// The style renders the button's label in the primary foreground color over a padded, circular Liquid Glass background — tinted by
|
||||
/// the color given at initialization — that reacts fluidly to presses. The whole button dims while disabled, and both the label and its
|
||||
/// the color given at initialization — that reacts fluidly to presses. On visionOS, where Liquid Glass is unavailable, the background is
|
||||
/// the platform's own glass material overlaid with the tint color. The whole button dims while disabled, and both the label and its
|
||||
/// padding scale relative to the current dynamic type size.
|
||||
struct RecordingButtonStyle: ButtonStyle {
|
||||
|
||||
@@ -52,6 +53,14 @@ struct RecordingButtonStyle: ButtonStyle {
|
||||
.padding(padding)
|
||||
.scaledToFit()
|
||||
.foregroundStyle(.primary.opacity(opacity))
|
||||
#if os(visionOS)
|
||||
.background(
|
||||
tintColor.opacity(Constant.Opacity.tint),
|
||||
in: .circle
|
||||
)
|
||||
.glassBackgroundEffect(in: .circle)
|
||||
.opacity(opacity)
|
||||
#else
|
||||
.glassEffect(
|
||||
.regular
|
||||
.tint(tintColor)
|
||||
@@ -59,6 +68,7 @@ struct RecordingButtonStyle: ButtonStyle {
|
||||
in: .circle
|
||||
)
|
||||
.opacity(opacity)
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
@@ -108,6 +118,8 @@ private enum Constant {
|
||||
static let disabled: Double = 0.5
|
||||
/// The opacity of an enabled button.
|
||||
static let enabled: Double = 1
|
||||
/// The opacity of the tint color laid over the glass background on visionOS.
|
||||
static let tint: Double = 0.5
|
||||
}
|
||||
|
||||
/// The padding constants.
|
||||
|
||||
@@ -81,54 +81,13 @@ public struct RecordingView: View {
|
||||
.accessibilityValue(model.textTimerAccessible)
|
||||
}
|
||||
|
||||
#if os(visionOS)
|
||||
controls
|
||||
#else
|
||||
GlassEffectContainer {
|
||||
HStack(
|
||||
spacing: Constant.Spacing.stack
|
||||
) {
|
||||
if model.shouldShowActions {
|
||||
Button {
|
||||
model.pressedDiscard()
|
||||
} label: {
|
||||
Image.Icon.discard
|
||||
.resizable()
|
||||
}
|
||||
.buttonStyle(.recording(
|
||||
tintColor: .red
|
||||
))
|
||||
.accessibilityLabel(.viewRecordingButtonDiscardLabel)
|
||||
}
|
||||
|
||||
Button {
|
||||
model.pressedMain()
|
||||
} label: {
|
||||
Image(model.iconMain)
|
||||
.resizable()
|
||||
}
|
||||
.buttonStyle(.recording(
|
||||
tintColor: .yellow
|
||||
))
|
||||
.disabled(model.shouldDisableMain)
|
||||
.accessibilityLabel(model.labelMain)
|
||||
|
||||
if model.shouldShowActions {
|
||||
Button {
|
||||
model.pressedSend()
|
||||
} label: {
|
||||
if let icon = model.iconSend {
|
||||
Image(icon)
|
||||
.resizable()
|
||||
} else {
|
||||
ProgressView()
|
||||
}
|
||||
}
|
||||
.buttonStyle(.recording(
|
||||
tintColor: .green
|
||||
))
|
||||
.disabled(model.isProcessing)
|
||||
.accessibilityLabel(model.labelSend)
|
||||
}
|
||||
}
|
||||
controls
|
||||
}
|
||||
#endif
|
||||
}
|
||||
.animation(
|
||||
.easeInOut,
|
||||
@@ -174,6 +133,64 @@ public struct RecordingView: View {
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Subviews
|
||||
|
||||
private extension RecordingView {
|
||||
|
||||
// MARK: Computed
|
||||
|
||||
/// The main, discard, and send buttons controlling the recording flow, laid out in a horizontal stack.
|
||||
var controls: some View {
|
||||
HStack(
|
||||
spacing: Constant.Spacing.stack
|
||||
) {
|
||||
if model.shouldShowActions {
|
||||
Button {
|
||||
model.pressedDiscard()
|
||||
} label: {
|
||||
Image.Icon.discard
|
||||
.resizable()
|
||||
}
|
||||
.buttonStyle(.recording(
|
||||
tintColor: .red
|
||||
))
|
||||
.accessibilityLabel(.viewRecordingButtonDiscardLabel)
|
||||
}
|
||||
|
||||
Button {
|
||||
model.pressedMain()
|
||||
} label: {
|
||||
Image(model.iconMain)
|
||||
.resizable()
|
||||
}
|
||||
.buttonStyle(.recording(
|
||||
tintColor: .yellow
|
||||
))
|
||||
.disabled(model.shouldDisableMain)
|
||||
.accessibilityLabel(model.labelMain)
|
||||
|
||||
if model.shouldShowActions {
|
||||
Button {
|
||||
model.pressedSend()
|
||||
} label: {
|
||||
if let icon = model.iconSend {
|
||||
Image(icon)
|
||||
.resizable()
|
||||
} else {
|
||||
ProgressView()
|
||||
}
|
||||
}
|
||||
.buttonStyle(.recording(
|
||||
tintColor: .green
|
||||
))
|
||||
.disabled(model.isProcessing)
|
||||
.accessibilityLabel(model.labelSend)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
/// The constant values used across the view.
|
||||
|
||||
Reference in New Issue
Block a user