Helper+ButtonStyles.swift 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import SwiftUI
  2. struct WatchOSButtonStyle: ButtonStyle {
  3. var backgroundGradient = LinearGradient(colors: [
  4. Color(red: 0.721, green: 0.341, blue: 1),
  5. Color(red: 0.486, green: 0.545, blue: 0.953),
  6. Color(red: 0.262, green: 0.733, blue: 0.914)
  7. ], startPoint: .topLeading, endPoint: .bottomTrailing)
  8. var foregroundColor: Color = .white
  9. var fontSize: Font = .title2
  10. private var is40mm: Bool {
  11. let size = WKInterfaceDevice.current().screenBounds.size
  12. return size.height < 225 && size.width < 185
  13. }
  14. func makeBody(configuration: Configuration) -> some View {
  15. configuration.label
  16. .font(fontSize)
  17. .fontWeight(is40mm ? .medium : .semibold)
  18. .padding(is40mm ? 6 : 8)
  19. .background(
  20. backgroundGradient.opacity(configuration.isPressed ? 0.8 : 1.0)
  21. )
  22. .clipShape(Circle())
  23. .animation(.easeInOut(duration: 0.1), value: configuration.isPressed)
  24. }
  25. }
  26. struct PressableIconButtonStyle: ButtonStyle {
  27. func makeBody(configuration: Configuration) -> some View {
  28. configuration.label
  29. .background(Color.clear)
  30. .opacity(configuration.isPressed ? 0.3 : 1.0) // Change opacity when pressed
  31. .animation(.easeInOut(duration: 0.25), value: configuration.isPressed) // Smooth transition
  32. }
  33. }