diff --git a/Sources/FASwiftUI/FASearchHolder.swift b/Sources/FASwiftUI/FASearchHolder.swift index ab6ac6e..d0a151a 100644 --- a/Sources/FASwiftUI/FASearchHolder.swift +++ b/Sources/FASwiftUI/FASearchHolder.swift @@ -12,11 +12,7 @@ import SwiftUI class FASearchHolder: ObservableObject { - @Published var searchQuery: String = "" { - didSet { - print("Set: \(searchQuery)") - } - } + @Published var searchQuery: String = "" @Published var searchResults: [String: FAIcon]? private var keyboardVisible: Bool = false diff --git a/Sources/FASwiftUI/FAText.swift b/Sources/FASwiftUI/FAText.swift index aa3b12f..4afc4e4 100644 --- a/Sources/FASwiftUI/FAText.swift +++ b/Sources/FASwiftUI/FAText.swift @@ -11,23 +11,35 @@ import SwiftUI public struct FAText: View { var iconName: String - private var icon: FAIcon { - return FontAwesome.shared.icon(byName: iconName) ?? FontAwesome.shared.icon(byName: "question-square")! - } + private var icon: FAIcon var size: CGFloat - var style: FAStyle? + var style: FAStyle private var weight: Font.Weight { - if let style = style { - return style.weight - } else { - return .regular - } + return style.weight } public init(iconName: String, size: CGFloat, style: FAStyle? = nil) { - self.iconName = iconName.hasPrefix("fa-") ? String(iconName.dropFirst(3)) : iconName self.size = size - self.style = style + self.style = style ?? .regular + self.iconName = iconName.hasPrefix("fa-") ? String(iconName.dropFirst(3)) : iconName + + if let icon = FontAwesome.shared.icon(byName: self.iconName) { + self.icon = icon + } else { + self.icon = FontAwesome.shared.icon(byName: "question-circle")! + self.style = .regular + print("FASwiftUI: Icon \"\(iconName)\" not found. Check list at https://fontawesome.com/icons for set availability.") + } + + if !self.icon.styles.contains(self.style) { + let fallbackStyle = self.icon.styles.first! + if fallbackStyle != .brands && style != nil { + print("FASwiftUI: Style \"\(style ?? .regular)\" not available for icon \"\(iconName)\", using \"\(fallbackStyle)\". Check list at https://fontawesome.com/icons for set availability.") + } else if self.style != .regular && style != nil { + print("FASwiftUI: Icon \"\(iconName)\" is part of the brands set and doesn't support alternate styles. Check list at https://fontawesome.com/icons for set availability.") + } + self.style = fallbackStyle + } } public var body: some View {