Skip to content

Commit 0a4ec8f

Browse files
initial implementation of the new chat view
1 parent b541645 commit 0a4ec8f

File tree

10 files changed

+557
-160
lines changed

10 files changed

+557
-160
lines changed

DemoAppSwiftUI/CustomChannelHeader.swift

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ import SwiftUI
77
import StreamChatSwiftUI
88

99
public struct CustomChannelHeader: ToolbarContent {
10-
10+
1111
@Injected(\.fonts) var fonts
1212
@Injected(\.images) var images
13-
13+
1414
public var title: String
15-
public var onTapLeading: () -> ()
1615

1716
public var body: some ToolbarContent {
1817
ToolbarItem(placement: .principal) {
@@ -21,37 +20,23 @@ public struct CustomChannelHeader: ToolbarContent {
2120
}
2221
ToolbarItem(placement: .navigationBarTrailing) {
2322
NavigationLink {
24-
Text("This is injected view")
23+
NewChatView()
2524
} label: {
2625
Image(uiImage: images.messageActionEdit)
2726
.resizable()
2827
}
2928
}
30-
ToolbarItem(placement: .navigationBarLeading) {
31-
Button {
32-
onTapLeading()
33-
} label: {
34-
Image(systemName: "line.3.horizontal")
35-
.resizable()
36-
}
37-
}
3829
}
30+
3931
}
4032

4133
struct CustomChannelModifier: ChannelListHeaderViewModifier {
4234

4335
var title: String
4436

45-
@State var profileShown = false
46-
4737
func body(content: Content) -> some View {
4838
content.toolbar {
49-
CustomChannelHeader(title: title) {
50-
profileShown = true
51-
}
52-
}
53-
.sheet(isPresented: $profileShown) {
54-
Text("Profile View")
39+
CustomChannelHeader(title: title)
5540
}
5641
}
5742

DemoAppSwiftUI/DemoAppSwiftUIApp.swift

Lines changed: 1 addition & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct DemoAppSwiftUIApp: App {
2121
// } else {
2222
// ChatChannelListView()
2323
// }
24-
ChatChannelListView()
24+
ChatChannelListView(viewFactory: DemoAppFactory.shared)
2525
/*
2626
//Example of custom query filters.
2727
ChatChannelListView(
@@ -48,134 +48,3 @@ struct DemoAppSwiftUIApp: App {
4848
return controller
4949
}
5050
}
51-
52-
struct CustomChannelDestination: View {
53-
54-
var channel: ChatChannel
55-
56-
var body: some View {
57-
VStack {
58-
Text("This is the channel \(channel.name ?? "")")
59-
}
60-
}
61-
62-
}
63-
64-
class CustomFactory: ViewFactory {
65-
66-
@Injected(\.chatClient) public var chatClient
67-
68-
private init() {}
69-
70-
public static let shared = CustomFactory()
71-
72-
func makeGiphyBadgeViewType(for message: ChatMessage, availableWidth: CGFloat) -> some View {
73-
EmptyView()
74-
}
75-
76-
func makeLoadingView() -> some View {
77-
VStack {
78-
Text("This is custom loading view")
79-
ProgressView()
80-
}
81-
}
82-
83-
func makeNoChannelsView() -> some View {
84-
VStack {
85-
Spacer()
86-
Text("This is our own custom no channels view.")
87-
Spacer()
88-
}
89-
}
90-
91-
func makeChannelListHeaderViewModifier(title: String) -> some ChannelListHeaderViewModifier {
92-
CustomChannelModifier(title: title)
93-
}
94-
95-
96-
// Example for an injected action. Uncomment to see it in action.
97-
func suppotedMoreChannelActions(
98-
for channel: ChatChannel,
99-
onDismiss: @escaping () -> Void,
100-
onError: @escaping (Error) -> Void
101-
) -> [ChannelAction] {
102-
var defaultActions = ChannelAction.defaultActions(
103-
for: channel,
104-
chatClient: chatClient,
105-
onDismiss: onDismiss,
106-
onError: onError
107-
)
108-
109-
let freeze = {
110-
let controller = self.chatClient.channelController(for: channel.cid)
111-
controller.freezeChannel { error in
112-
if let error = error {
113-
onError(error)
114-
} else {
115-
onDismiss()
116-
}
117-
}
118-
}
119-
120-
let confirmationPopup = ConfirmationPopup(
121-
title: "Freeze channel",
122-
message: "Are you sure you want to freeze this channel?",
123-
buttonTitle: "Freeze"
124-
)
125-
126-
let channelAction = ChannelAction(
127-
title: "Freeze channel",
128-
iconName: "person.crop.circle.badge.minus",
129-
action: freeze,
130-
confirmationPopup: confirmationPopup,
131-
isDestructive: false
132-
)
133-
134-
defaultActions.insert(channelAction, at: 0)
135-
return defaultActions
136-
}
137-
138-
func makeMoreChannelActionsView(
139-
for channel: ChatChannel,
140-
onDismiss: @escaping () -> Void,
141-
onError: @escaping (Error) -> Void) -> some View {
142-
VStack {
143-
Text("This is our custom view")
144-
Spacer()
145-
HStack {
146-
Button {
147-
onDismiss()
148-
} label: {
149-
Text("Action")
150-
}
151-
152-
}
153-
.padding()
154-
}
155-
}
156-
157-
func makeMessageTextView(
158-
for message: ChatMessage,
159-
isFirst: Bool,
160-
availableWidth: CGFloat
161-
) -> some View {
162-
CustomMessageTextView(
163-
message: message,
164-
isFirst: isFirst
165-
)
166-
}
167-
168-
func makeCustomAttachmentViewType(
169-
for message: ChatMessage,
170-
isFirst: Bool,
171-
availableWidth: CGFloat
172-
) -> some View {
173-
CustomAttachmentView(
174-
message: message,
175-
width: availableWidth,
176-
isFirst: isFirst
177-
)
178-
}
179-
180-
181-
}

0 commit comments

Comments
 (0)