Skip to content

Commit a8a84eb

Browse files
committed
feat(style): add support for tint/accentColor
1 parent 1ad602a commit a8a84eb

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

ios/components/StyleProps.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import SwiftUI
22

33
public struct StyleProps: Decodable {
44
// ViewStyle
5+
public var color: Color? // alias for foregroundColor
6+
public var accentColor: Color?
7+
public var tintColor: Color?
8+
public var foregroundColor: Color?
59
public var backgroundColor: Color?
610
// - Frame
711
public var width: Size?
@@ -30,21 +34,23 @@ public struct StyleProps: Decodable {
3034
public var borderRadius: CGFloat?
3135
public var cornerRadius: CGFloat?
3236
// TextStyle
33-
public var color: Color? // alias for foregroundColor
34-
public var foregroundColor: Color?
3537
public var fontWeight: Font.Weight?
3638
public var fontSize: CGFloat?
3739
public var font: Font?
3840
public var fontFamily: String?
3941

4042
enum CodingKeys: String, CodingKey {
41-
case color, backgroundColor, foregroundColor, width, minWidth, maxWidth, height, minHeight, maxHeight, position, top, left, bottom, right, padding, paddingHorizontal, paddingVertical, paddingLeft, paddingRight, paddingTop, paddingBottom, borderColor, borderWidth, borderRadius, cornerRadius, fontWeight, fontSize, font, fontFamily
43+
case color, accentColor, tintColor, backgroundColor, foregroundColor, width, minWidth, maxWidth, height, minHeight, maxHeight, position, top, left, bottom, right, padding, paddingHorizontal, paddingVertical, paddingLeft, paddingRight, paddingTop, paddingBottom, borderColor, borderWidth, borderRadius, cornerRadius, fontWeight, fontSize, font, fontFamily
4244
}
4345

4446
public init(from decoder: Decoder) throws {
4547
let container = try decoder.container(keyedBy: CodingKeys.self)
4648

4749
// ViewStyle
50+
color = try container.decodeColorIfPresent(forKey: .color) // alias for foregroundColor
51+
accentColor = try container.decodeColorIfPresent(forKey: .accentColor)
52+
tintColor = try container.decodeColorIfPresent(forKey: .tintColor)
53+
foregroundColor = try container.decodeColorIfPresent(forKey: .foregroundColor)
4854
backgroundColor = try container.decodeColorIfPresent(forKey: .backgroundColor)
4955
// - Frame
5056
width = try container.decodeIfPresent(Size.self, forKey: .width)
@@ -74,8 +80,6 @@ public struct StyleProps: Decodable {
7480
cornerRadius = try container.decodeIfPresent(CGFloat.self, forKey: .cornerRadius)
7581

7682
// TextStyle
77-
color = try container.decodeColorIfPresent(forKey: .color) // alias for foregroundColor
78-
foregroundColor = try container.decodeColorIfPresent(forKey: .foregroundColor)
7983
fontWeight = try container.decodeFontWeightIfPresent(forKey: .fontWeight)
8084
fontSize = try container.decodeIfPresent(CGFloat.self, forKey: .fontSize)
8185
font = try container.decodeFontIfPresent(forKey: .font)

ios/extensions/View+Styling.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ extension View {
7979
AnyView(
8080
applyBoxStyles(style)
8181
.applyIf(style.backgroundColor != nil) { $0.background(style.backgroundColor!) }
82+
.applyIf(style.color != nil || style.foregroundColor != nil) { $0.foregroundStyle(style.color ?? style.foregroundColor!) }
83+
.applyIf(style.accentColor != nil) { $0.accentColor(style.accentColor!) }
84+
.applyIf(style.tintColor != nil) { $0.tint(style.tintColor!) }
8285
.applyIf(style.borderWidth != nil) { view in
8386
view.overlay(
8487
RoundedRectangle(cornerRadius: style.cornerRadius ?? style.borderRadius ?? 0)
@@ -92,7 +95,7 @@ extension View {
9295
}
9396

9497
private func applyTextStyles(_ style: StyleProps) -> some View {
95-
return applyIf(style.color != nil) { $0.foregroundStyle(style.color!) }
98+
return applyIf(style.color != nil) { $0.foregroundStyle(style.color!).tint(style.color!) }
9699
.applyIf(style.font != nil) { $0.font(style.font!) }
97100
.applyIf(style.fontFamily != nil) { $0.font(.custom(style.fontFamily!, size: style.fontSize ?? 17)) }
98101
.applyIf(style.fontFamily == nil && style.fontSize != nil) { $0.font(.system(size: style.fontSize!)) }

0 commit comments

Comments
 (0)