-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extends example app to include edit and delete functionality in `.moc…
…k` and `.live` mode
- Loading branch information
1 parent
80e0a40
commit 6a41b58
Showing
7 changed files
with
316 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
Example/AblyChatExample/MessageViews/DeletedMessageView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import SwiftUI | ||
|
||
struct DeletedMessageView: View { | ||
var item: MessageListItem | ||
|
||
var body: some View { | ||
HStack(alignment: .firstTextBaseline) { | ||
VStack { | ||
Text("\(item.message.clientID):") | ||
.foregroundColor(.blue) | ||
.bold() | ||
} | ||
VStack { | ||
Text("This message was deleted.") | ||
.foregroundStyle(.secondary) | ||
.italic() | ||
} | ||
} | ||
#if !os(tvOS) | ||
.listRowSeparator(.hidden) | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import SwiftUI | ||
|
||
struct MenuButtonView: View { | ||
var onEdit: () -> Void | ||
var onDelete: () -> Void | ||
|
||
var body: some View { | ||
Menu { | ||
Button(action: onEdit) { | ||
Label("Edit", systemImage: "pencil") | ||
} | ||
|
||
Button(role: .destructive, action: onDelete) { | ||
Label("Delete", systemImage: "trash") | ||
} | ||
} label: { | ||
Image(systemName: "ellipsis.circle") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import AblyChat | ||
import SwiftUI | ||
|
||
struct MessageView: View { | ||
var item: MessageListItem | ||
@Binding var isEditing: Bool | ||
var onDelete: () -> Void | ||
@State private var isPresentingConfirm = false | ||
|
||
var body: some View { | ||
HStack(alignment: .firstTextBaseline) { | ||
VStack { | ||
Text("\(item.message.clientID):") | ||
.foregroundColor(.blue) | ||
.bold() | ||
} | ||
VStack(alignment: .leading) { | ||
Text(item.message.text) | ||
.foregroundStyle(.black) | ||
.background(isEditing ? .orange.opacity(0.12) : .clear) | ||
if item.message.action == .update { | ||
Text("Edited").foregroundStyle(.gray).font(.footnote) | ||
} | ||
} | ||
Spacer() | ||
if item.isSender { | ||
MenuButtonView( | ||
onEdit: { | ||
isEditing = true | ||
}, onDelete: { | ||
isPresentingConfirm = true | ||
} | ||
) | ||
.confirmationDialog( | ||
"Are you sure?", | ||
isPresented: $isPresentingConfirm | ||
) { | ||
Button("Delete message", role: .destructive) { | ||
onDelete() | ||
isPresentingConfirm = false | ||
} | ||
} message: { | ||
Text("You cannot undo this action") | ||
} | ||
} | ||
} | ||
#if !os(tvOS) | ||
.listRowSeparator(.hidden) | ||
#endif | ||
} | ||
} | ||
|
||
struct MessageListItem { | ||
var message: Message | ||
var isSender: Bool = false | ||
} |
Oops, something went wrong.