Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Example/ChatExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
9B49D53A263D9606008804B5 /* CustomLayoutSizeCalculator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B49D539263D9606008804B5 /* CustomLayoutSizeCalculator.swift */; };
9B49D542263DA6F9008804B5 /* CustomMessageContentCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B49D541263DA6F9008804B5 /* CustomMessageContentCell.swift */; };
9B49D547263DAA29008804B5 /* CustomTextMessageContentCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B49D546263DAA29008804B5 /* CustomTextMessageContentCell.swift */; };
ABCBBB1428F57513008955E4 /* InputBarAccessoryView in Frameworks */ = {isa = PBXBuildFile; productRef = ABCBBB1328F57513008955E4 /* InputBarAccessoryView */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -124,6 +125,7 @@
buildActionMask = 2147483647;
files = (
13EFA5D927AC5634003002CC /* Kingfisher in Frameworks */,
ABCBBB1428F57513008955E4 /* InputBarAccessoryView in Frameworks */,
1C5433DF24C38DBF00A5383B /* SwiftUI.framework in Frameworks */,
13EFA5D727AC5631003002CC /* MessageKit in Frameworks */,
);
Expand Down Expand Up @@ -349,6 +351,7 @@
packageProductDependencies = (
13EFA5D627AC5631003002CC /* MessageKit */,
13EFA5D827AC5634003002CC /* Kingfisher */,
ABCBBB1328F57513008955E4 /* InputBarAccessoryView */,
);
productName = ChatExample;
productReference = 882B5E331CF7D4B900B6E160 /* ChatExample.app */;
Expand Down Expand Up @@ -426,6 +429,7 @@
mainGroup = 882B5E2A1CF7D4B900B6E160;
packageReferences = (
13CCA06125793E24005C19BB /* XCRemoteSwiftPackageReference "Kingfisher" */,
ABCBBB1228F57513008955E4 /* XCRemoteSwiftPackageReference "InputBarAccessoryView" */,
);
productRefGroup = 882B5E341CF7D4B900B6E160 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -820,6 +824,14 @@
minimumVersion = 5.15.8;
};
};
ABCBBB1228F57513008955E4 /* XCRemoteSwiftPackageReference "InputBarAccessoryView" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/deemaze/InputBarAccessoryView.git";
requirement = {
branch = "custom-attachment-cell";
kind = branch;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand All @@ -841,6 +853,11 @@
package = 13CCA06125793E24005C19BB /* XCRemoteSwiftPackageReference "Kingfisher" */;
productName = Kingfisher;
};
ABCBBB1328F57513008955E4 /* InputBarAccessoryView */ = {
isa = XCSwiftPackageProductDependency;
package = ABCBBB1228F57513008955E4 /* XCRemoteSwiftPackageReference "InputBarAccessoryView" */;
productName = InputBarAccessoryView;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 882B5E2B1CF7D4B900B6E160 /* Project object */;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PreviewsEnabled</key>
<false/>
</dict>
</plist>
Comment on lines +1 to +8

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this?

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let package = Package(
.plugin(name: "SwiftFormatPlugin", targets: ["SwiftFormatPlugin"]),
],
dependencies: [
.package(url: "https://github.com/nathantannar4/InputBarAccessoryView", .upToNextMajor(from: "6.1.0")),
.package(url: "https://github.com/deemaze/InputBarAccessoryView", branch: "custom-attachment-cell")
],
targets: [
// MARK: - MessageKit
Expand Down
73 changes: 66 additions & 7 deletions Sources/Layout/MessageSizeCalculator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,27 @@ open class MessageSizeCalculator: CellSizeCalculator {
open func avatarPosition(for message: MessageType) -> AvatarPosition {
let dataSource = messagesLayout.messagesDataSource
let isFromCurrentSender = dataSource.isFromCurrentSender(message: message)
var position = isFromCurrentSender ? outgoingAvatarPosition : incomingAvatarPosition

// Check if RTL mode is active
let isRTL = messagesLayout.messagesCollectionView.rtlLanguageProvider?.isRTLLanguage ?? false

// In RTL, swap incoming/outgoing positions
var position: AvatarPosition
if isRTL {
position = isFromCurrentSender ? incomingAvatarPosition : outgoingAvatarPosition
} else {
position = isFromCurrentSender ? outgoingAvatarPosition : incomingAvatarPosition
}

switch position.horizontal {
case .cellTrailing, .cellLeading:
break
case .natural:
position.horizontal = isFromCurrentSender ? .cellTrailing : .cellLeading
if isRTL {
position.horizontal = isFromCurrentSender ? .cellLeading : .cellTrailing
} else {
position.horizontal = isFromCurrentSender ? .cellTrailing : .cellLeading
}
}
return position
}
Expand Down Expand Up @@ -157,7 +171,16 @@ open class MessageSizeCalculator: CellSizeCalculator {
open func cellTopLabelAlignment(for message: MessageType) -> LabelAlignment {
let dataSource = messagesLayout.messagesDataSource
let isFromCurrentSender = dataSource.isFromCurrentSender(message: message)
return isFromCurrentSender ? outgoingCellTopLabelAlignment : incomingCellTopLabelAlignment

// Check if RTL mode is active
let isRTL = messagesLayout.messagesCollectionView.rtlLanguageProvider?.isRTLLanguage ?? false

// In RTL, swap incoming/outgoing alignments
if isRTL {
return isFromCurrentSender ? incomingCellTopLabelAlignment : outgoingCellTopLabelAlignment
} else {
return isFromCurrentSender ? outgoingCellTopLabelAlignment : incomingCellTopLabelAlignment
}
}

// MARK: - Top message Label
Expand All @@ -179,7 +202,16 @@ open class MessageSizeCalculator: CellSizeCalculator {

let dataSource = messagesLayout.messagesDataSource
let isFromCurrentSender = dataSource.isFromCurrentSender(message: message)
return isFromCurrentSender ? outgoingMessageTopLabelAlignment : incomingMessageTopLabelAlignment

// Check if RTL mode is active
let isRTL = collectionView.rtlLanguageProvider?.isRTLLanguage ?? false

// In RTL, swap incoming/outgoing alignments
if isRTL {
return isFromCurrentSender ? incomingMessageTopLabelAlignment : outgoingMessageTopLabelAlignment
} else {
return isFromCurrentSender ? outgoingMessageTopLabelAlignment : incomingMessageTopLabelAlignment
}
}

// MARK: - Message time label
Expand All @@ -205,7 +237,16 @@ open class MessageSizeCalculator: CellSizeCalculator {
open func cellBottomLabelAlignment(for message: MessageType) -> LabelAlignment {
let dataSource = messagesLayout.messagesDataSource
let isFromCurrentSender = dataSource.isFromCurrentSender(message: message)
return isFromCurrentSender ? outgoingCellBottomLabelAlignment : incomingCellBottomLabelAlignment

// Check if RTL mode is active
let isRTL = messagesLayout.messagesCollectionView.rtlLanguageProvider?.isRTLLanguage ?? false

// In RTL, swap incoming/outgoing alignments
if isRTL {
return isFromCurrentSender ? incomingCellBottomLabelAlignment : outgoingCellBottomLabelAlignment
} else {
return isFromCurrentSender ? outgoingCellBottomLabelAlignment : incomingCellBottomLabelAlignment
}
}

// MARK: - Bottom Message Label
Expand All @@ -227,15 +268,33 @@ open class MessageSizeCalculator: CellSizeCalculator {

let dataSource = messagesLayout.messagesDataSource
let isFromCurrentSender = dataSource.isFromCurrentSender(message: message)
return isFromCurrentSender ? outgoingMessageBottomLabelAlignment : incomingMessageBottomLabelAlignment

// Check if RTL mode is active
let isRTL = collectionView.rtlLanguageProvider?.isRTLLanguage ?? false

// In RTL, swap incoming/outgoing alignments
if isRTL {
return isFromCurrentSender ? incomingMessageBottomLabelAlignment : outgoingMessageBottomLabelAlignment
} else {
return isFromCurrentSender ? outgoingMessageBottomLabelAlignment : incomingMessageBottomLabelAlignment
}
}

// MARK: - MessageContainer

open func messageContainerPadding(for message: MessageType) -> UIEdgeInsets {
let dataSource = messagesLayout.messagesDataSource
let isFromCurrentSender = dataSource.isFromCurrentSender(message: message)
return isFromCurrentSender ? outgoingMessagePadding : incomingMessagePadding

// Check if RTL mode is active
let isRTL = messagesLayout.messagesCollectionView.rtlLanguageProvider?.isRTLLanguage ?? false

// In RTL, swap incoming/outgoing paddings
if isRTL {
return isFromCurrentSender ? incomingMessagePadding : outgoingMessagePadding
} else {
return isFromCurrentSender ? outgoingMessagePadding : incomingMessagePadding
}
}

open func messageContainerSize(for _: MessageType, at _: IndexPath) -> CGSize {
Expand Down
4 changes: 4 additions & 0 deletions Sources/Views/Cells/MessageContentCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ open class MessageContentCell: MessageCollectionViewCell {
open var cellTopLabel: InsetLabel = {
let label = InsetLabel()
label.numberOfLines = 0
label.adjustsFontForContentSizeCategory = true
label.textAlignment = .center
return label
}()
Expand All @@ -64,6 +65,7 @@ open class MessageContentCell: MessageCollectionViewCell {
open var cellBottomLabel: InsetLabel = {
let label = InsetLabel()
label.numberOfLines = 0
label.adjustsFontForContentSizeCategory = true
label.textAlignment = .center
return label
}()
Expand All @@ -72,13 +74,15 @@ open class MessageContentCell: MessageCollectionViewCell {
open var messageTopLabel: InsetLabel = {
let label = InsetLabel()
label.numberOfLines = 0
label.adjustsFontForContentSizeCategory = true
return label
}()

/// The bottom label of the messageBubble.
open var messageBottomLabel: InsetLabel = {
let label = InsetLabel()
label.numberOfLines = 0
label.adjustsFontForContentSizeCategory = true
return label
}()

Expand Down
8 changes: 8 additions & 0 deletions Sources/Views/MessagesCollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
import Foundation
import UIKit

/// Protocol to provide RTL (Right-to-Left) language support for MessageKit
public protocol RTLLanguageProvider: AnyObject {
/// Returns `true` if the current language is RTL (Right-to-Left)
var isRTLLanguage: Bool { get }
}

open class MessagesCollectionView: UICollectionView {
// MARK: Lifecycle

Expand Down Expand Up @@ -55,6 +61,8 @@ open class MessagesCollectionView: UICollectionView {

open weak var messageCellDelegate: MessageCellDelegate?

open weak var rtlLanguageProvider: RTLLanguageProvider?

open var isTypingIndicatorHidden: Bool {
messagesCollectionViewFlowLayout.isTypingIndicatorViewHidden
}
Expand Down
Loading