Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Max button align fix #36

Merged
merged 3 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 27 additions & 23 deletions Gem/Transfer/Scenes/AmountScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import Components
import Primitives

struct AmountScene: View {

@StateObject var model: AmounViewModel

@Environment(\.nodeService) private var nodeService

@State var amount: String = ""
@State private var isPresentingErrorMessage: String?

Expand All @@ -21,14 +21,14 @@ struct AmountScene: View {
var id: String { String(rawValue) }
}
@FocusState private var focusedField: Field?

// next scene
@State var transferData: TransferData?
@State var delegation: DelegationValidator?

var body: some View {
UITextField.appearance().clearButtonMode = .never

return VStack {
List {
Section { } header: {
Expand All @@ -48,15 +48,15 @@ struct AmountScene: View {
.padding(.trailing, 8)
.fixedSize(horizontal: true, vertical: false)
.disabled(model.isInputDisabled)

Text(model.assetSymbol)
.font(.system(size: 52))
.fontWeight(.semibold)
.lineLimit(1)
.foregroundColor(Colors.black)
.fixedSize()
}

ZStack {
Text(model.fiatAmount(amount: amount))
.font(Font.system(size: 16))
Expand All @@ -72,13 +72,15 @@ struct AmountScene: View {
.textCase(nil)
.listRowSeparator(.hidden)
.listRowInsets(EdgeInsets())

if let validator = model.currentValidator {
Section(Localized.Stake.validator) {
//TODO: Use this, other option does not work for some reason
// NavigationLink(value: Scenes.Validators()) {
// ListItemView(title: validator.name, subtitle: .none)
// }
/*
NavigationLink(value: Scenes.Validators()) {
ListItemView(title: validator.name, subtitle: .none)
}
*/
if model.isSelectValidatorEnabled {
NavigationCustomLink(with:
HStack {
Expand All @@ -104,7 +106,7 @@ struct AmountScene: View {
}
if model.isBalanceViewEnabled {
Section {
VStack(alignment: .center) {
VStack {
AssetListItemView {
AssetImageView(assetImage: model.assetImage)
} primary: {
Expand All @@ -121,19 +123,21 @@ struct AmountScene: View {
)
} secondary: {
AnyView(
Button(Localized.Transfer.max, action: useMax)
.buttonStyle(ColorButton.lightGray(paddingHorizontal: 16, paddingVertical: 8))
.fixedSize()
HStack {
Button(Localized.Transfer.max, action: useMax)
.buttonStyle(ColorButton.lightGray(paddingHorizontal: Spacing.medium, paddingVertical: Spacing.small))
.fixedSize()
}
)
}
}
.frame(maxWidth: Spacing.scene.button.maxWidth)
.frame(maxWidth: .infinity)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to make sure button is not larger than Spacing.scene.button.maxWidth

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah. Button still fixedSize and haven't changed. The frame changed for container view for iPad to fix ipad layout for that button

}
}
}

Spacer()

Button(Localized.Common.continue, action: {
Task { await next() }
})
Expand Down Expand Up @@ -183,10 +187,10 @@ struct AmountScene: View {
Alert(title: Text(""), message: Text($0))
}
}

func next() async {
//TODO: Move validation per field on demand

do {
let value = try model.isValidAmount(amount: amount)
let transfer = try model.getTransferData(value: value)
Expand All @@ -195,10 +199,10 @@ struct AmountScene: View {
isPresentingErrorMessage = error.localizedDescription
}
}

func useMax() {
amount = model.maxBalance

focusedField = .none
}
}
4 changes: 2 additions & 2 deletions Packages/Components/Sources/AssetListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public struct AssetListItemView: View {
public var body: some View {
HStack {
imageView
HStack(alignment: .center) {
HStack {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure this does not break other places

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. By default HStack initialise with alignment: center. HStack(alignment: .center) - not necessary to write

primary
Spacer(minLength: 2)
secondary
Expand Down Expand Up @@ -180,7 +180,7 @@ public struct AssetListView: View {
}
)
}
.onChange(of: toggleValue) { newValue in
.onChange(of: toggleValue) { _, newValue in
model.action?(.enabled(newValue))
}
}
Expand Down
Loading