Skip to content

Commit

Permalink
add default icon for transfer search items
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-dydx committed Jan 30, 2024
1 parent c280d20 commit 576a992
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
11 changes: 9 additions & 2 deletions PlatformUI/PlatformUI/Components/Icons/PlatformIcon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class PlatformIconViewModel: PlatformViewModel {
public enum IconType {
case asset(name: String?, bundle: Bundle?)
case url(url: URL?)
case urlWithPlaceholder(url: URL?, placeholderContent: () -> AnyView)
case system(name: String)
case uiImage(image: UIImage)
case any(viewModel: PlatformViewModel)
Expand All @@ -33,7 +34,7 @@ public class PlatformIconViewModel: PlatformViewModel {
@Published public var clip: IconClip
@Published public var size: CGSize
@Published public var templateColor: ThemeColor.SemanticColor?

public init(type: IconType, clip: IconClip = .noClip, size: CGSize = CGSize(width: 32, height: 32), templateColor: ThemeColor.SemanticColor? = nil) {
self.type = type
self.clip = clip
Expand Down Expand Up @@ -62,7 +63,13 @@ public class PlatformIconViewModel: PlatformViewModel {
PlatformView.nilView
}
case .url(let url):
WebImage(url: url)
WebImage (url: url)
.resizable()
.templateColor(self.templateColor)
.scaledToFit()
case .urlWithPlaceholder(let url, let placeholderContent):
WebImage (url: url)
.placeholder(content: placeholderContent)
.resizable()
.templateColor(self.templateColor)
.scaledToFit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ public enum BorderAndClipStyle {
case cornerRadius(CGFloat)
/// A capsule shape is equivalent to a rounded rectangle where the corner radius is chosen as half the length of the rectangle’s smallest edge.
case capsule
case circle
}

private struct BorderAndClipModifier: ViewModifier {
Expand All @@ -289,6 +290,12 @@ private struct BorderAndClipModifier: ViewModifier {

func body(content: Content) -> some View {
switch style {
case .circle:
content
.clipShape(Circle())
.overlay(Circle()
.strokeBorder(borderColor.color, lineWidth: lineWidth))

case .cornerRadius(let cornerRadius):
content
.clipShape(RoundedRectangle(cornerSize: .init(width: cornerRadius, height: cornerRadius)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import PlatformUI
import dydxStateManager
import Abacus
import Combine
import SwiftUI

public class dydxTransferSearchViewBuilder: NSObject, ObjectBuilderProtocol {
public func build<T>() -> T? {
Expand Down Expand Up @@ -110,8 +111,17 @@ private extension dydxTransferSearchItemViewModel {
self.tokenText = TokenTextViewModel(symbol: symbol)
}
self.isSelected = selected
if let iconUrl = option.iconUrl, let url = URL(string: iconUrl), UIDevice.current.isSimulator == false {
self.icon = PlatformIconViewModel(type: .url(url: url), size: CGSize(width: 32, height: 32))
if let iconUrl = option.iconUrl, let url = URL(string: iconUrl) {
self.icon = PlatformIconViewModel(
type: .urlWithPlaceholder(url: url, placeholderContent: {
Text(option.localizedString?.prefix(1) ?? "")
.frame(width: 32, height: 32)
.themeColor(foreground: .textTertiary)
.themeColor(background: .layer5)
.borderAndClip(style: .circle, borderColor: .layer7, lineWidth: 1)
.wrappedInAnyView()
}),
size: CGSize(width: 32, height: 32))
}
self.onTapAction = onTapAction
}
Expand Down

0 comments on commit 576a992

Please sign in to comment.