forked from GetStream/stream-chat-swiftui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomChannelHeader.swift
95 lines (84 loc) · 2.93 KB
/
CustomChannelHeader.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// Copyright © 2024 Stream.io Inc. All rights reserved.
//
import StreamChat
import StreamChatSwiftUI
import SwiftUI
public struct CustomChannelHeader: ToolbarContent {
@Injected(\.fonts) var fonts
@Injected(\.images) var images
@Injected(\.colors) var colors
var title: String
var currentUserController: CurrentChatUserController
@Binding var isNewChatShown: Bool
@Binding var logoutAlertShown: Bool
@MainActor
public var body: some ToolbarContent {
ToolbarItem(placement: .principal) {
Text(title)
.font(fonts.bodyBold)
}
ToolbarItem(placement: .navigationBarTrailing) {
Button {
isNewChatShown = true
notifyHideTabBar()
} label: {
Image(uiImage: images.messageActionEdit)
.resizable()
.scaledToFit()
.foregroundColor(Color.white)
.padding(.all, 8)
.background(colors.tintColor)
.clipShape(Circle())
}
}
ToolbarItem(placement: .navigationBarLeading) {
Button {
logoutAlertShown = true
} label: {
StreamLazyImage(url: currentUserController.currentUser?.imageURL)
}
}
}
}
struct CustomChannelModifier: ChannelListHeaderViewModifier {
@Injected(\.chatClient) var chatClient
var title: String
@State var isNewChatShown = false
@State var logoutAlertShown = false
func body(content: Content) -> some View {
ZStack {
content.toolbar {
CustomChannelHeader(
title: title,
currentUserController: chatClient.currentUserController(),
isNewChatShown: $isNewChatShown,
logoutAlertShown: $logoutAlertShown
)
}
NavigationLink(isActive: $isNewChatShown) {
NewChatView(isNewChatShown: $isNewChatShown)
} label: {
EmptyView()
}
.isDetailLink(UIDevice.current.userInterfaceIdiom == .pad)
.alert(isPresented: $logoutAlertShown) {
Alert(
title: Text("Sign out"),
message: Text("Are you sure you want to sign out?"),
primaryButton: .destructive(Text("Sign out")) {
withAnimation {
chatClient.disconnect {
UnsecureRepository.shared.removeCurrentUser()
DispatchQueue.main.async {
AppState.shared.userState = .notLoggedIn
}
}
}
},
secondaryButton: .cancel()
)
}
}
}
}