Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-dydx committed Dec 8, 2023
1 parent 6251057 commit 3982efb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
16 changes: 10 additions & 6 deletions PlatformUI/PlatformUI/DesignSystem/Theme/ThemeViewModifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -503,24 +503,28 @@ public extension AttributedString {
/// - Parameters:
/// - foreground: the font to apply
/// - range: the range to modify, `nil` if the entire string should be modified
mutating func themeFont(fontType: ThemeFont.FontType = .text, fontSize: ThemeFont.FontSize = .medium, to range: Range<AttributedString.Index>? = nil) {
func themeFont(fontType: ThemeFont.FontType = .text, fontSize: ThemeFont.FontSize = .medium, to range: Range<AttributedString.Index>? = nil) -> Self {
var string = self
if let range = range {
self[range].font = ThemeSettings.shared.themeConfig.themeFont.font(of: fontType, fontSize: fontSize)
string[range].font = ThemeSettings.shared.themeConfig.themeFont.font(of: fontType, fontSize: fontSize)
} else {
self.font = ThemeSettings.shared.themeConfig.themeFont.font(of: fontType, fontSize: fontSize)
string.font = ThemeSettings.shared.themeConfig.themeFont.font(of: fontType, fontSize: fontSize)
}
return string
}

/// Applies a foreground color to the attributed string.
/// - Parameters:
/// - foreground: the color to apply
/// - range: the range to modify, `nil` if the entire string should be modified
mutating func themeColor(foreground: ThemeColor.SemanticColor, to range: Range<AttributedString.Index>? = nil) {
func themeColor(foreground: ThemeColor.SemanticColor, to range: Range<AttributedString.Index>? = nil) -> Self {
var string = self
if let range = range {
self[range].foregroundColor = ThemeSettings.shared.themeConfig.themeColor.color(of: foreground)
string[range].foregroundColor = ThemeSettings.shared.themeConfig.themeColor.color(of: foreground)
} else {
self.foregroundColor = ThemeSettings.shared.themeConfig.themeColor.color(of: foreground)
string.foregroundColor = ThemeSettings.shared.themeConfig.themeColor.color(of: foreground)
}
return string
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ public class dydxPortfolioFeesItemViewModel: PlatformViewModel {
var titleString: AttributedString
if let title = condition.title {
titleString = AttributedString(title)
titleString.themeFont(fontType: .text, fontSize: .smaller)
titleString.themeColor(foreground: .textTertiary)
.themeFont(fontType: .text, fontSize: .smaller)
.themeColor(foreground: .textTertiary)
} else {
titleString = AttributedString("")
}

var valueString = AttributedString(condition.value)
valueString.themeFont(fontType: .text, fontSize: .smaller)
valueString.themeColor(foreground: .textPrimary)
.themeFont(fontType: .text, fontSize: .smaller)
.themeColor(foreground: .textPrimary)

return Text(titleString + AttributedString(" ") + valueString)
.multilineTextAlignment(.trailing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public class dydxRewardsHistoryViewModel: dydxTitledCardViewModel {
// MARK: public properties
@Published public var filters: [TabItemViewModel.TabItemContent] = []
@Published public var onSelectionChanged: ((Int) -> Void)?
@Published public var items: [dydxRewardsRewardView] = []
@Published public var items: [dydxRewardsRewardViewModel] = []
public var contentChanged: (() -> Void)?

// MARK: private properties
private static let numItemsStepSize: Int = 10
private var visibleItems: [dydxRewardsRewardView] {
private var visibleItems: [dydxRewardsRewardViewModel] {
Array(items.prefix(maxItemsToDisplay))
}
private var hasMoreItemsToDisplay: Bool { items.count > maxItemsToDisplay }
Expand Down Expand Up @@ -52,7 +52,7 @@ public class dydxRewardsHistoryViewModel: dydxTitledCardViewModel {
.wrappedInAnyView()
}

let headerViewModel: PlatformViewModel = {
private let headerViewModel: PlatformViewModel = {
PlatformViewModel { _ in
HStack(spacing: 0) {
Text(DataLocalizer.shared?.localize(path: "APP.TRADING_REWARDS.EVENT", params: nil) ?? "")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// dydxRewardsRewardView.swift
// dydxRewardsRewardViewModel.swift
// dydxViews
//
// Created by Michael Maguire on 12/7/23.
Expand All @@ -9,7 +9,7 @@ import SwiftUI
import PlatformUI
import Utilities

public class dydxRewardsRewardView: PlatformViewModel {
public class dydxRewardsRewardViewModel: PlatformViewModel {

public var id: String { period + amount }
private let period: String
Expand All @@ -25,11 +25,11 @@ public class dydxRewardsRewardView: PlatformViewModel {
let localizedString = DataLocalizer.shared?.localize(path: "APP.TRADING_REWARDS.FOR_TRADING", params: ["PERIOD": period]) ?? ""

var attributedString = AttributedString(localizedString)
attributedString.themeFont(fontType: .text, fontSize: .smaller)
.themeFont(fontType: .text, fontSize: .smaller)

attributedString.themeColor(foreground: .textTertiary, to: nil)
attributedString = attributedString.themeColor(foreground: .textTertiary, to: nil)
if let periodTextRange = attributedString.range(of: period) {
attributedString.themeColor(foreground: .textSecondary, to: periodTextRange)
attributedString = attributedString.themeColor(foreground: .textSecondary, to: periodTextRange)
}

return attributedString
Expand Down Expand Up @@ -58,21 +58,21 @@ public class dydxRewardsRewardView: PlatformViewModel {
}
}

public static var previewValue: dydxRewardsRewardView {
let vm = dydxRewardsRewardView(period: "test period", amount: "15")
public static var previewValue: dydxRewardsRewardViewModel {
let vm = dydxRewardsRewardViewModel(period: "test period", amount: "15")
return vm
}

}

#if DEBUG
struct dydxRewardsRewardView_Previews_Dark: PreviewProvider {
struct dydxRewardsRewardViewModel_Previews_Dark: PreviewProvider {
@StateObject static var themeSettings = ThemeSettings.shared

static var previews: some View {
ThemeSettings.applyDarkTheme()
ThemeSettings.applyStyles()
return dydxRewardsRewardView.previewValue
return dydxRewardsRewardViewModel.previewValue
.createView()
.themeColor(background: .layer0)
.environmentObject(themeSettings)
Expand All @@ -81,13 +81,13 @@ struct dydxRewardsRewardView_Previews_Dark: PreviewProvider {
}
}

struct dydxRewardsRewardView_Previews_Light: PreviewProvider {
struct dydxRewardsRewardViewModel_Previews_Light: PreviewProvider {
@StateObject static var themeSettings = ThemeSettings.shared

static var previews: some View {
ThemeSettings.applyLightTheme()
ThemeSettings.applyStyles()
return dydxRewardsRewardView.previewValue
return dydxRewardsRewardViewModel.previewValue
.createView()
.themeColor(background: .layer0)
.environmentObject(themeSettings)
Expand Down

0 comments on commit 3982efb

Please sign in to comment.