-
Notifications
You must be signed in to change notification settings - Fork 4
Add attachmentPreview for MessageComposerView #14
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
Changes from 3 commits
cb4a3a5
00275fb
6d6400b
6d55863
7ca89a2
0de0b8c
18a21ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ extension EnvironmentValues { | |
| @Entry var onSubmitAction: () -> Void = {} | ||
| @Entry var disableAttachments: Bool = false | ||
| @Entry var attachmentActions: AnyView = AnyView(EmptyView()) | ||
| @Entry var attachmentPreview: AnyView = AnyView(EmptyView()) | ||
| } | ||
|
|
||
| extension View { | ||
|
|
@@ -36,13 +37,18 @@ extension View { | |
| public func attachmentActions<Content: View>(@ViewBuilder content: () -> Content) -> some View { | ||
| environment(\.attachmentActions, AnyView(content())) | ||
| } | ||
|
|
||
| public func attachmentPreview<Content: View>(@ViewBuilder content: () -> Content) -> some View { | ||
| environment(\.attachmentPreview, AnyView(content())) | ||
| } | ||
| } | ||
|
|
||
| public struct MessageComposerView: View { | ||
| @Environment(\.onSubmitAction) private var onSubmitAction | ||
| @Environment(\.disableAttachments) private var disableAttachments | ||
| @Environment(\.attachmentActions) private var attachmentActions | ||
|
|
||
| @Environment(\.attachmentPreview) private var attachmentPreview | ||
|
|
||
| @Binding var message: String | ||
|
|
||
| public init(message: Binding<String>) { | ||
|
|
@@ -63,18 +69,22 @@ public struct MessageComposerView: View { | |
| .controlSize(.large) | ||
| .buttonBorderShape(.circle) | ||
| } | ||
|
|
||
| VStack { | ||
| attachmentPreview | ||
|
|
||
| HStack(alignment: .bottom) { | ||
| TextField("Enter a message", text: $message, axis: .vertical) | ||
| .frame(minHeight: 32) | ||
| .padding(EdgeInsets(top: 7, leading: 16, bottom: 7, trailing: 0)) | ||
| .onSubmit(of: .text) { onSubmitAction() } | ||
|
|
||
| Button(action: { onSubmitAction() }) { | ||
| Image(systemName: "arrow.up") | ||
| HStack(alignment: .bottom) { | ||
| TextField("Enter a message", text: $message, axis: .vertical) | ||
| .frame(minHeight: 32) | ||
| .padding(EdgeInsets(top: 7, leading: 16, bottom: 7, trailing: 0)) | ||
| .onSubmit(of: .text) { onSubmitAction() } | ||
|
|
||
| Button(action: { onSubmitAction() }) { | ||
| Image(systemName: "arrow.up") | ||
| } | ||
| .buttonStyle(.borderedProminent) | ||
| .padding(EdgeInsets(top: 7, leading: 0, bottom: 7, trailing: 7)) | ||
| } | ||
| .buttonStyle(.borderedProminent) | ||
| .padding(EdgeInsets(top: 7, leading: 0, bottom: 7, trailing: 7)) | ||
| } | ||
| .glassEffect(.regular.interactive(), in: .rect(cornerRadius: 20.0)) | ||
| .offset(x: -5.0, y: 0.0) | ||
|
|
@@ -101,20 +111,24 @@ public struct MessageComposerView: View { | |
| ) | ||
| .padding(.trailing, 8) | ||
| } | ||
|
|
||
| HStack(alignment: .bottom) { | ||
| TextField("Enter a message", text: $message, axis: .vertical) | ||
| .frame(minHeight: 32) | ||
| .padding(EdgeInsets(top: 6, leading: 16, bottom: 6, trailing: 0)) | ||
| .onSubmit(of: .text) { onSubmitAction() } | ||
|
|
||
| Button(action: { onSubmitAction() }) { | ||
| Image(systemName: "arrow.up") | ||
|
|
||
| VStack { | ||
| attachmentPreview | ||
|
|
||
| HStack(alignment: .bottom) { | ||
| TextField("Enter a message", text: $message, axis: .vertical) | ||
| .frame(minHeight: 32) | ||
| .padding(EdgeInsets(top: 6, leading: 16, bottom: 6, trailing: 0)) | ||
| .onSubmit(of: .text) { onSubmitAction() } | ||
|
|
||
| Button(action: { onSubmitAction() }) { | ||
| Image(systemName: "arrow.up") | ||
| } | ||
| .buttonStyle(.borderedProminent) | ||
| .buttonBorderShape(.circle) | ||
| .controlSize(.regular) | ||
| .padding(EdgeInsets(top: 6, leading: 0, bottom: 6, trailing: 7)) | ||
| } | ||
| .buttonStyle(.borderedProminent) | ||
| .buttonBorderShape(.circle) | ||
| .controlSize(.regular) | ||
| .padding(EdgeInsets(top: 6, leading: 0, bottom: 6, trailing: 7)) | ||
| } | ||
| .background(.regularMaterial) | ||
| .clipShape(RoundedRectangle(cornerRadius: 22)) | ||
|
Comment on lines
+115
to
134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is significant code duplication between this block (for older iOS versions) and the one inside the To improve maintainability, consider refactoring the common view structure into a private |
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.