Skip to content

Commit

Permalink
Remove delete menu action and PopupView dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
f3dm76 committed Jul 8, 2024
1 parent bfdbf9d commit 99857b5
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 78 deletions.
131 changes: 128 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,132 @@

# Created by https://www.gitignore.io/api/swift,macos,carthage,cocoapods
# Edit at https://www.gitignore.io/?templates=swift,macos,carthage,cocoapods

### Carthage ###
# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build

### CocoaPods ###
## CocoaPods GitIgnore Template

# CocoaPods - Only use to conserve bandwidth / Save time on Pushing
# - Also handy if you have a large number of dependant pods
# - AS PER https://guides.cocoapods.org/using/using-cocoapods.html NEVER IGNORE THE LOCK FILE
Pods/
Podfile.lock
Example.xcworkspace

### macOS ###
# General
.DS_Store
.idea
**/xcuserdata/*
Package.resolved
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Swift ###
# Xcode
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
# Package.resolved
.build/
# Add this line if you want to avoid checking in Xcode SPM integration.
# .swiftpm/xcode

# CocoaPods
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
# Pods/
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace

# Carthage
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts


# Accio dependency management
Dependencies/
.accio/

# fastlane
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output

# Code Injection
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/

# End of https://www.gitignore.io/api/swift,macos,carthage,cocoapods
.idea/

/.build/
GoogleService-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/exyte/FloatingButton",
"state" : {
"revision" : "301fba68ed56c68c04af0b40a4eb422518c8eaf8",
"version" : "1.2.2"
"revision" : "cf77c2f124df1423d90a9a1985e9b9ccfa4b9b3e",
"version" : "1.3.0"
}
},
{
"identity" : "mediapicker",
"kind" : "remoteSourceControl",
"location" : "https://github.com/exyte/MediaPicker.git",
"state" : {
"revision" : "f493425514490b0629725387122d15d2876aeff5",
"version" : "2.1.1"
}
},
{
"identity" : "popupview",
"kind" : "remoteSourceControl",
"location" : "https://github.com/exyte/PopupView.git",
"state" : {
"revision" : "259f45a4fcc42ea4ebb3ab61e8d6d6dfc4f652ed",
"version" : "3.0.3"
"revision" : "88769b1b69c2b5e5fa5b65522c08bc7b667a6cb8",
"version" : "2.2.3"
}
},
{
"identity" : "swiftui-introspect",
"kind" : "remoteSourceControl",
"location" : "https://github.com/siteline/SwiftUI-Introspect.git",
"location" : "https://github.com/siteline/swiftui-introspect",
"state" : {
"revision" : "9e1cc02a65b22e09a8251261cccbccce02731fc5",
"version" : "1.1.1"
"revision" : "668a65735751432b640260c56dfa621cec568368",
"version" : "1.2.0"
}
}
],
Expand Down
5 changes: 1 addition & 4 deletions Example/ChatExample/Screens/CommentsExampleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ struct CommentsExampleView: View {
print(editedText)
})
case .delete:
defaultActionClosure(message, .delete(confirmClosure: {
// delete this message on your BE
print("deleted")
}))
print("deleted")
case .print:
print(message.text)
}
Expand Down
2 changes: 1 addition & 1 deletion ExyteChat.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "ExyteChat"
s.version = "2.0.0"
s.version = "2.0.1"
s.summary = "Chat with fully customizable message cells and built-in media picker written with SwiftUI"

s.homepage = 'https://github.com/exyte/Chat.git'
Expand Down
7 changes: 1 addition & 6 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ let package = Package(
url: "https://github.com/exyte/ActivityIndicatorView",
from: "1.0.0"
),
.package(
url: "https://github.com/exyte/PopupView.git",
from: "3.0.0"
),
],
targets: [
.target(
Expand All @@ -42,8 +38,7 @@ let package = Package(
.product(name: "SwiftUIIntrospect", package: "swiftui-introspect"),
.product(name: "ExyteMediaPicker", package: "MediaPicker"),
.product(name: "FloatingButton", package: "FloatingButton"),
.product(name: "ActivityIndicatorView", package: "ActivityIndicatorView"),
.product(name: "PopupView", package: "PopupView")
.product(name: "ActivityIndicatorView", package: "ActivityIndicatorView")
]
),
.testTarget(
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ ChatView(messages: viewModel.messages) { draft in
```
`messageMenuAction`'s parameters:
- `selectedMenuAction` - action selected by the user from the menu. NOTE: when declaring this variable, specify its type (your custom descendant of MessageMenuAction) explicitly
- `defaultActionClosure` - a closure taking a case of default implementation of MessageMenuAction which provides simple actions handlers; you call this closure passing the selected message and choosing one of the default actions if you need them; or you can write a custom implementation for all your actions, in that case just ignore this closure
- `defaultActionClosure` - a closure taking a case of default implementation of MessageMenuAction which provides simple actions handlers; you call this closure passing the selected message and choosing one of the default actions (.reply, .edit) if you need them; or you can write a custom implementation for all your actions, in that case just ignore this closure
- `message` - message for which the menu is displayed

When implementing your own `MessageMenuActionClosure`, write a switch statement passing through all the cases of your `MessageMenuAction`, inside each case write your own action handler, or call the default one. NOTE: not all default actions work out of the box - e.g. for `.edit` you'll still need to provide a closure to save the edited text on your BE. Please see CommentsExampleView in ChatExample project for MessageMenuActionClosure usage example.
Expand Down
33 changes: 1 addition & 32 deletions Sources/ExyteChat/ChatView/ChatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import SwiftUI
import FloatingButton
import SwiftUIIntrospect
import ExyteMediaPicker
import PopupView

public typealias MediaPickerParameters = SelectionParamsHolder

Expand Down Expand Up @@ -190,36 +189,6 @@ public struct ChatView<MessageContent: View, InputViewContent: View, MenuAction:
globalFocusState.focus = nil
}
}

.popup(isPresented: $viewModel.showConfirmDeleteMessage) {
VStack(spacing: 0) {
Text("Are you sure you want to delete this message?")
.multilineTextAlignment(.center)
.padding(15)

Divider()

Button("Delete", role: .destructive) {
viewModel.confirmDeleteMessageClosure?()
viewModel.showConfirmDeleteMessage = false
}
.padding(15)

Divider()

Button("Cancel", role: .cancel) {
viewModel.confirmDeleteMessageClosure = nil
viewModel.showConfirmDeleteMessage = false
}
.padding(15)
}
.background(.ultraThickMaterial)
.cornerRadius(10)
.padding(.horizontal, 30)
} customize: {
$0.type(.floater())
.closeOnTap(false)
}
}

var mainView: some View {
Expand Down Expand Up @@ -328,7 +297,7 @@ public struct ChatView<MessageContent: View, InputViewContent: View, MenuAction:
ScrollView {
messageMenu(row)
}
.introspect(.scrollView, on: .iOS(.v16, .v17)) { scrollView in
.introspect(.scrollView, on: .iOS(.v16, .v17, .v18)) { scrollView in
DispatchQueue.main.async {
self.menuScrollView = scrollView
}
Expand Down
6 changes: 0 additions & 6 deletions Sources/ExyteChat/ChatView/ChatViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ final class ChatViewModel: ObservableObject {
var inputViewModel: InputViewModel?
var globalFocusState: GlobalFocusState?

@Published var showConfirmDeleteMessage = false
@Published var confirmDeleteMessageClosure: (() -> Void)?

func presentAttachmentFullScreen(_ attachment: Attachment) {
fullscreenAttachmentItem = attachment
fullscreenAttachmentPresented = true
Expand Down Expand Up @@ -53,9 +50,6 @@ final class ChatViewModel: ObservableObject {
inputViewModel?.text = message.text
inputViewModel?.edit(saveClosure)
globalFocusState?.focus = .uuid(inputFieldId)
case .delete(let confirmClosure):
showConfirmDeleteMessage = true
confirmDeleteMessageClosure = confirmClosure
}
}
}
10 changes: 1 addition & 9 deletions Sources/ExyteChat/ChatView/MessageView/MessageMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@ public enum DefaultMessageMenuAction: MessageMenuAction {

case reply
case edit(saveClosure: (String)->Void)
case delete(confirmClosure: ()->Void)

public func title() -> String {
switch self {
case .reply:
"Reply"
case .edit:
"Edit"
case .delete:
"Delete"
}
}

Expand All @@ -37,8 +34,6 @@ public enum DefaultMessageMenuAction: MessageMenuAction {
Image(.reply)
case .edit:
Image(.edit)
case .delete:
Image(.delete)
}
}

Expand All @@ -49,14 +44,11 @@ public enum DefaultMessageMenuAction: MessageMenuAction {
if case .edit(_) = lhs, case .edit(_) = rhs {
return true
}
if case .delete(_) = lhs, case .delete(_) = rhs {
return true
}
return false
}

public static var allCases: [DefaultMessageMenuAction] = [
.reply, .edit(saveClosure: {_ in}), .delete(confirmClosure: {})
.reply, .edit(saveClosure: {_ in})
]
}

Expand Down

0 comments on commit 99857b5

Please sign in to comment.