Skip to content

Commit

Permalink
chore(deps): update dependency onevcat/kingfisher to 8.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
EnesKaraosman committed Nov 15, 2024
1 parent 79027c8 commit c6a9c52
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 139 deletions.
27 changes: 17 additions & 10 deletions Example/Example/AdvancedExampleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ struct AdvancedExampleView: View {
}

private var chatView: some View {
ChatView<MessageMocker.ChatMessageItem, MessageMocker.ChatUserItem>(messages: $messages, scrollToBottom: $scrollToBottom) {
ChatView<MessageMocker.ChatMessageItem, MessageMocker.ChatUserItem>(
messages: $messages,
scrollToBottom: $scrollToBottom
) {
BasicInputView(
message: $message,
placeholder: "Type something",
Expand All @@ -44,13 +47,17 @@ struct AdvancedExampleView: View {
.messageCellContextMenu { message -> AnyView in
switch message.messageKind {
case .text:
return Button(action: {
print("Forward Context Menu tapped!!")
// Forward text
}) {
Text("Forward")
Image(systemName: "arrowshape.turn.up.right")
}.embedInAnyView()
return Button(
action: {
print("Forward Context Menu tapped!!")
// Forward text
},
label: {
Text("Forward")
Image(systemName: "arrowshape.turn.up.right")
}
)
.embedInAnyView()
default:
// If you don't want to implement contextMenu action
// for a specific case, simply return EmptyView like below;
Expand All @@ -68,15 +75,15 @@ struct AdvancedExampleView: View {
)
}
// ▼ Implement in case ChatMessageKind.contact
.contactItemButtons { (contact, message) -> [ContactCellButton] in
.contactItemButtons { (contact, _) -> [ContactCellButton] in
return [
.init(title: "Save", action: {
print(contact.displayName)
})
]
}
// ▼ Optional
.onCarouselItemAction(action: { (button, message) in
.onCarouselItemAction(action: { (_, message) in
print(message.messageKind.description)
})
// ▼ Required
Expand Down
38 changes: 20 additions & 18 deletions Example/Example/BasicExampleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import SwiftyChat
import SwiftyChatMock

struct BasicExampleView: View {

@State var messages: [MessageMocker.ChatMessageItem] = MessageMocker.generate(kind: .text, count: 20)

@State private var message = ""

var body: some View {
chatView
}

private var chatView: some View {
ChatView<MessageMocker.ChatMessageItem, MessageMocker.ChatUserItem>(messages: $messages) {

Expand All @@ -33,25 +33,27 @@ struct BasicExampleView: View {
)
.background(Color.primary.colorInvert())
.embedInAnyView()

}
// ▼ Optional, Present context menu when cell long pressed
.messageCellContextMenu { message -> AnyView in
switch message.messageKind {
case .text(let text):
return Button(action: {
print("Copy Context Menu tapped!!")
#if os(iOS)
UIPasteboard.general.string = text
#endif

#if os(macOS)
NSPasteboard.general.setString(text, forType: .string)
#endif
}) {
Text("Copy")
Image(systemName: "doc.on.doc")
}.embedInAnyView()
return Button(
action: {
print("Copy Context Menu tapped!!")
#if os(iOS)
UIPasteboard.general.string = text
#endif
#if os(macOS)
NSPasteboard.general.setString(text, forType: .string)
#endif
},
label: {
Text("Copy")
Image(systemName: "doc.on.doc")
}
).embedInAnyView()
default:
// If you don't want to implement contextMenu action
// for a specific case, simply return EmptyView like below;
Expand Down
3 changes: 1 addition & 2 deletions Example/Example/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension Color {
let futuraFont = Font.custom("Futura", size: 17)

extension ChatMessageCellStyle {

static let basicStyle = ChatMessageCellStyle(
incomingTextStyle: .init(
textStyle: .init(textColor: .black, font: futuraFont),
Expand All @@ -36,5 +36,4 @@ extension ChatMessageCellStyle {
),
incomingAvatarStyle: .init(imageStyle: .init(imageSize: .zero))
)

}
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/onevcat/Kingfisher.git",
"state" : {
"revision" : "3340001633525fd68c53d3a359e3c118797ad08e",
"version" : "8.0.2"
"revision" : "c0940e241945e6378c01fbd45fd3815579d47ef5",
"version" : "8.1.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let package = Package(
),
],
dependencies: [
.package(url: "https://github.com/onevcat/Kingfisher.git", from: "8.0.2"),
.package(url: "https://github.com/onevcat/Kingfisher.git", from: "8.1.0"),
.package(url: "https://github.com/EnesKaraosman/SwiftUIEKtensions.git", from: "0.4.0"),
.package(url: "https://github.com/dkk/WrappingHStack.git", from: "2.2.11")
],
Expand Down
21 changes: 5 additions & 16 deletions Sources/SwiftyChat/ChatMessageViewContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,15 @@ struct ChatMessageViewContainer<Message: ChatMessage>: View {
let contactFooterSection: (ContactItem, Message) -> [ContactCellButton]
let onCarouselItemAction: (CarouselItemButton, Message) -> Void

@ViewBuilder private func messageCell() -> some View {
@ViewBuilder
private func messageCell() -> some View {
switch message.messageKind {

case .text(let text):
TextMessageView(
text: text,
message: message,
size: size
)
TextMessageView(text: text, message: message, size: size)

case .location(let location):
LocationMessageView(
location: location,
message: message,
size: size
)
LocationMessageView(location: location, message: message, size: size)

case .imageText(let imageLoadingType, let text):
ImageTextMessageView(
Expand Down Expand Up @@ -71,11 +64,7 @@ struct ChatMessageViewContainer<Message: ChatMessage>: View {
)

case .video(let videoItem):
VideoMessageView(
media: videoItem,
message: message,
size: size
)
VideoMessageView(media: videoItem, message: message, size: size)

case .loading:
LoadingMessageView(message: message, size: size)
Expand Down
28 changes: 0 additions & 28 deletions Sources/SwiftyChat/Core/Extension/Double++.swift

This file was deleted.

4 changes: 2 additions & 2 deletions Sources/SwiftyChat/Core/Extension/UIDevice++.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public struct Device {
let orientation = UIDevice.current.orientation
return orientation == .landscapeLeft || orientation == .landscapeRight

#endif

#else
return false
#endif
}
}
34 changes: 12 additions & 22 deletions Sources/SwiftyChat/Core/Video/PIPVideoCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,29 +69,21 @@ struct PIPVideoCell<Message: ChatMessage>: View {
let inputViewOffset: CGFloat = videoManager.isFullScreen ? 0 : 60
let hPadding = videoManager.isFullScreen ? 0 : horizontalPadding
withAnimation(.easeIn) {
switch toCorner {
case .center:
location = .init(
x: size.width / 2,
y: size.height / 2
)
case .leftTop:
location = .init(
location = switch toCorner {
case .center: .init(x: size.width / 2, y: size.height / 2)
case .leftTop: .init(
x: (videoFrameWidth(in: size) / 2) + (hPadding / 2),
y: videoFrameHeight(in: size) / 2
)
case .leftBottom:
location = .init(
case .leftBottom: .init(
x: (videoFrameWidth(in: size) / 2) + (hPadding / 2),
y: size.height - videoFrameHeight(in: size) / 2 - inputViewOffset
)
case .rightTop:
location = .init(
case .rightTop: .init(
x: size.width - (videoFrameWidth(in: size) / 2) - (hPadding / 2),
y: videoFrameHeight(in: size) / 2
)
case .rightBottom:
location = .init(
case .rightBottom: .init(
x: size.width - (videoFrameWidth(in: size) / 2) - (hPadding / 2),
y: size.height - videoFrameHeight(in: size) / 2 - inputViewOffset
)
Expand All @@ -117,9 +109,8 @@ struct PIPVideoCell<Message: ChatMessage>: View {
.gesture(simpleDrag(in: geometry.size))
.animation(.linear(duration: 0.1))
.onAppear { rePositionVideoFrame(toCorner: .rightTop, in: geometry.size) }
.onAppear {

videoManager.$isFullScreen
.onAppear { [weak videoManager] in
videoManager?.$isFullScreen
.removeDuplicates()
.sink { _ in
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
Expand All @@ -141,7 +132,6 @@ struct PIPVideoCell<Message: ChatMessage>: View {
}
.onDisappear {
cancellables.forEach { $0.cancel() }
print("☠️ pip disappeared..")
}
}
}
Expand All @@ -166,20 +156,20 @@ struct PIPVideoCell<Message: ChatMessage>: View {
var newLocation = startLocation ?? location
newLocation.x += value.translation.width
newLocation.y += value.translation.height
self.location = newLocation
location = newLocation
}
.updating($startLocation) { _, startLocation, _ in
startLocation = startLocation ?? location
}
.onEnded { _ in
if self.location.y > size.midY {
if self.location.x > size.midX {
if location.y > size.midY {
if location.x > size.midX {
rePositionVideoFrame(toCorner: .rightBottom, in: size)
} else {
rePositionVideoFrame(toCorner: .leftBottom, in: size)
}
} else {
if self.location.x > size.midX {
if location.x > size.midX {
rePositionVideoFrame(toCorner: .rightTop, in: size)
} else {
rePositionVideoFrame(toCorner: .leftTop, in: size)
Expand Down
26 changes: 19 additions & 7 deletions Sources/SwiftyChat/Core/Video/PlayerViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,35 @@ import AVFoundation
import Combine

final class PlayerViewModel: ObservableObject {
let player = AVPlayer()
@Published var isInPipMode: Bool = false
@Published var isPlaying = false
@Published var isEditingCurrentTime = false
@Published var currentTime: Double = .zero
@Published var duration: Double?
let player: AVPlayer

@Published
var isEditingCurrentTime = false

@Published
var currentTime: Double = .zero

@Published
var isInPipMode: Bool = false

@Published
private(set) var isPlaying = false

@Published
private(set) var duration: Double?

private var subscriptions: Set<AnyCancellable> = []
private var timeObserver: Any?

deinit {
if let timeObserver = timeObserver {
if let timeObserver {
player.removeTimeObserver(timeObserver)
}
}

init() {
player = AVPlayer()

$isEditingCurrentTime
.dropFirst()
.filter({ $0 == false })
Expand Down
Loading

0 comments on commit c6a9c52

Please sign in to comment.