Skip to content

Instantly share code, notes, and snippets.

@mezhevikin
Created March 20, 2024 09:27
Show Gist options
  • Save mezhevikin/b8b1e357eb9f66824e95299dfa59b113 to your computer and use it in GitHub Desktop.
Save mezhevikin/b8b1e357eb9f66824e95299dfa59b113 to your computer and use it in GitHub Desktop.
var fieldsView: some View {
VStack(spacing: .padding) {
ForEach(state.converter.fields.prefix(state.props.countOfFields)) { field in
HStack(spacing: .padding) {
CurrencyButton(field: field)
ConverterFieldView(field: field)
}
}
}
}
import SwiftUI
struct CurrencyButton: View, Equatable {
@ObservedObject var field: ConverterField
@EnvironmentObject var state: AppState
var body: some View {
Button(action: showCurrencies) {
HStack(spacing: .smallPadding) {
iconView
codeView
}
}
.buttonStyle(CurrencyButtonStyle())
.accessibility(identifier: "currency-\(field.index)")
.background(Color.random)
}
var iconView: some View {
CurrencyIconView(
currency: field.currency,
size: .currencyMiddleIcon
)
}
var codeView: some View {
Text(field.currency.code.prefix(3))
.lineLimit(1)
.frame(width: .currencyCodeWidth)
.font(.code)
.minimumScaleFactor(0.3)
}
func showCurrencies() {
state.showCurrencies(field)
}
static func == (lhs: Self, rhs: Self) -> Bool {
lhs.field.currency.code == rhs.field.currency.code
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment