Helper+ButtonStyles.swift 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import SwiftUI
  2. struct WatchOSButtonStyle: ButtonStyle {
  3. let deviceType: WatchSize
  4. var foregroundColor: Color = .white
  5. var fontSize: Font = .title2
  6. private var fontWeight: Font.Weight {
  7. switch deviceType {
  8. case .watch40mm:
  9. return .medium
  10. case .watch41mm:
  11. return .medium
  12. case .watch42mm:
  13. return .medium
  14. case .watch44mm:
  15. return .semibold
  16. case .watch45mm:
  17. return .semibold
  18. case .watch49mm:
  19. return .bold
  20. case .unknown:
  21. return .semibold
  22. }
  23. }
  24. private var buttonPadding: CGFloat {
  25. switch deviceType {
  26. case .watch40mm:
  27. return 6
  28. case .watch41mm:
  29. return 6
  30. case .watch42mm:
  31. return 6
  32. case .watch44mm:
  33. return 8
  34. case .watch45mm:
  35. return 8
  36. case .watch49mm:
  37. return 8
  38. case .unknown:
  39. return 8
  40. }
  41. }
  42. func makeBody(configuration: Configuration) -> some View {
  43. configuration.label
  44. .font(fontSize)
  45. .fontWeight(fontWeight)
  46. .padding(buttonPadding)
  47. .background(Color.tabBar.opacity(configuration.isPressed ? 0.8 : 1.0))
  48. .clipShape(Circle())
  49. .animation(.easeInOut(duration: 0.1), value: configuration.isPressed)
  50. }
  51. }
  52. struct PressableIconButtonStyle: ButtonStyle {
  53. func makeBody(configuration: Configuration) -> some View {
  54. configuration.label
  55. .background(Color.clear)
  56. .opacity(configuration.isPressed ? 0.3 : 1.0) // Change opacity when pressed
  57. .animation(.easeInOut(duration: 0.25), value: configuration.isPressed) // Smooth transition
  58. }
  59. }