Mercurial > public > lazybear
diff LazyBear/Views/Company/Helpers/KeyStatsHelper.swift @ 448:f71761f166f2
Handle when data is empty
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Wed, 23 Jun 2021 11:47:14 +0200 |
parents | 8621ba6fd457 |
children |
line wrap: on
line diff
--- a/LazyBear/Views/Company/Helpers/KeyStatsHelper.swift Wed Jun 23 10:54:47 2021 +0200 +++ b/LazyBear/Views/Company/Helpers/KeyStatsHelper.swift Wed Jun 23 11:47:14 2021 +0200 @@ -8,65 +8,31 @@ import SwiftUI struct KeyStatsHelper: View { - var keyStats: KeyStatsModel? + var keyStats: KeyStatsModel let displayWords: DisplayWordsModel = parseJSON("DisplayWords.json") - @Environment(\.colorScheme) private var colorScheme var body: some View { - if let keyStats = keyStats { - ScrollView(.horizontal, showsIndicators: false) { - HStack(spacing: 20) { - - let mirror = Mirror(reflecting: keyStats) - ForEach(Array(mirror.children), id: \.label) { child in /// Iterate over each variable within the class - - if let unwrappedValue = unwrapAnyOptional(value: child.value) { + ScrollView(.horizontal, showsIndicators: false) { + HStack(spacing: 20) { + + let mirror = Mirror(reflecting: keyStats) + ForEach(Array(mirror.children), id: \.label) { child in /// Iterate over each variable within the class + if let unwrappedValue = unwrapAnyOptional(value: child.value) { + if unwrappedValue != "0.000" && unwrappedValue != "0" && !unwrappedValue.isEmpty { let label = String(child.label!) NavigationLink(destination: KeyStatsList(keyStats: keyStats) .navigationTitle("Key Stats") ) { - Capsule() - .frame(width: 250, height: 40) - .foregroundColor(Color("customSecondaryBackground")) - .if(colorScheme == .light) { content in - content.shadow(color: Color(.systemGray).opacity(0.25), radius: 10, x: 0.0, y: 0.0) - } - .overlay( - HStack { - Text("\(displayWords.keyStats[label]!):") - .font(.callout) - .fontWeight(.semibold) - .lineLimit(1) - - Spacer() - Text(unwrappedValue) - .font(.callout) - .lineLimit(1) - } - .padding() - ) + KeyStatsRow(label: displayWords.keyStats[label]!) } .buttonStyle(PlainButtonStyle()) } } } - .frame(height: 70) - .padding(.horizontal) } - } - } - - /* - Unwrap optional Int, Double, String into String - */ - private func unwrapAnyOptional(value: Any) -> String? { - if let value = value as? Int { - return "\(value)" - } else if let value = value as? Double { - return String(format: "%.3f", value) - } else { - return value as? String + .frame(height: 70) + .padding(.horizontal) } } }