Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Sources/DynamicUI/Extensions/View.modifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import SwiftUI
public struct DynamicUIModifier: ViewModifier {
/// The modifiers to apply
let modifiers: [String: AnyCodable]?
let helper = DynamicUIHelper()

// TODO: Ideally, this function would use @ViewBuilder to avoid type erasure with AnyView,
// which would improve type safety and allow for more natural SwiftUI composition.
Expand All @@ -30,19 +29,19 @@ public struct DynamicUIModifier: ViewModifier {
case "foregroundStyle", "foregroundColor":
guard #available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *),
let string = value.toString(),
let color = helper.translateColor(string) else { break }
let color = DynamicUIHelper.translateColor(string) else { break }
tempView = AnyView(tempView.foregroundStyle(color))

case "backgroundStyle", "backgroundColor":
guard #available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *),
let string = value.toString(),
let color = helper.translateColor(string) else { break }
let color = DynamicUIHelper.translateColor(string) else { break }
tempView = AnyView(tempView.backgroundStyle(color))

case "fontWeight":
guard #available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *),
let string = value.toString(),
let weight = helper.translateFontWeight(string) else { break }
let weight = DynamicUIHelper.translateFontWeight(string) else { break }
tempView = AnyView(tempView.fontWeight(weight))

case "font":
Expand All @@ -60,7 +59,7 @@ public struct DynamicUIModifier: ViewModifier {
let minHeight = frameDict["minHeight"]?.toDouble().map { CGFloat($0) }
let idealHeight = frameDict["idealHeight"]?.toDouble().map { CGFloat($0) }
let maxHeight = frameDict["maxHeight"]?.toDouble().map { CGFloat($0) }
let alignment = helper.translateAlignment(frameDict["alignment"]?.toString())
let alignment = DynamicUIHelper.translateAlignment(frameDict["alignment"]?.toString())

if width != nil || height != nil {
tempView = AnyView(
Expand Down
6 changes: 3 additions & 3 deletions Sources/DynamicUI/Helpers/DynamicUIHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class DynamicUIHelper {
/// - Parameter input: Color as string
///
/// - Returns: SwiftUI ``Color``
public func translateColor(_ input: String) -> Color? {
static func translateColor(_ input: String) -> Color? {
Comment thread
0xWDG marked this conversation as resolved.
switch input.lowercased() {
case "red":
return .red
Expand Down Expand Up @@ -102,7 +102,7 @@ public class DynamicUIHelper {
/// - Parameter input: Font weight as string
///
/// - Returns: Translated ``Font.Weight``
func translateFontWeight(_ input: String) -> Font.Weight? {
static func translateFontWeight(_ input: String) -> Font.Weight? {
switch input {
case "ultraLight":
return .ultraLight
Expand Down Expand Up @@ -136,7 +136,7 @@ public class DynamicUIHelper {
}
}

func translateAlignment(_ input: String?) -> Alignment {
static func translateAlignment(_ input: String?) -> Alignment {
switch input {
case "leading":
return .leading
Expand Down