Skip to content

Commit

Permalink
Managed payment date row
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-nirali-s committed Nov 21, 2024
1 parent 691c0d1 commit c30b748
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 54 deletions.
112 changes: 59 additions & 53 deletions Splito/UI/Home/Expense/AddExpenseView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,77 +231,87 @@ struct DatePickerView: View {

@Binding var date: Date

var isForAddExpense: Bool

private let maximumDate = Calendar.current.date(byAdding: .year, value: 0, to: Date()) ?? Date()

@State private var tempDate: Date
@State private var showDatePicker = false

init(date: Binding<Date>) {
init(date: Binding<Date>, isForAddExpense: Bool = true) {
self._date = date
self.isForAddExpense = isForAddExpense
self._tempDate = State(initialValue: date.wrappedValue)
}

var body: some View {
ExpenseDatePickerButton(date: $date, tempDate: $tempDate, showDatePicker: $showDatePicker)
.sheet(isPresented: $showDatePicker) {
VStack(spacing: 0) {
NavigationBarTopView(title: "Choose date", leadingButton: EmptyView(),
trailingButton: DismissButton(padding: (16, 0), foregroundColor: primaryText, onDismissAction: {
showDatePicker = false
})
.fontWeight(.regular)
)
.padding(.leading, 16)

ScrollView {
DatePicker("", selection: $tempDate, in: ...maximumDate, displayedComponents: .date)
.datePickerStyle(GraphicalDatePickerStyle())
.labelsHidden()
.padding(24)
.id(tempDate)
}
.scrollIndicators(.hidden)
HStack {
if !isForAddExpense {
Text(date.longDate)
.font(.subTitle2())
.foregroundStyle(primaryText)
.frame(maxWidth: .infinity, alignment: .leading)
.contentShape(Rectangle())
} else {
DateDisplayView(date: $date)
}
}
.onTapGesture {
tempDate = date
showDatePicker = true
UIApplication.shared.endEditing()
}
.sheet(isPresented: $showDatePicker) {
VStack(spacing: 0) {
NavigationBarTopView(title: "Choose date", leadingButton: EmptyView(),
trailingButton: DismissButton(padding: (16, 0), foregroundColor: primaryText, onDismissAction: {
showDatePicker = false
})
.fontWeight(.regular)
)
.padding(.leading, 16)

Spacer()
ScrollView {
DatePicker("", selection: $tempDate, in: ...maximumDate, displayedComponents: .date)
.datePickerStyle(GraphicalDatePickerStyle())
.labelsHidden()
.padding(24)
.id(tempDate)
}
.scrollIndicators(.hidden)

PrimaryButton(text: "Done") {
date = tempDate
showDatePicker = false
}
.padding(16)
Spacer()

PrimaryButton(text: "Done") {
date = tempDate
showDatePicker = false
}
.background(surfaceColor)
.padding(16)
}
.background(surfaceColor)
}
}
}

private struct ExpenseDatePickerButton: View {
private struct DateDisplayView: View {

@Binding var date: Date
@Binding var tempDate: Date
@Binding var showDatePicker: Bool

var body: some View {
Button {
tempDate = date
showDatePicker = true
UIApplication.shared.endEditing()
} label: {
HStack(spacing: 8) {
Text(date.shortDate)
.font(.subTitle2())
.foregroundStyle(primaryText)

Image(.calendarIcon)
.resizable()
.scaledToFit()
.frame(width: 24, height: 24)
}
.padding(.horizontal, 8)
.padding(.vertical, 4)
.background(container2Color)
.cornerRadius(8)
HStack(spacing: 8) {
Text(date.shortDate)
.font(.subTitle2())
.foregroundStyle(primaryText)

Image(.calendarIcon)
.resizable()
.scaledToFit()
.frame(width: 24, height: 24)
}
.padding(.horizontal, 8)
.padding(.vertical, 4)
.background(container2Color)
.cornerRadius(8)
}
}

Expand Down Expand Up @@ -352,10 +362,6 @@ struct ExpenseImageView: View {
})
.resizable()
.aspectRatio(contentMode: .fill)
} else {
Image(.group)
.resizable()
.scaledToFill()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private struct PaymentDateRow: View {
.font(.body3())
.foregroundStyle(disableText)

DatePickerView(date: $date)
DatePickerView(date: $date, isForAddExpense: false)
.padding(16)
.overlay {
RoundedRectangle(cornerRadius: 12)
Expand Down

0 comments on commit c30b748

Please sign in to comment.