From 9a8afea15748c29b34009524b215b5ca6bcd1564 Mon Sep 17 00:00:00 2001 From: Valentin Perignon Date: Tue, 30 Jul 2024 13:15:41 +0200 Subject: [PATCH] chore: Do not use SwiftUIMacros --- Package.resolved | 18 ---- Package.swift | 6 +- .../Buttons/Models/IKButtonHeight.swift | 5 +- .../Modifiers/IKButtonEnvironments.swift | 83 +++++++++++++++++-- 4 files changed, 79 insertions(+), 33 deletions(-) diff --git a/Package.resolved b/Package.resolved index 119808b..1df3e0b 100644 --- a/Package.resolved +++ b/Package.resolved @@ -125,24 +125,6 @@ "revision" : "9cb486020ebf03bfa5b5df985387a14a98744537", "version" : "1.6.1" } - }, - { - "identity" : "swift-syntax", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-syntax", - "state" : { - "revision" : "303e5c5c36d6a558407d364878df131c3546fad8", - "version" : "510.0.2" - } - }, - { - "identity" : "swiftui-macros", - "kind" : "remoteSourceControl", - "location" : "https://github.com/Wouter01/SwiftUI-Macros.git", - "state" : { - "revision" : "a7d9eeaec29c2d46fa1ada18f3a54a13ddf043b0", - "version" : "1.2.0" - } } ], "version" : 2 diff --git a/Package.swift b/Package.swift index da6c55d..2553156 100644 --- a/Package.swift +++ b/Package.swift @@ -17,8 +17,7 @@ let package = Package( .package(url: "https://github.com/Infomaniak/ios-core", .upToNextMajor(from: "11.0.0")), .package(url: "https://github.com/Infomaniak/SnackBar.swift", .upToNextMajor(from: "1.2.0")), .package(url: "https://github.com/onevcat/Kingfisher", .upToNextMajor(from: "7.10.0")), - .package(url: "https://github.com/matomo-org/matomo-sdk-ios", .upToNextMajor(from: "7.5.2")), - .package(url: "https://github.com/Wouter01/SwiftUI-Macros.git", .upToNextMajor(from: "1.2.0")) + .package(url: "https://github.com/matomo-org/matomo-sdk-ios", .upToNextMajor(from: "7.5.2")) ], targets: [ .target( @@ -27,8 +26,7 @@ let package = Package( "Kingfisher", .product(name: "MatomoTracker", package: "matomo-sdk-ios"), .product(name: "InfomaniakCore", package: "ios-core"), - .product(name: "SnackBar", package: "SnackBar.swift"), - .product(name: "SwiftUIMacros", package: "SwiftUI-Macros") + .product(name: "SnackBar", package: "SnackBar.swift") ]), .testTarget( name: "InfomaniakCoreUITests", diff --git a/Sources/InfomaniakCoreUI/SwiftUI/Components/Buttons/Models/IKButtonHeight.swift b/Sources/InfomaniakCoreUI/SwiftUI/Components/Buttons/Models/IKButtonHeight.swift index 99c9fd7..4da87dc 100644 --- a/Sources/InfomaniakCoreUI/SwiftUI/Components/Buttons/Models/IKButtonHeight.swift +++ b/Sources/InfomaniakCoreUI/SwiftUI/Components/Buttons/Models/IKButtonHeight.swift @@ -25,10 +25,9 @@ enum IKButtonHeight { static let medium: CGFloat = 40 static func convert(controlSize: ControlSize) -> CGFloat { - switch controlSize { - case .large: + if controlSize == .large { return IKButtonHeight.large - default: + } else { return IKButtonHeight.medium } } diff --git a/Sources/InfomaniakCoreUI/SwiftUI/Components/Buttons/Modifiers/IKButtonEnvironments.swift b/Sources/InfomaniakCoreUI/SwiftUI/Components/Buttons/Modifiers/IKButtonEnvironments.swift index 568527d..96ba94f 100644 --- a/Sources/InfomaniakCoreUI/SwiftUI/Components/Buttons/Modifiers/IKButtonEnvironments.swift +++ b/Sources/InfomaniakCoreUI/SwiftUI/Components/Buttons/Modifiers/IKButtonEnvironments.swift @@ -17,21 +17,88 @@ */ import SwiftUI -import SwiftUIMacros + +// MARK: - EnvironmentValues @available(iOS 15.0, *) -@EnvironmentValues public extension EnvironmentValues { - var ikButtonPrimaryStyle: any ShapeStyle = TintShapeStyle.tint - var ikButtonSecondaryStyle: any ShapeStyle = Color.primary +public extension EnvironmentValues { + // MARK: IKButtonPrimaryStyleKey + + var ikButtonPrimaryStyle: any ShapeStyle { + get { + self[IKButtonPrimaryStyleKey.self] + } + set { + self[IKButtonPrimaryStyleKey.self] = newValue + } + } + + private struct IKButtonPrimaryStyleKey: EnvironmentKey { + static let defaultValue: any ShapeStyle = TintShapeStyle.tint + } + + // MARK: IKButtonSecondaryStyleKey + + var ikButtonSecondaryStyle: any ShapeStyle { + get { + self[IKButtonSecondaryStyleKey.self] + } + set { + self[IKButtonSecondaryStyleKey.self] = newValue + } + } + + private struct IKButtonSecondaryStyleKey: EnvironmentKey { + static let defaultValue: any ShapeStyle = Color.primary + } + + // MARK: IKButtonThemeKey - var ikButtonTheme = IKButtonTheme.defaultTheme + var ikButtonTheme: IKButtonTheme { + get { + self[IKButtonThemeKey.self] + } + set { + self[IKButtonThemeKey.self] = newValue + } + } + + private struct IKButtonThemeKey: EnvironmentKey { + static let defaultValue = IKButtonTheme.defaultTheme + } - var ikButtonFullWidth = false + // MARK: IKButtonFullWidthKey - var ikButtonLoading = false + var ikButtonFullWidth: Bool { + get { + self[IKButtonFullWidthKey.self] + } + set { + self[IKButtonFullWidthKey.self] = newValue + } + } + + private struct IKButtonFullWidthKey: EnvironmentKey { + static let defaultValue = false + } + + // MARK: IKButtonLoadingKey + + var ikButtonLoading: Bool { + get { + self[IKButtonLoadingKey.self] + } + set { + self[IKButtonLoadingKey.self] = newValue + } + } + + private struct IKButtonLoadingKey: EnvironmentKey { + static let defaultValue = false + } } -// MARK: - View functions +// MARK: - View extension @available(iOS 15.0, *) public extension View {