From acdd65b9031b9819a33750ac9492a4883ab1eab5 Mon Sep 17 00:00:00 2001 From: Anthony Li Date: Sun, 24 Mar 2024 13:21:47 -0400 Subject: [PATCH 1/9] Replace aspectRatio with scaledToFill --- Sources/PennForms/FormComponents/ImagePicker.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/PennForms/FormComponents/ImagePicker.swift b/Sources/PennForms/FormComponents/ImagePicker.swift index a281e30..0794baa 100644 --- a/Sources/PennForms/FormComponents/ImagePicker.swift +++ b/Sources/PennForms/FormComponents/ImagePicker.swift @@ -40,7 +40,7 @@ public struct ImagePicker: FormComponent { image .resizable() - .aspectRatio(contentMode: .fill) + .scaledToFill() .frame(width: 350, height: 200) .clipShape(RoundedRectangle(cornerRadius: 8)) @@ -58,7 +58,7 @@ public struct ImagePicker: FormComponent { Image(uiImage: selectedImages[0]) .resizable() - .aspectRatio(contentMode: .fill) + .scaledToFill() .frame(width: 350, height: 200) .clipShape(RoundedRectangle(cornerRadius: 8)) From 52664462b5f57f572e560f3dfe67a8bb795af93a Mon Sep 17 00:00:00 2001 From: Anthony Li Date: Sun, 24 Mar 2024 13:25:16 -0400 Subject: [PATCH 2/9] Add contentShape modifiers --- Sources/PennForms/FormComponents/ImagePicker.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/PennForms/FormComponents/ImagePicker.swift b/Sources/PennForms/FormComponents/ImagePicker.swift index 0794baa..b7edb9f 100644 --- a/Sources/PennForms/FormComponents/ImagePicker.swift +++ b/Sources/PennForms/FormComponents/ImagePicker.swift @@ -43,6 +43,7 @@ public struct ImagePicker: FormComponent { .scaledToFill() .frame(width: 350, height: 200) .clipShape(RoundedRectangle(cornerRadius: 8)) + .contentShape(RoundedRectangle(cornerRadius: 8) } }, @@ -61,6 +62,7 @@ public struct ImagePicker: FormComponent { .scaledToFill() .frame(width: 350, height: 200) .clipShape(RoundedRectangle(cornerRadius: 8)) + .contentShape(RoundedRectangle(cornerRadius: 8) } From 1f23c02548094141f786e2737f7f7b2d01329b70 Mon Sep 17 00:00:00 2001 From: Anthony Li Date: Sun, 24 Mar 2024 13:26:21 -0400 Subject: [PATCH 3/9] Fix parentheses --- Sources/PennForms/FormComponents/ImagePicker.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/PennForms/FormComponents/ImagePicker.swift b/Sources/PennForms/FormComponents/ImagePicker.swift index b7edb9f..a796b0e 100644 --- a/Sources/PennForms/FormComponents/ImagePicker.swift +++ b/Sources/PennForms/FormComponents/ImagePicker.swift @@ -43,7 +43,7 @@ public struct ImagePicker: FormComponent { .scaledToFill() .frame(width: 350, height: 200) .clipShape(RoundedRectangle(cornerRadius: 8)) - .contentShape(RoundedRectangle(cornerRadius: 8) + .contentShape(RoundedRectangle(cornerRadius: 8)) } }, @@ -62,7 +62,7 @@ public struct ImagePicker: FormComponent { .scaledToFill() .frame(width: 350, height: 200) .clipShape(RoundedRectangle(cornerRadius: 8)) - .contentShape(RoundedRectangle(cornerRadius: 8) + .contentShape(RoundedRectangle(cornerRadius: 8)) } From 762d6bd2d9cbca68063b0376ebdb2dd576d87bfd Mon Sep 17 00:00:00 2001 From: Anthony Li Date: Sun, 24 Mar 2024 13:32:48 -0400 Subject: [PATCH 4/9] Disable hit testing on image entirely --- Sources/PennForms/FormComponents/ImagePicker.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/PennForms/FormComponents/ImagePicker.swift b/Sources/PennForms/FormComponents/ImagePicker.swift index a796b0e..452ac73 100644 --- a/Sources/PennForms/FormComponents/ImagePicker.swift +++ b/Sources/PennForms/FormComponents/ImagePicker.swift @@ -43,7 +43,7 @@ public struct ImagePicker: FormComponent { .scaledToFill() .frame(width: 350, height: 200) .clipShape(RoundedRectangle(cornerRadius: 8)) - .contentShape(RoundedRectangle(cornerRadius: 8)) + .allowsHitTesting(false) } }, @@ -63,6 +63,7 @@ public struct ImagePicker: FormComponent { .frame(width: 350, height: 200) .clipShape(RoundedRectangle(cornerRadius: 8)) .contentShape(RoundedRectangle(cornerRadius: 8)) + .allowsHitTesting(false) } From e384e7beacc01dc68a61ee0fb25fa55876e4ed67 Mon Sep 17 00:00:00 2001 From: JHawk0224 Date: Wed, 10 Apr 2024 15:39:13 -0400 Subject: [PATCH 5/9] Fix overflow on old version --- Sources/PennForms/FormComponents/ImagePicker.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/PennForms/FormComponents/ImagePicker.swift b/Sources/PennForms/FormComponents/ImagePicker.swift index e3fc2e7..5000430 100644 --- a/Sources/PennForms/FormComponents/ImagePicker.swift +++ b/Sources/PennForms/FormComponents/ImagePicker.swift @@ -61,7 +61,7 @@ public struct ImagePicker: FormComponent { url: URL(string: url), content: { image in image.resizable() - .scaledToFill() + .scaledToFit() .badge(imageStr: "xmark", badgeColor: Color(uiColor: .systemGray3), textColor: Color(uiColor: .systemGray), action: { withAnimation { @@ -80,7 +80,7 @@ public struct ImagePicker: FormComponent { ForEach(selectedImages, id: \.self) { image in Image(uiImage: image) .resizable() - .scaledToFill() + .scaledToFit() .frame(width: 120, height: 120) } } From 2535634f4e17467112bc10e054efae808b68de36 Mon Sep 17 00:00:00 2001 From: christinaqiu3 Date: Sun, 14 Apr 2024 13:35:56 -0400 Subject: [PATCH 6/9] fixed aspect ratio of images --- Sources/PennForms/FormComponents/ImagePicker.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sources/PennForms/FormComponents/ImagePicker.swift b/Sources/PennForms/FormComponents/ImagePicker.swift index 5000430..d86e289 100644 --- a/Sources/PennForms/FormComponents/ImagePicker.swift +++ b/Sources/PennForms/FormComponents/ImagePicker.swift @@ -60,8 +60,11 @@ public struct ImagePicker: FormComponent { AsyncImage( url: URL(string: url), content: { image in + image.resizable() - .scaledToFit() + .aspectRatio(contentMode: .fill) + .frame(width: 350, height: 200) + .clipShape(RoundedRectangle(cornerRadius: 8)) .badge(imageStr: "xmark", badgeColor: Color(uiColor: .systemGray3), textColor: Color(uiColor: .systemGray), action: { withAnimation { @@ -80,8 +83,9 @@ public struct ImagePicker: FormComponent { ForEach(selectedImages, id: \.self) { image in Image(uiImage: image) .resizable() - .scaledToFit() - .frame(width: 120, height: 120) + .aspectRatio(contentMode: .fill) + .frame(width: 120, height: 120) + .clipShape(RoundedRectangle(cornerRadius: 8)) } } if selectedImages.count + existingImages.count < maxSelectionCount { From 3be0ee42cd8be794267147140a4338f33f9bec8b Mon Sep 17 00:00:00 2001 From: christinaqiu3 Date: Sun, 14 Apr 2024 14:03:19 -0400 Subject: [PATCH 7/9] greyed out unpicked photos --- .../FormComponents/ImagePicker.swift | 142 +++++++++++------- 1 file changed, 91 insertions(+), 51 deletions(-) diff --git a/Sources/PennForms/FormComponents/ImagePicker.swift b/Sources/PennForms/FormComponents/ImagePicker.swift index d86e289..d9d4e36 100644 --- a/Sources/PennForms/FormComponents/ImagePicker.swift +++ b/Sources/PennForms/FormComponents/ImagePicker.swift @@ -30,71 +30,111 @@ public struct ImagePicker: FormComponent { public var body: some View { VStack(alignment: .leading, spacing: 10) { - PhotosPicker(selection: $selection, - maxSelectionCount: maxSelectionCount - existingImages.count, - matching: .any(of: [.images, .not(.videos)])) { - VStack(spacing: 8) { - Image(systemName: "photo.badge.plus") - Text("Add Photos") - } - .frame(width: 350, height: 200) - .background(RoundedRectangle(cornerRadius: 8) - .strokeBorder(style: StrokeStyle(lineWidth: 1, dash: [7]))) - .foregroundColor(!showValidationErrors || validator.isValid(selectedImages.count + existingImages.count) ? Color.secondary : Color.red) - } - .onChange(of: selection) { newSelection in - Task { - selectedImages.removeAll() - for item in newSelection { - if let data = try? await item.loadTransferable(type: Data.self), let image = UIImage(data: data) { - selectedImages.append(image) - } - } - } - } - - ScrollView(.horizontal) { - HStack(spacing: 8) { - if existingImages.count > 0 { - ForEach(existingImages, id: \.self) { url in + if existingImages.count > 0 { AsyncImage( - url: URL(string: url), + url: URL(string: existingImages[0]), content: { image in - - image.resizable() - .aspectRatio(contentMode: .fill) - .frame(width: 350, height: 200) - .clipShape(RoundedRectangle(cornerRadius: 8)) - .badge(imageStr: "xmark", badgeColor: Color(uiColor: .systemGray3), textColor: - Color(uiColor: .systemGray), action: { - withAnimation { - existingImages.removeAll(where: { $0 == url }) - } - }) - .frame(width: 120, height: 120) + ZStack { + RoundedRectangle(cornerRadius: 8) + .strokeBorder(style: StrokeStyle(lineWidth: 0.5)) + .frame(width: 350, height: 200) + + image + .resizable() + .aspectRatio(contentMode: .fill) + .frame(width: 350, height: 200) + .clipShape(RoundedRectangle(cornerRadius: 8)) + + } }, placeholder: { ProgressView() } ) + } else if selectedImages.count > 0 { + ZStack { + RoundedRectangle(cornerRadius: 8) + .strokeBorder(style: StrokeStyle(lineWidth: 0.5)) + .frame(width: 350, height: 200) + + Image(uiImage: selectedImages[0]) + .resizable() + .aspectRatio(contentMode: .fill) + .frame(width: 350, height: 200) + .clipShape(RoundedRectangle(cornerRadius: 8)) + + + } + } else { + PhotosPicker(selection: $selection, + maxSelectionCount: maxSelectionCount - existingImages.count, + matching: .any(of: [.images, .not(.videos)])) { + VStack(spacing: 8) { + Image(systemName: "photo.badge.plus") + Text("Add Photos") + } + .frame(width: 350, height: 200) + .background(RoundedRectangle(cornerRadius: 8) + .strokeBorder(style: StrokeStyle(lineWidth: 1, dash: [7]))) + .foregroundColor(!showValidationErrors || validator.isValid(selectedImages.count + existingImages.count) ? Color.secondary : Color.red) + } + .onChange(of: selection) { newSelection in + Task { + selectedImages.removeAll() + for item in newSelection { + if let data = try? await item.loadTransferable(type: Data.self), let image = UIImage(data: data) { + selectedImages.append(image) + } } } - if selectedImages.count > 0 { - ForEach(selectedImages, id: \.self) { image in - Image(uiImage: image) - .resizable() - .aspectRatio(contentMode: .fill) - .frame(width: 120, height: 120) - .clipShape(RoundedRectangle(cornerRadius: 8)) + } + } + + ScrollView(.horizontal) { + HStack(spacing: 8) { + ForEach(Array(existingImages.enumerated()), id: \.offset) { index, url in + if index != 0 { +// ForEach(existingImages, id: \.self) { url in + AsyncImage( + url: URL(string: url), + content: { image in + + image.resizable() + .aspectRatio(contentMode: .fill) + .frame(width: 350, height: 200) + .clipShape(RoundedRectangle(cornerRadius: 8)) + .badge(imageStr: "xmark", badgeColor: Color(uiColor: .systemGray3), textColor: + Color(uiColor: .systemGray), action: { + withAnimation { + existingImages.removeAll(where: { $0 == url }) + } + }) + .frame(width: 120, height: 120) + }, + placeholder: { + ProgressView() + } + ) +// } + } + } + if (existingImages.count == 0 && selectedImages.count-1 > 0) || selectedImages.count > 0 { + ForEach(Array(selectedImages.enumerated()), id: \.offset) { index, image in + if index != 0 { + Image(uiImage: image) + .resizable() + .aspectRatio(contentMode: .fill) + .frame(width: 120, height: 120) + .clipShape(RoundedRectangle(cornerRadius: 8)) + } } } if selectedImages.count + existingImages.count < maxSelectionCount { ForEach(0..<(maxSelectionCount - selectedImages.count - existingImages.count), id: \.self) { _ in - Image(systemName: "photo.badge.plus") + RoundedRectangle(cornerRadius: 8) .frame(width: 120, height: 120) - .background(RoundedRectangle(cornerRadius: 8) - .strokeBorder(style: StrokeStyle(lineWidth: 0.5))) - .foregroundColor(Color.secondary) + .foregroundColor(Color.gray.opacity(0.5)) // Fill color for the rounded rectangle + } } } From 884e51de70e1199041e27d3001215059b724c96c Mon Sep 17 00:00:00 2001 From: christinaqiu3 Date: Sun, 14 Apr 2024 14:06:42 -0400 Subject: [PATCH 8/9] clicking on main image allows for photopicker popup --- .../FormComponents/ImagePicker.swift | 110 +++++++++++++----- 1 file changed, 78 insertions(+), 32 deletions(-) diff --git a/Sources/PennForms/FormComponents/ImagePicker.swift b/Sources/PennForms/FormComponents/ImagePicker.swift index d9d4e36..4ea48a7 100644 --- a/Sources/PennForms/FormComponents/ImagePicker.swift +++ b/Sources/PennForms/FormComponents/ImagePicker.swift @@ -31,40 +31,86 @@ public struct ImagePicker: FormComponent { public var body: some View { VStack(alignment: .leading, spacing: 10) { if existingImages.count > 0 { - AsyncImage( - url: URL(string: existingImages[0]), - content: { image in - ZStack { - RoundedRectangle(cornerRadius: 8) - .strokeBorder(style: StrokeStyle(lineWidth: 0.5)) - .frame(width: 350, height: 200) - - image - .resizable() - .aspectRatio(contentMode: .fill) - .frame(width: 350, height: 200) - .clipShape(RoundedRectangle(cornerRadius: 8)) - - } - }, - placeholder: { - ProgressView() - } - ) - } else if selectedImages.count > 0 { + + PhotosPicker(selection: $selection, + maxSelectionCount: maxSelectionCount - existingImages.count, + matching: .any(of: [.images, .not(.videos)])) { + AsyncImage( + url: URL(string: existingImages[0]), + content: { image in ZStack { - RoundedRectangle(cornerRadius: 8) - .strokeBorder(style: StrokeStyle(lineWidth: 0.5)) - .frame(width: 350, height: 200) - - Image(uiImage: selectedImages[0]) - .resizable() - .aspectRatio(contentMode: .fill) - .frame(width: 350, height: 200) - .clipShape(RoundedRectangle(cornerRadius: 8)) - + RoundedRectangle(cornerRadius: 8) + .strokeBorder(style: StrokeStyle(lineWidth: 0.5)) + .frame(width: 350, height: 200) + + image + .resizable() + .aspectRatio(contentMode: .fill) + .frame(width: 350, height: 200) + .clipShape(RoundedRectangle(cornerRadius: 8)) - } + } + }, + placeholder: { + ProgressView() + } + ) + .frame(width: 350, height: 200) + .background(RoundedRectangle(cornerRadius: 8) + .strokeBorder(style: StrokeStyle(lineWidth: 1, dash: [7]))) + .foregroundColor(!showValidationErrors || validator.isValid(selectedImages.count + existingImages.count) ? Color.secondary : Color.red) + } + .onChange(of: selection) { newSelection in + Task { + selectedImages.removeAll() + for item in newSelection { + if let data = try? await item.loadTransferable(type: Data.self), let image = UIImage(data: data) { + selectedImages.append(image) + } + } + } + } + + + + + } else if selectedImages.count > 0 { + PhotosPicker(selection: $selection, + maxSelectionCount: maxSelectionCount - existingImages.count, + matching: .any(of: [.images, .not(.videos)])) { + ZStack { + RoundedRectangle(cornerRadius: 8) + .strokeBorder(style: StrokeStyle(lineWidth: 0.5)) + .frame(width: 350, height: 200) + + Image(uiImage: selectedImages[0]) + .resizable() + .aspectRatio(contentMode: .fill) + .frame(width: 350, height: 200) + .clipShape(RoundedRectangle(cornerRadius: 8)) + + + } + .frame(width: 350, height: 200) + .background(RoundedRectangle(cornerRadius: 8) + .strokeBorder(style: StrokeStyle(lineWidth: 1, dash: [7]))) + .foregroundColor(!showValidationErrors || validator.isValid(selectedImages.count + existingImages.count) ? Color.secondary : Color.red) + } + .onChange(of: selection) { newSelection in + Task { + selectedImages.removeAll() + for item in newSelection { + if let data = try? await item.loadTransferable(type: Data.self), let image = UIImage(data: data) { + selectedImages.append(image) + } + } + } + } + + + + + } else { PhotosPicker(selection: $selection, maxSelectionCount: maxSelectionCount - existingImages.count, From 382ad0c97f1ee1329e62636226bbc1f2ab805f91 Mon Sep 17 00:00:00 2001 From: JHawk0224 Date: Sun, 21 Apr 2024 18:33:08 -0400 Subject: [PATCH 9/9] Slight daterange bugfix --- Sources/PennForms/FormComponents/DateRangeField.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/PennForms/FormComponents/DateRangeField.swift b/Sources/PennForms/FormComponents/DateRangeField.swift index d4e2c42..2bec248 100644 --- a/Sources/PennForms/FormComponents/DateRangeField.swift +++ b/Sources/PennForms/FormComponents/DateRangeField.swift @@ -49,9 +49,9 @@ public struct DateRangeField: FormComponent { .bold() } HStack { - let begin = range.lowerBound < lowerDate ? lowerDate : range.lowerBound - let end = range.upperBound > upperDate ? upperDate : range.upperBound - DateRangeSubfield(date: $lowerDate, range: self.range.lowerBound...end, placeholder: lowerPlaceholder, wasSet: $wasSet1) + let begin = max(self.lowerDate, self.range.lowerBound) + let end = min(self.upperDate, self.range.upperBound) + DateRangeSubfield(date: $lowerDate, range: min(self.range.lowerBound, end)...max(self.range.lowerBound, end), placeholder: lowerPlaceholder, wasSet: $wasSet1) DateRangeSubfield(date: $upperDate, range: begin...self.range.upperBound, placeholder: upperPlaceholder, wasSet: $wasSet2) } @@ -69,7 +69,7 @@ public struct DateRangeField: FormComponent { self.lowerDate = self.range.lowerBound == .distantPast ? .now : self.range.lowerBound } .onChange(of: wasSet2) { _ in - self.upperDate = Calendar.current.date(byAdding: .day, value: upperOffset, to: .now) ?? (self.range.upperBound == .distantFuture ? .now : self.range.upperBound) + self.upperDate = min(Calendar.current.date(byAdding: .day, value: upperOffset, to: self.range.lowerBound == .distantPast ? .now : self.range.lowerBound) ?? .now, self.range.upperBound) } } }