From ce0e147ad184bac523817b6282a8d55968b6b1d3 Mon Sep 17 00:00:00 2001 From: Cay Zhang <13341339+Cay-Zhang@users.noreply.github.com> Date: Fri, 9 Feb 2024 11:57:23 -0600 Subject: [PATCH] Fix regressions --- Shared/BottomBar.swift | 17 ++++++++++++----- Shared/Extensions/ButtonStyling.swift | 10 ++++++---- Shared/Extensions/Extensions.swift | 5 ++++- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Shared/BottomBar.swift b/Shared/BottomBar.swift index cc9f4f33..c8a3a9c0 100644 --- a/Shared/BottomBar.swift +++ b/Shared/BottomBar.swift @@ -192,22 +192,22 @@ struct BottomBar: View { isTextFieldFocused = false assert(viewModel.dragTranslationYDelta == 0, "dragTranslationYDelta should not accumulate.") viewModel.dragTranslationYDelta = -rawTranslation.height - 45 -// Self.feedbackGenerator.selectionChanged() + Self.playSensoryFeedback() } } else if translation.height < -50 { if !viewModel.isEditing { viewModel.isEditing = true -// Self.feedbackGenerator.selectionChanged() + Self.playSensoryFeedback() } } else if translation.height > 15 { if !viewModel.isEditing { viewModel._isEditing = true viewModel.editingText = "" -// Self.feedbackGenerator.selectionChanged() + Self.playSensoryFeedback() } } else if viewModel.isEditing && viewModel.linkURL != nil { viewModel.isEditing = false -// Self.feedbackGenerator.selectionChanged() + Self.playSensoryFeedback() } } } @@ -299,7 +299,14 @@ extension BottomBar { } extension BottomBar { -// static let feedbackGenerator: UISelectionFeedbackGenerator = UISelectionFeedbackGenerator() +#if os(visionOS) + static func playSensoryFeedback() { } +#else + static let sensoryFeedbackGenerator: UISelectionFeedbackGenerator = UISelectionFeedbackGenerator() + static func playSensoryFeedback() { + sensoryFeedbackGenerator.selectionChanged() + } +#endif static var transitionAnimation: Animation { Animation.interpolatingSpring(mass: 3, stiffness: 1000, damping: 500, initialVelocity: 0) } static var contentTransition: AnyTransition { AnyTransition.offset(y: 25).combined(with: AnyTransition.opacity) diff --git a/Shared/Extensions/ButtonStyling.swift b/Shared/Extensions/ButtonStyling.swift index 61e8ec7e..18424cf8 100644 --- a/Shared/Extensions/ButtonStyling.swift +++ b/Shared/Extensions/ButtonStyling.swift @@ -85,13 +85,15 @@ struct CayMenuStyle: MenuStyle { } } -//extension UIImpactFeedbackGenerator { -// static let light: UIImpactFeedbackGenerator = UIImpactFeedbackGenerator(style: .light) -//} +#if os(visionOS) +fileprivate func playButtonSensoryFeedback() { } +#else +fileprivate let buttonSensoryFeedbackGenerator: UIImpactFeedbackGenerator = UIImpactFeedbackGenerator(style: .light) fileprivate func playButtonSensoryFeedback() { -// UIImpactFeedbackGenerator.light.impactOccurred(intensity: 0.5) + buttonSensoryFeedbackGenerator.impactOccurred(intensity: 0.5) } +#endif struct WideButtonContainerModifier: ViewModifier { @ScaledMetric var height: CGFloat = 42 diff --git a/Shared/Extensions/Extensions.swift b/Shared/Extensions/Extensions.swift index 95342e0d..64113c38 100644 --- a/Shared/Extensions/Extensions.swift +++ b/Shared/Extensions/Extensions.swift @@ -384,8 +384,11 @@ extension LPLinkMetadata { if let provider = self.iconProvider { var data = try? await provider.loadDataRepresentation(forTypeIdentifier: UTType.image.identifier) if data == nil { data = try? await provider.loadDataRepresentation(forTypeIdentifier: "dyn.agq80w5pbq7ww88brrfv085u") } -// let scale = await UIScreen.main.scale +#if os(visionOS) let scale = 3.0 +#else + let scale = await UIScreen.main.scale +#endif return data .flatMap { UIImage(data: $0, scale: scale) } } else {