Skip to content

Commit

Permalink
Remove any additional vertical padding in TotalsView for cash view,…
Browse files Browse the repository at this point in the history
… and update the bottom padding to account for safe area insets and floating control.
  • Loading branch information
jaclync committed Feb 24, 2025
1 parent 1e15b50 commit 01118d6
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 62 deletions.
130 changes: 69 additions & 61 deletions WooCommerce/Classes/POS/Presentation/PointOfSaleCollectCashView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import WooFoundation
@available(iOS 17.0, *)
struct PointOfSaleCollectCashView: View {
@Environment(\.dynamicTypeSize) var dynamicTypeSize
@Environment(\.floatingControlAreaSize) private var floatingControlAreaSize: CGSize
@Environment(PointOfSaleAggregateModel.self) private var posModel
@FocusState private var isTextFieldFocused: Bool

Expand All @@ -31,79 +32,85 @@ struct PointOfSaleCollectCashView: View {
allowNegativeNumber: false)

var body: some View {
ScrollView {
VStack(alignment: .center, spacing: conditionalPadding(POSSpacing.medium)) {
POSPageHeaderView(title: Localization.backNavigationTitle,
subtitle: formattedOrderTotal,
backButtonConfiguration: .init(state: isLoading ? .disabled: .enabled,
action: {
Task { @MainActor in
await posModel.cancelCashPayment()
isTextFieldFocused = false
}
}))

GeometryReader { geometry in
ScrollView {
VStack(alignment: .center, spacing: conditionalPadding(POSSpacing.medium)) {
Spacer()

VStack(alignment: .center, spacing: conditionalPadding(POSSpacing.xSmall)) {
FormattableAmountTextField(viewModel: textFieldViewModel, style: .pos)
.focused($isTextFieldFocused)
.dynamicTypeSize(...DynamicTypeSize.accessibility1)
.onSubmit {
Task { @MainActor in
await submitCashAmount()
POSPageHeaderView(title: Localization.backNavigationTitle,
subtitle: formattedOrderTotal,
backButtonConfiguration: .init(state: isLoading ? .disabled: .enabled,
action: {
Task { @MainActor in
await posModel.cancelCashPayment()
isTextFieldFocused = false
}
}))

VStack(alignment: .center, spacing: conditionalPadding(POSSpacing.medium)) {
Spacer()

VStack(alignment: .center, spacing: conditionalPadding(POSSpacing.xSmall)) {
FormattableAmountTextField(viewModel: textFieldViewModel, style: .pos)
.focused($isTextFieldFocused)
.dynamicTypeSize(...DynamicTypeSize.accessibility1)
.onSubmit {
Task { @MainActor in
await submitCashAmount()
}
}
.onChange(of: textFieldViewModel.amount) { newValue in
textFieldAmountInput = newValue
updateChangeDueMessage()
}
}
.onChange(of: textFieldViewModel.amount) { newValue in
textFieldAmountInput = newValue
updateChangeDueMessage()
}

if let changeDue = changeDueMessage {
Text(changeDue)
.font(.posBodySmallRegular())
.foregroundColor(.posOnSurfaceVariantLowest)
}
if let changeDue = changeDueMessage {
Text(changeDue)
.font(.posBodySmallRegular())
.foregroundColor(.posOnSurfaceVariantLowest)
}

if let errorMessage = errorMessage {
Text(errorMessage)
.font(.posBodySmallRegular())
.foregroundColor(.posError)
if let errorMessage = errorMessage {
Text(errorMessage)
.font(.posBodySmallRegular())
.foregroundColor(.posError)
}
}
}

Spacer()
Spacer()

Button(action: {
Task { @MainActor in
await submitCashAmount()
Button(action: {
Task { @MainActor in
await submitCashAmount()
}
}, label: {
Text(Localization.markPaymentCompletedButtonTitle)
})
.measureFrame {
buttonFrame = $0
}
}, label: {
Text(Localization.markPaymentCompletedButtonTitle)
})
.measureFrame {
buttonFrame = $0
.buttonStyle(POSFilledButtonStyle(size: .normal, isLoading: isLoading))
.frame(maxWidth: .infinity)
.dynamicTypeSize(...DynamicTypeSize.accessibility1)
.disabled(isLoading)
}
.buttonStyle(POSFilledButtonStyle(size: .normal, isLoading: isLoading))
.frame(maxWidth: .infinity)
.dynamicTypeSize(...DynamicTypeSize.accessibility1)
.disabled(isLoading)
.padding([.horizontal])
.padding(.bottom, max(keyboardFrame.height - geometry.safeAreaInsets.bottom,
floatingControlAreaSize.height) + Constants.bottomPadding
)
}
.padding([.horizontal])
.padding(.bottom, keyboardFrame.height)
}
.animation(.easeInOut, value: errorMessage)
.animation(.easeInOut, value: changeDueMessage)
.onChange(of: textFieldAmountInput) { _ in
errorMessage = nil
}
.onReceive(Publishers.keyboardFrame) {
keyboardFrame = $0
shouldMinimizePadding = $0.intersects(buttonFrame)
.frame(minHeight: geometry.size.height)
.animation(.easeInOut, value: errorMessage)
.animation(.easeInOut, value: changeDueMessage)
.onChange(of: textFieldAmountInput) { _ in
errorMessage = nil
}
.onReceive(Publishers.keyboardFrame) {
keyboardFrame = $0
shouldMinimizePadding = $0.intersects(buttonFrame)
}
.animation(.default, value: shouldMinimizePadding)
}
.animation(.default, value: shouldMinimizePadding)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}

private func markComplete() async throws {
Expand Down Expand Up @@ -147,6 +154,7 @@ private extension PointOfSaleCollectCashView {
private extension PointOfSaleCollectCashView {
enum Constants {
static let minimumPadding: CGFloat = POSSpacing.xSmall
static let bottomPadding: CGFloat = POSPadding.medium
}

private func conditionalPadding(_ padding: CGFloat) -> CGFloat {
Expand Down
2 changes: 1 addition & 1 deletion WooCommerce/Classes/POS/ViewHelpers/TotalsViewHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ final class TotalsViewHelper {

func shouldApplyPadding(paymentState: PointOfSalePaymentState) -> Bool {
switch paymentState {
case .card(.cardPaymentSuccessful), .cash(.paymentSuccess):
case .card(.cardPaymentSuccessful), .cash(.paymentSuccess), .cash(.collectingCash):
return false
default:
return true
Expand Down

0 comments on commit 01118d6

Please sign in to comment.