@@ -6,44 +6,47 @@ import StreamChat
6
6
import SwiftUI
7
7
8
8
/// View for the add users popup.
9
- struct AddUsersView : View {
9
+ struct AddUsersView < Factory : ViewFactory > : View {
10
10
11
11
@Injected ( \. fonts) private var fonts
12
12
@Injected ( \. colors) private var colors
13
13
14
- private static let columnCount = 4
15
- private static let itemSize : CGFloat = 64
16
-
17
14
private let columns = Array (
18
15
repeating:
19
16
GridItem (
20
- . adaptive( minimum: itemSize ) ,
17
+ . adaptive( minimum: 64 ) ,
21
18
alignment: . top
22
19
) ,
23
- count: columnCount
20
+ count: 4
24
21
)
22
+
23
+ private let factory : Factory
25
24
26
25
@StateObject private var viewModel : AddUsersViewModel
27
26
var onUserTap : ( ChatUser ) -> Void
28
27
29
28
init (
29
+ factory: Factory = DefaultViewFactory . shared,
30
30
loadedUserIds: [ String ] ,
31
31
onUserTap: @escaping ( ChatUser ) -> Void
32
32
) {
33
33
_viewModel = StateObject (
34
34
wrappedValue: AddUsersViewModel ( loadedUserIds: loadedUserIds)
35
35
)
36
36
self . onUserTap = onUserTap
37
+ self . factory = factory
37
38
}
38
39
39
40
init (
41
+ factory: Factory = DefaultViewFactory . shared,
40
42
viewModel: AddUsersViewModel ,
41
43
onUserTap: @escaping ( ChatUser ) -> Void
42
44
) {
43
45
_viewModel = StateObject (
44
46
wrappedValue: viewModel
45
47
)
46
48
self . onUserTap = onUserTap
49
+ self . factory = factory
47
50
}
48
51
49
52
var body : some View {
@@ -57,17 +60,20 @@ struct AddUsersView: View {
57
60
onUserTap ( user)
58
61
} label: {
59
62
VStack {
60
- MessageAvatarView (
61
- avatarURL: user. imageURL,
62
- size: CGSize ( width: Self . itemSize, height: Self . itemSize) ,
63
- showOnlineIndicator: false
63
+ let itemSize : CGFloat = 64
64
+ let userDisplayInfo = UserDisplayInfo (
65
+ id: user. id,
66
+ name: user. name ?? " " ,
67
+ imageURL: user. imageURL,
68
+ size: CGSize ( width: itemSize, height: itemSize)
64
69
)
70
+ factory. makeMessageAvatarView ( for: userDisplayInfo)
65
71
66
72
Text ( user. name ?? user. id)
67
73
. multilineTextAlignment ( . center)
68
74
. lineLimit ( 2 )
69
75
. font ( fonts. footnoteBold)
70
- . frame ( width: Self . itemSize)
76
+ . frame ( width: itemSize)
71
77
. foregroundColor ( Color ( colors. text) )
72
78
}
73
79
. padding ( . all, 8 )
0 commit comments