Skip to content

Commit

Permalink
Added&used variable from viewmodel
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-nirali-s committed Jan 16, 2025
1 parent a5edbc5 commit d22ff1a
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 46 deletions.
5 changes: 1 addition & 4 deletions BaseStyle/BaseStyle/Views/AttachmentZoomView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@ import Kingfisher

public struct AttachmentContainerView: View {

@Binding var showImageDisplayView: Bool

var image: UIImage?
var imageUrl: String?

@Namespace private var animationNamespace

public init(showImageDisplayView: Binding<Bool>, image: UIImage? = nil, imageUrl: String? = nil) {
self._showImageDisplayView = showImageDisplayView
public init(image: UIImage? = nil, imageUrl: String? = nil) {
self.image = image
self.imageUrl = imageUrl
}
Expand Down
39 changes: 21 additions & 18 deletions Splito/UI/Home/Expense/AddExpenseView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ struct AddExpenseView: View {
.scrollIndicators(.hidden)
.scrollBounceBehavior(.basedOnSize)

AddNoteImageFooterView(date: $viewModel.expenseDate, showImagePickerOptions: $viewModel.showImagePickerOptions,
image: viewModel.expenseImage, imageUrl: viewModel.expenseImageUrl,
isNoteEmpty: viewModel.expenseNote.isEmpty, handleNoteBtnTap: viewModel.handleNoteBtnTap,
handleImageTap: viewModel.handleExpenseImageTap,
AddNoteImageFooterView(date: $viewModel.expenseDate, showImageDisplayView: $viewModel.showImageDisplayView,
showImagePickerOptions: $viewModel.showImagePickerOptions, image: viewModel.expenseImage,
imageUrl: viewModel.expenseImageUrl, isNoteEmpty: viewModel.expenseNote.isEmpty,
handleNoteBtnTap: viewModel.handleNoteBtnTap, handleCameraTap: viewModel.handleCameraTap,
handleAttachmentTap: viewModel.handleAttachmentTap,
handleActionSelection: viewModel.handleActionSelection(_:))
}
}
Expand Down Expand Up @@ -210,14 +211,16 @@ private struct ExpenseDetailRow: View {
struct AddNoteImageFooterView: View {

@Binding var date: Date
@Binding var showImageDisplayView: Bool
@Binding var showImagePickerOptions: Bool

let image: UIImage?
let imageUrl: String?
let isNoteEmpty: Bool

let handleNoteBtnTap: (() -> Void)
let handleImageTap: (() -> Void)
let handleCameraTap: (() -> Void)
let handleAttachmentTap: (() -> Void)
let handleActionSelection: ((ActionsOfSheet) -> Void)

var body: some View {
Expand All @@ -230,10 +233,11 @@ struct AddNoteImageFooterView: View {

DatePickerView(date: $date)

ImageAttachmentView(image: image, imageUrl: imageUrl, handleImageBtnTap: handleImageTap)
.confirmationDialog("", isPresented: $showImagePickerOptions, titleVisibility: .hidden) {
MediaPickerOptionsView(image: image, imageUrl: imageUrl, handleActionSelection: handleActionSelection)
}
ImageAttachmentView(showImageDisplayView: $showImageDisplayView, image: image, imageUrl: imageUrl,
handleCameraTap: handleCameraTap, handleAttachmentTap: handleAttachmentTap)
.confirmationDialog("", isPresented: $showImagePickerOptions, titleVisibility: .hidden) {
MediaPickerOptionsView(image: image, imageUrl: imageUrl, handleActionSelection: handleActionSelection)
}

NoteButtonView(isNoteEmpty: isNoteEmpty, handleNoteBtnTap: handleNoteBtnTap)
}
Expand All @@ -244,22 +248,21 @@ struct AddNoteImageFooterView: View {

private struct ImageAttachmentView: View {

@Binding var showImageDisplayView: Bool

let image: UIImage?
let imageUrl: String?

let handleImageBtnTap: (() -> Void)

@State private var showImageDisplayView = false

let handleCameraTap: (() -> Void)
let handleAttachmentTap: (() -> Void)

var body: some View {
HStack(spacing: 0) {
if image != nil || (imageUrl != nil && !(imageUrl?.isEmpty ?? false)) {
AttachmentContainerView(showImageDisplayView: $showImageDisplayView, image: image, imageUrl: imageUrl)
AttachmentContainerView(image: image, imageUrl: imageUrl)
.frame(width: 24, height: 24)
.clipShape(RoundedRectangle(cornerRadius: 4))
.onTapGestureForced {
showImageDisplayView = true
}
.onTapGestureForced(perform: handleAttachmentTap)
.padding(.leading, 8)
.padding(.vertical, 4)
}
Expand All @@ -270,7 +273,7 @@ private struct ImageAttachmentView: View {
.frame(width: 24, height: 24)
.padding(.horizontal, 8)
.padding(.vertical, 4)
.onTouchGesture(handleImageBtnTap)
.onTouchGesture(handleCameraTap)
}
.background(container2Color)
.cornerRadius(8)
Expand Down
11 changes: 7 additions & 4 deletions Splito/UI/Home/Expense/AddExpenseViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class AddExpenseViewModel: BaseViewModel, ObservableObject {
@Published var showAddNoteEditor = false
@Published var showGroupSelection = false
@Published var showPayerSelection = false
@Published var showImageDisplayView = false
@Published var showImagePickerOptions = false
@Published var showSplitTypeSelection = false
@Published private(set) var showLoader = false
Expand Down Expand Up @@ -186,7 +187,11 @@ extension AddExpenseViewModel {
showGroupSelection = expenseId == nil
}

func handleExpenseImageTap() {
func handleAttachmentTap() {
showImageDisplayView = true
}

func handleCameraTap() {
UIApplication.shared.endEditing()
showImagePickerOptions = true
}
Expand Down Expand Up @@ -421,9 +426,7 @@ extension AddExpenseViewModel {
newExpense.splitTo = splitData.map { $0.key }
newExpense.splitData = splitData
newExpense.splitType = splitType

let participants = Array(Set(newExpense.splitTo + newExpense.paidBy.keys))
newExpense.participants = participants
newExpense.participants = Array(Set(newExpense.splitTo + newExpense.paidBy.keys))

return await updateExpense(group: group, expense: newExpense, oldExpense: expense)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ struct ExpenseDetailsView: View {
@StateObject var viewModel: ExpenseDetailsViewModel

@FocusState var isFocused: Bool
@State private var showImageDisplayView = false

var body: some View {
VStack(alignment: .leading, spacing: 0) {
Expand All @@ -34,12 +33,10 @@ struct ExpenseDetailsView: View {
VStack(spacing: 12) {
SectionHeaderView(text: "Attachment")

AttachmentContainerView(showImageDisplayView: $showImageDisplayView, imageUrl: imageUrl)
AttachmentContainerView(imageUrl: imageUrl)
.frame(height: 140)
.clipShape(RoundedRectangle(cornerRadius: 12))
.onTapGestureForced {
showImageDisplayView = true
}
.onTapGestureForced(perform: viewModel.handleAttachmentTap)
.padding(.horizontal, 16)
}
.padding(.top, 8)
Expand Down Expand Up @@ -115,7 +112,7 @@ struct ExpenseDetailsView: View {
}
}
}
.navigationDestination(isPresented: $showImageDisplayView) {
.navigationDestination(isPresented: $viewModel.showImageDisplayView) {
if let imageUrl = viewModel.expense?.imageUrl, !imageUrl.isEmpty {
AttachmentZoomView(imageUrl: imageUrl)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class ExpenseDetailsViewModel: BaseViewModel, ObservableObject {

@Published var showLoader: Bool = false
@Published var showAddNoteEditor = false
@Published var showImageDisplayView = false
@Published var showEditExpenseSheet = false
@Published private(set) var hasMoreComments: Bool = true

Expand Down Expand Up @@ -165,6 +166,10 @@ class ExpenseDetailsViewModel: BaseViewModel, ObservableObject {
return expenseUsersData.first(where: { $0.id == id })
}

func handleAttachmentTap() {
showImageDisplayView = true
}

func handleNoteTap() {
guard let expense, expense.isActive, let userId = preference.user?.id,
let group, group.members.contains(userId) else { return }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,12 @@ struct GroupPaymentView: View {
.scrollIndicators(.hidden)
.scrollBounceBehavior(.basedOnSize)

AddNoteImageFooterView(date: $viewModel.paymentDate,
showImagePickerOptions: $viewModel.showImagePickerOptions,
image: viewModel.paymentImage, imageUrl: viewModel.paymentImageUrl,
isNoteEmpty: (viewModel.paymentNote.isEmpty &&
viewModel.paymentReason.isEmpty),
handleNoteBtnTap: viewModel.handleNoteBtnTap,
handleImageTap: viewModel.handlePaymentImageTap,
AddNoteImageFooterView(date: $viewModel.paymentDate, showImageDisplayView: $viewModel.showImageDisplayView,
showImagePickerOptions: $viewModel.showImagePickerOptions, image: viewModel.paymentImage,
imageUrl: viewModel.paymentImageUrl,
isNoteEmpty: (viewModel.paymentNote.isEmpty && viewModel.paymentReason.isEmpty),
handleNoteBtnTap: viewModel.handleNoteBtnTap, handleCameraTap: viewModel.handleCameraTap,
handleAttachmentTap: viewModel.handleAttachmentTap,
handleActionSelection: viewModel.handleActionSelection(_:))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class GroupPaymentViewModel: BaseViewModel, ObservableObject {

@Published var showImagePicker = false
@Published var showAddNoteEditor = false
@Published var showImageDisplayView = false
@Published var showImagePickerOptions = false
@Published private(set) var showLoader: Bool = false
@Published private(set) var sourceTypeIsCamera = false
Expand Down Expand Up @@ -154,8 +155,12 @@ class GroupPaymentViewModel: BaseViewModel, ObservableObject {
self.paymentNote = note
self.paymentReason = reason ?? ""
}

func handleAttachmentTap() {
showImageDisplayView = true
}

func handlePaymentImageTap() {
func handleCameraTap() {
UIApplication.shared.endEditing()
showImagePickerOptions = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ struct GroupTransactionDetailView: View {
@StateObject var viewModel: GroupTransactionDetailViewModel

@FocusState var isFocused: Bool
@State private var showImageDisplayView = false

var body: some View {
GeometryReader { geometry in
Expand Down Expand Up @@ -42,12 +41,10 @@ struct GroupTransactionDetailView: View {
VStack(spacing: 12) {
SectionHeaderView(text: "Attachment")

AttachmentContainerView(showImageDisplayView: $showImageDisplayView, imageUrl: imageUrl)
AttachmentContainerView(imageUrl: imageUrl)
.frame(height: 140)
.clipShape(RoundedRectangle(cornerRadius: 12))
.onTapGestureForced {
showImageDisplayView = true
}
.onTapGestureForced(perform: viewModel.handleAttachmentTap)
.padding(.horizontal, 16)
}
.padding(.top, 24)
Expand Down Expand Up @@ -129,7 +126,7 @@ struct GroupTransactionDetailView: View {
note: viewModel.paymentNote, paymentReason: viewModel.paymentReason))
}
}
.navigationDestination(isPresented: $showImageDisplayView) {
.navigationDestination(isPresented: $viewModel.showImageDisplayView) {
if let imageUrl = viewModel.transaction?.imageUrl, !imageUrl.isEmpty {
AttachmentZoomView(imageUrl: imageUrl)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class GroupTransactionDetailViewModel: BaseViewModel, ObservableObject {

@Published var showLoader: Bool = false
@Published var showAddNoteEditor = false
@Published var showImageDisplayView = false
@Published var showEditTransactionSheet = false
@Published private(set) var hasMoreComments: Bool = true

Expand Down Expand Up @@ -170,6 +171,10 @@ class GroupTransactionDetailViewModel: BaseViewModel, ObservableObject {
}

// MARK: - User Actions
func handleAttachmentTap() {
showImageDisplayView = true
}

func handleNoteTap() {
guard let transaction, transaction.isActive, let userId = preference.user?.id,
let group, group.members.contains(userId) else { return }
Expand Down

0 comments on commit d22ff1a

Please sign in to comment.