Skip to content

Commit 6453df1

Browse files
committed
Fix Demo
1 parent ea4b14d commit 6453df1

14 files changed

Lines changed: 99 additions & 135 deletions

File tree

ChatLayout/Classes/Core/CollectionViewChatLayout.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ open class CollectionViewChatLayout: NSUICollectionViewLayout {
236236

237237
private var needsIOS15_1IssueFix: Bool {
238238
#if canImport(AppKit) && !targetEnvironment(macCatalyst)
239-
// return true
240239
return false
241240
#endif
242241

ChatLayout/Classes/Core/Extensions/CollectionView+Extension.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import AppKit
66
extension NSCollectionView {
77
var contentOffset: CGPoint {
88
set {
9-
enclosingScrollView?.contentView.scroll(to: newValue)
9+
enclosingScrollView?.contentView.setBoundsOrigin(newValue)
1010
// animator().scroll(newValue)
1111
}
1212
get {

ChatLayout/Classes/Core/Extensions/NSEdgeInsets+Extension.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Foundation
33
#if canImport(AppKit) && !targetEnvironment(macCatalyst)
44
import AppKit
55

6-
extension NSEdgeInsets: Equatable {
6+
extension NSEdgeInsets: @retroactive Equatable {
77
public static func == (lhs: NSEdgeInsets, rhs: NSEdgeInsets) -> Bool {
88
lhs.top == rhs.top && lhs.left == rhs.left && lhs.right == rhs.right && lhs
99
.bottom == rhs.bottom

Example/ChatLayout.xcodeproj/project.pbxproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@
284284
E9622F332CA2B6DE00EEA1CA /* Typealias.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Typealias.swift; sourceTree = "<group>"; };
285285
E9A2833E2CA2EB74007C8383 /* ChatLayout_Example_macOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ChatLayout_Example_macOS.app; sourceTree = BUILT_PRODUCTS_DIR; };
286286
E9A283402CA2EB74007C8383 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
287-
E9A283422CA2EB75007C8383 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
288287
E9A283452CA2EB75007C8383 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
289288
E9A283472CA2EB75007C8383 /* ChatLayout_Example_macOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = ChatLayout_Example_macOS.entitlements; sourceTree = "<group>"; };
290289
E9A2836D2CA2EFDC007C8383 /* NSLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSLabel.swift; sourceTree = "<group>"; };
@@ -683,7 +682,6 @@
683682
isa = PBXGroup;
684683
children = (
685684
E9A283402CA2EB74007C8383 /* AppDelegate.swift */,
686-
E9A283422CA2EB75007C8383 /* Assets.xcassets */,
687685
E9A283442CA2EB75007C8383 /* MainMenu.xib */,
688686
E9A283472CA2EB75007C8383 /* ChatLayout_Example_macOS.entitlements */,
689687
);

Example/ChatLayout/Assets.xcassets/AppIcon.appiconset/Contents.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,56 @@
9797
"idiom" : "ios-marketing",
9898
"scale" : "1x",
9999
"size" : "1024x1024"
100+
},
101+
{
102+
"idiom" : "mac",
103+
"scale" : "1x",
104+
"size" : "16x16"
105+
},
106+
{
107+
"idiom" : "mac",
108+
"scale" : "2x",
109+
"size" : "16x16"
110+
},
111+
{
112+
"idiom" : "mac",
113+
"scale" : "1x",
114+
"size" : "32x32"
115+
},
116+
{
117+
"idiom" : "mac",
118+
"scale" : "2x",
119+
"size" : "32x32"
120+
},
121+
{
122+
"idiom" : "mac",
123+
"scale" : "1x",
124+
"size" : "128x128"
125+
},
126+
{
127+
"idiom" : "mac",
128+
"scale" : "2x",
129+
"size" : "128x128"
130+
},
131+
{
132+
"idiom" : "mac",
133+
"scale" : "1x",
134+
"size" : "256x256"
135+
},
136+
{
137+
"idiom" : "mac",
138+
"scale" : "2x",
139+
"size" : "256x256"
140+
},
141+
{
142+
"idiom" : "mac",
143+
"scale" : "1x",
144+
"size" : "512x512"
145+
},
146+
{
147+
"idiom" : "mac",
148+
"scale" : "2x",
149+
"size" : "512x512"
100150
}
101151
],
102152
"info" : {

Example/ChatLayout/Chat/Extension/AppKit+.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -165,21 +165,6 @@ extension NSView {
165165
return layer?.backgroundColor.flatMap { NSColor(cgColor: $0) }
166166
}
167167
}
168-
169-
static var layoutMarginsKey: Void = ()
170-
171-
// var layoutMargins: NSEdgeInsets {
172-
// set {
173-
// objc_setAssociatedObject(self, &Self.layoutMarginsKey, NSValue(edgeInsets: newValue), .OBJC_ASSOCIATION_COPY_NONATOMIC)
174-
// }
175-
// get {
176-
// (objc_getAssociatedObject(self, &Self.layoutMarginsKey) as? NSValue)?.edgeInsetsValue ?? .zero
177-
// }
178-
// }
179-
180-
// @objc func _marginsInsetsForSafeAreaInsets(_ insets: NSEdgeInsets) -> NSEdgeInsets {
181-
// layoutMargins + safeAreaInsets
182-
// }
183168
}
184169

185170
extension NSEdgeInsets {

Example/ChatLayout/Chat/Model/DefaultRandomDataProvider.swift

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -143,32 +143,32 @@ final class DefaultRandomDataProvider: RandomDataProvider {
143143
guard enableNewMessages else {
144144
return
145145
}
146-
// let message = createRandomMessage()
147-
// delegate?.received(messages: [message])
148-
//
149-
// if message.userId != receiverId {
150-
// if Int.random(in: 0...1) == 0 {
151-
// lastReceivedUUID = message.id
152-
// delegate?.lastReceivedIdChanged(to: message.id)
153-
// }
154-
// if Int.random(in: 0...3) == 0 {
155-
// lastReadUUID = lastReceivedUUID
156-
// lastReceivedUUID = message.id
157-
// delegate?.lastReadIdChanged(to: message.id)
158-
// }
159-
// }
160-
//
161-
// restartMessageTimer()
162-
// restartTypingTimer()
146+
let message = createRandomMessage()
147+
delegate?.received(messages: [message])
148+
149+
if message.userId != receiverId {
150+
if Int.random(in: 0...1) == 0 {
151+
lastReceivedUUID = message.id
152+
delegate?.lastReceivedIdChanged(to: message.id)
153+
}
154+
if Int.random(in: 0...3) == 0 {
155+
lastReadUUID = lastReceivedUUID
156+
lastReceivedUUID = message.id
157+
delegate?.lastReadIdChanged(to: message.id)
158+
}
159+
}
160+
161+
restartMessageTimer()
162+
restartTypingTimer()
163163
}
164164

165165
@objc
166166
private func handleTypingTimer() {
167167
guard enableTyping else {
168168
return
169169
}
170-
// typingState = typingState == .idle ? TypingState.typing : .idle
171-
// delegate?.typingStateChanged(to: typingState)
170+
typingState = typingState == .idle ? TypingState.typing : .idle
171+
delegate?.typingStateChanged(to: typingState)
172172
}
173173

174174
private func restartMessageTimer() {
@@ -184,22 +184,22 @@ final class DefaultRandomDataProvider: RandomDataProvider {
184184
}
185185

186186
private func createRandomMessage(date: Date = Date()) -> RawMessage {
187-
let sender = allUsersIds[0] // allUsersIds.first!//
187+
let sender = allUsersIds[Int.random(in: 0..<allUsersIds.count)] // allUsersIds.first!//
188188
lastMessageIndex += 1
189189
switch (Int.random(in: 0...8), enableRichContent) {
190-
// case (5, true):
191-
// return RawMessage(id: UUID(), date: date, data: .url(websiteUrls[Int.random(in: 0..<websiteUrls.count)]), userId: sender)
192-
// case (6, true):
193-
// return RawMessage(id: UUID(), date: date, data: .image(.imageURL(imageUrls[Int.random(in: 0..<imageUrls.count)])), userId: sender)
194-
// case (7, true):
195-
// return RawMessage(id: UUID(), date: date, data: .image(.image(images[Int.random(in: 0..<images.count)])), userId: sender)
196-
// case (8, true):
197-
// return RawMessage(id: UUID(),
198-
// date: date,
199-
// data: .text(TextGenerator.getString(of: 5) +
200-
// " \(websiteUrls[Int.random(in: 0..<websiteUrls.count)]). " +
201-
// TextGenerator.getString(of: 5)),
202-
// userId: sender)
190+
case (5, true):
191+
return RawMessage(id: UUID(), date: date, data: .url(websiteUrls[Int.random(in: 0..<websiteUrls.count)]), userId: sender)
192+
case (6, true):
193+
return RawMessage(id: UUID(), date: date, data: .image(.imageURL(imageUrls[Int.random(in: 0..<imageUrls.count)])), userId: sender)
194+
case (7, true):
195+
return RawMessage(id: UUID(), date: date, data: .image(.image(images[Int.random(in: 0..<images.count)])), userId: sender)
196+
case (8, true):
197+
return RawMessage(id: UUID(),
198+
date: date,
199+
data: .text(TextGenerator.getString(of: 5) +
200+
" \(websiteUrls[Int.random(in: 0..<websiteUrls.count)]). " +
201+
TextGenerator.getString(of: 5)),
202+
userId: sender)
203203
default:
204204
return RawMessage(id: UUID(), date: date, data: .text(TextGenerator.getString(of: 20)), userId: sender)
205205
}

Example/ChatLayout/Chat/Model/TextGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class TextGenerator {
5858
return ""
5959
}
6060

61-
var result = words.prefix(wordsCount).joined(separator: " ")
61+
var result = words.shuffled().prefix(wordsCount).joined(separator: " ")
6262
result.replaceSubrange(result.startIndex...result.startIndex, with: String(result[result.startIndex]).capitalized)
6363
return result + "."
6464
}

Example/ChatLayout/Chat/View/ChatViewController+AppKit.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,14 @@ final class ChatViewController: NSViewController {
101101

102102
scrollView.documentView = collectionView
103103
scrollView.translatesAutoresizingMaskIntoConstraints = false
104-
scrollView.frame = view.bounds
105104
scrollView.hasHorizontalScroller = false
106105
scrollView.hasVerticalScroller = true
107-
scrollView.drawsBackground = false
108-
scrollView.backgroundColor = .clear
106+
// scrollView.drawsBackground = false
107+
scrollView.automaticallyAdjustsContentInsets = false
108+
scrollView.contentInsets = .zero
109+
scrollView.contentView.contentInsets = .zero
110+
111+
scrollView.scrollerStyle = .legacy
109112

110113
NSLayoutConstraint.activate([
111114
scrollView.topAnchor.constraint(equalTo: view.topAnchor, constant: 0),
@@ -122,8 +125,6 @@ final class ChatViewController: NSViewController {
122125
self.currentControllerActions.options.remove(.loadingInitialMessages)
123126
self.processUpdates(with: sections, animated: true, requiresIsolatedProcess: false)
124127
}
125-
126-
collectionView.addGestureRecognizer(panGesture)
127128
}
128129

129130
override func viewWillAppear() {

Example/ChatLayout/Chat/View/Other/BezierMaskedView.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ private func generateIncomingTailedBezierPath(offset: CGFloat, size: CGSize) ->
162162
bezierPath.addCurve(to: CGPoint(x: 22, y: size.height), controlPoint1: CGPoint(x: 16, y: size.height), controlPoint2: CGPoint(x: 19, y: size.height))
163163
bezierPath.close()
164164
bezierPath.apply(CGAffineTransform(translationX: offset, y: 0))
165-
165+
#if canImport(AppKit) && !targetEnvironment(macCatalyst)
166+
bezierPath.apply(CGAffineTransform(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: size.height))
167+
#endif
166168
return bezierPath
167169
}
168170

@@ -175,6 +177,9 @@ private func generateOutgoingTailedBezierPath(offset: CGFloat, size: CGSize) ->
175177

176178
private func generateIncomingNormalBezierPath(offset: CGFloat, size: CGSize) -> NSUIBezierPath {
177179
let bezierPath = NSUIBezierPath(roundedRect: CGRect(x: offset, y: 0, width: size.width - offset, height: size.height), cornerRadius: 17)
180+
#if canImport(AppKit) && !targetEnvironment(macCatalyst)
181+
bezierPath.apply(CGAffineTransform(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: size.height))
182+
#endif
178183
return bezierPath
179184
}
180185

0 commit comments

Comments
 (0)