Skip to content

Commit

Permalink
Replace MainViewBuilder, so there is no AnyView involved
Browse files Browse the repository at this point in the history
  • Loading branch information
f3dm76 committed Jul 3, 2024
2 parents 18c4f9b + db67d1e commit 47030b0
Show file tree
Hide file tree
Showing 31 changed files with 757 additions and 400 deletions.
66 changes: 39 additions & 27 deletions Example/ChatExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@
135987BA2869F3AE006388CF /* MockMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 135987B92869F3AE006388CF /* MockMessage.swift */; };
135987BD2869F6F2006388CF /* ChatInteractorProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 135987BC2869F6F2006388CF /* ChatInteractorProtocol.swift */; };
135987BF2869F704006388CF /* MockChatInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 135987BE2869F704006388CF /* MockChatInteractor.swift */; };
1376133E28782F8E00E7CF67 /* Date+Random.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1376133D28782F8E00E7CF67 /* Date+Random.swift */; };
1376133E28782F8E00E7CF67 /* Date+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1376133D28782F8E00E7CF67 /* Date+Extensions.swift */; };
1376F7BB286472530016CD1B /* ChatError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1376F7BA286472530016CD1B /* ChatError.swift */; };
13DF042D2864790B0043DBBC /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13DF042C2864790B0043DBBC /* ContentView.swift */; };
13DF043228647C070043DBBC /* ChatExampleViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13DF043128647C070043DBBC /* ChatExampleViewModel.swift */; };
13E17B6D2869E940004DF140 /* MockUser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13E17B6C2869E940004DF140 /* MockUser.swift */; };
13E17B6F2869E983004DF140 /* MockChatData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13E17B6E2869E983004DF140 /* MockChatData.swift */; };
13F1C0EF286AC86200D25D8A /* ChatExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13F1C0EE286AC86200D25D8A /* ChatExampleView.swift */; };
13F1C0F2286ADD8900D25D8A /* MockAttachment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13F1C0F1286ADD8900D25D8A /* MockAttachment.swift */; };
5B0636D72C2E9F6100E54AEE /* CommentsExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B0636D52C2E9F6100E54AEE /* CommentsExampleView.swift */; };
5B0636D82C2E9F6100E54AEE /* CommentsExampleViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B0636D62C2E9F6100E54AEE /* CommentsExampleViewModel.swift */; };
5B0636DB2C2EA21900E54AEE /* Sequence+asyncMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B0636DA2C2EA21900E54AEE /* Sequence+asyncMap.swift */; };
5B35D75C2A989D70006A1A67 /* ExyteChat in Frameworks */ = {isa = PBXBuildFile; productRef = 5B35D75B2A989D70006A1A67 /* ExyteChat */; };
5B6D3A732987D85A00765148 /* Color+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B6D3A722987D85A00765148 /* Color+Extension.swift */; };
5B6D3A732987D85A00765148 /* Color+hex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B6D3A722987D85A00765148 /* Color+hex.swift */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand All @@ -48,7 +51,7 @@
135987B92869F3AE006388CF /* MockMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockMessage.swift; sourceTree = "<group>"; };
135987BC2869F6F2006388CF /* ChatInteractorProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatInteractorProtocol.swift; sourceTree = "<group>"; };
135987BE2869F704006388CF /* MockChatInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockChatInteractor.swift; sourceTree = "<group>"; };
1376133D28782F8E00E7CF67 /* Date+Random.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+Random.swift"; sourceTree = "<group>"; };
1376133D28782F8E00E7CF67 /* Date+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+Extensions.swift"; sourceTree = "<group>"; };
1376F7A3286466460016CD1B /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
1376F7A6286466770016CD1B /* Chat */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = Chat; path = ..; sourceTree = "<group>"; };
1376F7BA286472530016CD1B /* ChatError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatError.swift; sourceTree = "<group>"; };
Expand All @@ -58,7 +61,10 @@
13E17B6E2869E983004DF140 /* MockChatData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockChatData.swift; sourceTree = "<group>"; };
13F1C0EE286AC86200D25D8A /* ChatExampleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatExampleView.swift; sourceTree = "<group>"; };
13F1C0F1286ADD8900D25D8A /* MockAttachment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockAttachment.swift; sourceTree = "<group>"; };
5B6D3A722987D85A00765148 /* Color+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Color+Extension.swift"; sourceTree = "<group>"; };
5B0636D52C2E9F6100E54AEE /* CommentsExampleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentsExampleView.swift; sourceTree = "<group>"; };
5B0636D62C2E9F6100E54AEE /* CommentsExampleViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentsExampleViewModel.swift; sourceTree = "<group>"; };
5B0636DA2C2EA21900E54AEE /* Sequence+asyncMap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Sequence+asyncMap.swift"; sourceTree = "<group>"; };
5B6D3A722987D85A00765148 /* Color+hex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Color+hex.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -95,12 +101,12 @@
isa = PBXGroup;
children = (
135549332864620900C9459A /* ChatExampleApp.swift */,
13DF043128647C070043DBBC /* ChatExampleViewModel.swift */,
13F1C0EE286AC86200D25D8A /* ChatExampleView.swift */,
13DF042C2864790B0043DBBC /* ContentView.swift */,
1376F7B3286471A80016CD1B /* Data */,
1376F7B4286471B30016CD1B /* Drivers */,
1376133C28782F7C00E7CF67 /* Extension */,
1376F7B3286471A80016CD1B /* Model */,
13F1C0F3286ADE5D00D25D8A /* DataGeneration */,
135987BB2869F6C2006388CF /* ChatInteractor */,
5B0636D92C2EA0CB00E54AEE /* Screens */,
1376133C28782F7C00E7CF67 /* Extensions */,
1376F7AE286470B70016CD1B /* Support Files */,
);
path = ChatExample;
Expand All @@ -114,22 +120,23 @@
path = "Preview Content";
sourceTree = "<group>";
};
135987BB2869F6C2006388CF /* Chat */ = {
135987BB2869F6C2006388CF /* ChatInteractor */ = {
isa = PBXGroup;
children = (
135987BC2869F6F2006388CF /* ChatInteractorProtocol.swift */,
135987BE2869F704006388CF /* MockChatInteractor.swift */,
);
path = Chat;
path = ChatInteractor;
sourceTree = "<group>";
};
1376133C28782F7C00E7CF67 /* Extension */ = {
1376133C28782F7C00E7CF67 /* Extensions */ = {
isa = PBXGroup;
children = (
1376133D28782F8E00E7CF67 /* Date+Random.swift */,
5B6D3A722987D85A00765148 /* Color+Extension.swift */,
1376133D28782F8E00E7CF67 /* Date+Extensions.swift */,
5B6D3A722987D85A00765148 /* Color+hex.swift */,
5B0636DA2C2EA21900E54AEE /* Sequence+asyncMap.swift */,
);
path = Extension;
path = Extensions;
sourceTree = "<group>";
};
1376F7A5286466770016CD1B /* Packages */ = {
Expand Down Expand Up @@ -157,33 +164,35 @@
name = "Support Files";
sourceTree = "<group>";
};
1376F7B3286471A80016CD1B /* Data */ = {
1376F7B3286471A80016CD1B /* Model */ = {
isa = PBXGroup;
children = (
1376F7BA286472530016CD1B /* ChatError.swift */,
13E17B6C2869E940004DF140 /* MockUser.swift */,
135987B92869F3AE006388CF /* MockMessage.swift */,
13F1C0F1286ADD8900D25D8A /* MockAttachment.swift */,
);
path = Data;
path = Model;
sourceTree = "<group>";
};
1376F7B4286471B30016CD1B /* Drivers */ = {
13F1C0F3286ADE5D00D25D8A /* DataGeneration */ = {
isa = PBXGroup;
children = (
13F1C0F3286ADE5D00D25D8A /* Data Generation */,
135987BB2869F6C2006388CF /* Chat */,
135987B72869F369006388CF /* Lorem.swift */,
13E17B6E2869E983004DF140 /* MockChatData.swift */,
);
path = Drivers;
path = DataGeneration;
sourceTree = "<group>";
};
13F1C0F3286ADE5D00D25D8A /* Data Generation */ = {
5B0636D92C2EA0CB00E54AEE /* Screens */ = {
isa = PBXGroup;
children = (
135987B72869F369006388CF /* Lorem.swift */,
13E17B6E2869E983004DF140 /* MockChatData.swift */,
13F1C0EE286AC86200D25D8A /* ChatExampleView.swift */,
13DF043128647C070043DBBC /* ChatExampleViewModel.swift */,
5B0636D52C2E9F6100E54AEE /* CommentsExampleView.swift */,
5B0636D62C2E9F6100E54AEE /* CommentsExampleViewModel.swift */,
);
path = "Data Generation";
path = Screens;
sourceTree = "<group>";
};
/* End PBXGroup section */
Expand Down Expand Up @@ -263,14 +272,17 @@
buildActionMask = 2147483647;
files = (
13DF043228647C070043DBBC /* ChatExampleViewModel.swift in Sources */,
5B6D3A732987D85A00765148 /* Color+Extension.swift in Sources */,
5B6D3A732987D85A00765148 /* Color+hex.swift in Sources */,
13E17B6F2869E983004DF140 /* MockChatData.swift in Sources */,
1376F7BB286472530016CD1B /* ChatError.swift in Sources */,
135987B82869F369006388CF /* Lorem.swift in Sources */,
135987BA2869F3AE006388CF /* MockMessage.swift in Sources */,
1376133E28782F8E00E7CF67 /* Date+Random.swift in Sources */,
1376133E28782F8E00E7CF67 /* Date+Extensions.swift in Sources */,
5B0636D82C2E9F6100E54AEE /* CommentsExampleViewModel.swift in Sources */,
13F1C0EF286AC86200D25D8A /* ChatExampleView.swift in Sources */,
135987BF2869F704006388CF /* MockChatInteractor.swift in Sources */,
5B0636D72C2E9F6100E54AEE /* CommentsExampleView.swift in Sources */,
5B0636DB2C2EA21900E54AEE /* Sequence+asyncMap.swift in Sources */,
13F1C0F2286ADD8900D25D8A /* MockAttachment.swift in Sources */,
135549342864620900C9459A /* ChatExampleApp.swift in Sources */,
13E17B6D2869E940004DF140 /* MockUser.swift in Sources */,
Expand Down
111 changes: 0 additions & 111 deletions Example/ChatExample/ChatExampleViewModel.swift

This file was deleted.

6 changes: 5 additions & 1 deletion Example/ChatExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ struct ContentView: View {
)
}

NavigationLink("Simple example") {
NavigationLink("Simple chat example") {
ChatExampleView(title: "Simple example")
}

NavigationLink("Simple comments example") {
CommentsExampleView()
}
} header: {
Text("Basic examples")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import Foundation
import UIKit
import ExyteChat
import ExyteMediaPicker

final class MockChatData {

Expand Down Expand Up @@ -100,5 +102,48 @@ class AssetExtractor {

return url
}
}

extension DraftMessage {
func makeMockImages() async -> [MockImage] {
await medias
.filter { $0.type == .image }
.asyncMap { (media : Media) -> (Media, URL?, URL?) in
(media, await media.getThumbnailURL(), await media.getURL())
}
.filter { (media: Media, thumb: URL?, full: URL?) -> Bool in
thumb != nil && full != nil
}
.map { media, thumb, full in
MockImage(id: media.id.uuidString, thumbnail: thumb!, full: full!)
}
}

func makeMockVideos() async -> [MockVideo] {
await medias
.filter { $0.type == .video }
.asyncMap { (media : Media) -> (Media, URL?, URL?) in
(media, await media.getThumbnailURL(), await media.getURL())
}
.filter { (media: Media, thumb: URL?, full: URL?) -> Bool in
thumb != nil && full != nil
}
.map { media, thumb, full in
MockVideo(id: media.id.uuidString, thumbnail: thumb!, full: full!)
}
}

func toMockMessage(user: MockUser, status: Message.Status = .read) async -> MockMessage {
MockMessage(
uid: id ?? UUID().uuidString,
sender: user,
createdAt: createdAt,
status: user.isCurrentUser ? status : nil,
text: text,
images: await makeMockImages(),
videos: await makeMockVideos(),
recording: recording,
replyMessage: replyMessage
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,18 @@ extension Date {
return Calendar.current.date(from: components)!
}
}

class DateFormatting {
static var agoFormatter = RelativeDateTimeFormatter()
}

extension Date {
// 1 hour ago, 2 days ago...
func formatAgo() -> String {
let result = DateFormatting.agoFormatter.localizedString(for: self, relativeTo: Date())
if result.contains("second") {
return "Just now"
}
return result
}
}
22 changes: 22 additions & 0 deletions Example/ChatExample/Extensions/Sequence+asyncMap.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Sequence+asyncMap.swift
// ChatExample
//
// Created by Alisa Mylnikova on 28.06.2024.
//

import Foundation

extension Sequence {
func asyncMap<T>(
_ transform: (Element) async throws -> T
) async rethrows -> [T] {
var values = [T]()

for element in self {
try await values.append(transform(element))
}

return values
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 47030b0

Please sign in to comment.