Helper+ButtonStyles.swift 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. import SwiftUI
  2. struct WatchOSButtonStyle: ButtonStyle {
  3. var foregroundColor: Color = .white
  4. var fontSize: Font = .title2
  5. private var is40mm: Bool {
  6. let size = WKInterfaceDevice.current().screenBounds.size
  7. return size.height < 225 && size.width < 185
  8. }
  9. func makeBody(configuration: Configuration) -> some View {
  10. configuration.label
  11. .font(fontSize)
  12. .fontWeight(is40mm ? .medium : .semibold)
  13. .padding(is40mm ? 6 : 8)
  14. .background(Color.tabBar.opacity(configuration.isPressed ? 0.8 : 1.0))
  15. .clipShape(Circle())
  16. .animation(.easeInOut(duration: 0.1), value: configuration.isPressed)
  17. }
  18. }
  19. struct PressableIconButtonStyle: ButtonStyle {
  20. func makeBody(configuration: Configuration) -> some View {
  21. configuration.label
  22. .background(Color.clear)
  23. .opacity(configuration.isPressed ? 0.3 : 1.0) // Change opacity when pressed
  24. .animation(.easeInOut(duration: 0.25), value: configuration.isPressed) // Smooth transition
  25. }
  26. }