Skip to content

Commit 683d4f8

Browse files
fixed linting issues in the demo app
1 parent d41e61c commit 683d4f8

11 files changed

+81
-113
lines changed

DemoAppSwiftUI/CreateGroupView.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//
2-
// Copyright © 2021 Stream.io Inc. All rights reserved.
2+
// Copyright © 2021 Stream.io Inc. All rights reserved.
33
//
44

5-
import SwiftUI
65
import StreamChat
76
import StreamChatSwiftUI
7+
import SwiftUI
88

99
struct CreateGroupView: View, KeyboardReadable {
1010

@@ -20,7 +20,7 @@ struct CreateGroupView: View, KeyboardReadable {
2020
var body: some View {
2121
VStack(spacing: 0) {
2222
SearchBar(text: $viewModel.searchText)
23-
.padding(.vertical, viewModel.selectedUsers.count > 0 ? 0 : 16)
23+
.padding(.vertical, !viewModel.selectedUsers.isEmpty ? 0 : 16)
2424

2525
ScrollView(.horizontal) {
2626
HStack(spacing: 16) {
@@ -31,7 +31,7 @@ struct CreateGroupView: View, KeyboardReadable {
3131
)
3232
}
3333
}
34-
.padding(.all, viewModel.selectedUsers.count > 0 ? 16 : 0)
34+
.padding(.all, !viewModel.selectedUsers.isEmpty ? 16 : 0)
3535
}
3636

3737
UsersHeaderView()
@@ -61,7 +61,7 @@ struct CreateGroupView: View, KeyboardReadable {
6161
Image(systemName: "arrow.forward")
6262
}
6363
.isDetailLink(false)
64-
.disabled(viewModel.selectedUsers.count == 0)
64+
.disabled(viewModel.selectedUsers.isEmpty)
6565
}
6666
})
6767
.navigationTitle("Add group members")
@@ -73,7 +73,6 @@ struct CreateGroupView: View, KeyboardReadable {
7373
}
7474
.modifier(HideKeyboardOnTapGesture(shouldAdd: keyboardShown))
7575
}
76-
7776
}
7877

7978
struct SelectedUserGroupView: View {
@@ -118,17 +117,16 @@ struct SelectedUserGroupView: View {
118117
)
119118
.frame(width: avatarSize)
120119
}
121-
122120
}
123121

124122
struct SearchBar: View {
125123

126124
@Injected(\.colors) var colors
127125

128126
@Binding var text: String
129-
127+
130128
@State private var isEditing = false
131-
129+
132130
var body: some View {
133131
HStack {
134132

DemoAppSwiftUI/CreateGroupViewModel.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
//
2-
// Copyright © 2021 Stream.io Inc. All rights reserved.
2+
// Copyright © 2021 Stream.io Inc. All rights reserved.
33
//
44

5-
import SwiftUI
65
import StreamChat
76
import StreamChatSwiftUI
7+
import SwiftUI
88

99
class CreateGroupViewModel: ObservableObject, ChatUserSearchControllerDelegate {
1010

1111
@Injected(\.chatClient) var chatClient
1212

1313
var channelController: ChatChannelController!
14-
14+
1515
@Published var searchText = "" {
1616
didSet {
1717
searchUsers(with: searchText)
1818
}
1919
}
20+
2021
@Published var state: NewChatState = .initial
2122
@Published var chatUsers = LazyCachedMapCollection<ChatUser>()
2223
@Published var selectedUsers = [ChatUser]()
@@ -35,7 +36,7 @@ class CreateGroupViewModel: ObservableObject, ChatUserSearchControllerDelegate {
3536
}
3637

3738
var canCreateGroup: Bool {
38-
selectedUsers.count > 0 && !groupName.isEmpty
39+
!selectedUsers.isEmpty && !groupName.isEmpty
3940
}
4041

4142
func userTapped(_ user: ChatUser) {
@@ -78,15 +79,15 @@ class CreateGroupViewModel: ObservableObject, ChatUserSearchControllerDelegate {
7879
self?.errorShown = true
7980
} else {
8081
self?.showGroupConversation = true
81-
}
82+
}
8283
}
8384

8485
} catch {
8586
errorShown = true
8687
}
8788
}
8889

89-
//MARK: - ChatUserSearchControllerDelegate
90+
// MARK: - ChatUserSearchControllerDelegate
9091

9192
func controller(
9293
_ controller: ChatUserSearchController,
@@ -95,10 +96,10 @@ class CreateGroupViewModel: ObservableObject, ChatUserSearchControllerDelegate {
9596
chatUsers = controller.users
9697
}
9798

98-
//MARK: - private
99+
// MARK: - private
99100

100101
private func searchUsers(with term: String?) {
101-
self.state = .loading
102+
state = .loading
102103
searchController.search(term: term) { [weak self] error in
103104
if error != nil {
104105
self?.state = .error
@@ -107,5 +108,4 @@ class CreateGroupViewModel: ObservableObject, ChatUserSearchControllerDelegate {
107108
}
108109
}
109110
}
110-
111111
}

DemoAppSwiftUI/CustomAttachment.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
//
2-
// Copyright © 2021 Stream.io Inc. All rights reserved.
2+
// Copyright © 2021 Stream.io Inc. All rights reserved.
33
//
44

5-
import SwiftUI
65
import StreamChat
76
import StreamChatSwiftUI
7+
import SwiftUI
88

99
class CustomMessageResolver: MessageTypeResolving {
1010

1111
func hasCustomAttachment(message: ChatMessage) -> Bool {
1212
let messageComponents = message.text.components(separatedBy: CharacterSet.whitespacesAndNewlines)
13-
return messageComponents.filter { component in
13+
return !messageComponents.filter { component in
1414
isValidEmail(component)
1515
}
16-
.count > 0
16+
.isEmpty
1717
}
1818

1919
private func isValidEmail(_ email: String) -> Bool {
2020
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"
21-
22-
let emailPred = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
21+
22+
let emailPred = NSPredicate(format: "SELF MATCHES %@", emailRegEx)
2323
return emailPred.evaluate(with: email)
2424
}
25-
2625
}
2726

2827
struct CustomAttachmentView: View {
@@ -40,7 +39,6 @@ struct CustomAttachmentView: View {
4039
.frame(maxWidth: width)
4140
.messageBubble(for: message, isFirst: isFirst)
4241
}
43-
4442
}
4543

4644
struct CustomMessageTextView: View {

DemoAppSwiftUI/CustomChannelHeader.swift

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
//
2-
// Created by Martin Mitrevski on 22.10.21.
3-
// Copyright © 2021 Stream.io Inc. All rights reserved.
2+
// Copyright © 2021 Stream.io Inc. All rights reserved.
43
//
54

6-
import SwiftUI
5+
import NukeUI
76
import StreamChat
87
import StreamChatSwiftUI
9-
import NukeUI
8+
import SwiftUI
109

1110
public struct CustomChannelHeader: ToolbarContent {
1211

@@ -29,7 +28,7 @@ public struct CustomChannelHeader: ToolbarContent {
2928
} label: {
3029
Image(uiImage: images.messageActionEdit)
3130
.resizable()
32-
}
31+
}
3332
}
3433
ToolbarItem(placement: .navigationBarLeading) {
3534
Button {
@@ -43,10 +42,8 @@ public struct CustomChannelHeader: ToolbarContent {
4342
height: 30
4443
)
4544
}
46-
4745
}
4846
}
49-
5047
}
5148

5249
struct CustomChannelModifier: ChannelListHeaderViewModifier {
@@ -68,13 +65,13 @@ struct CustomChannelModifier: ChannelListHeaderViewModifier {
6865
logoutAlertShown: $logoutAlertShown
6966
)
7067
}
71-
68+
7269
NavigationLink(isActive: $isNewChatShown) {
7370
NewChatView(isNewChatShown: $isNewChatShown)
7471
} label: {
7572
EmptyView()
7673
}
77-
.isDetailLink(false)
74+
.isDetailLink(false)
7875
.alert(isPresented: $logoutAlertShown) {
7976
Alert(
8077
title: Text("Sign out"),
@@ -84,10 +81,9 @@ struct CustomChannelModifier: ChannelListHeaderViewModifier {
8481
AppState.shared.userState = .notLoggedIn
8582
}
8683
},
87-
secondaryButton: .cancel())
84+
secondaryButton: .cancel()
85+
)
8886
}
8987
}
90-
9188
}
92-
9389
}

DemoAppSwiftUI/CustomComposerAttachmentView.swift

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
//
2-
// Copyright © 2021 Stream.io Inc. All rights reserved.
2+
// Copyright © 2021 Stream.io Inc. All rights reserved.
33
//
44

55
import Foundation
66
import StreamChat
7-
import SwiftUI
87
import StreamChatSwiftUI
8+
import SwiftUI
99

1010
extension AttachmentType {
1111
static let contact = Self(rawValue: "contact")
1212
}
1313

1414
struct ContactAttachmentPayload: AttachmentPayload {
1515
static let type: AttachmentType = .contact
16-
16+
1717
let name: String
1818
let phoneNumber: String
1919
}
@@ -23,7 +23,6 @@ extension ContactAttachmentPayload: Identifiable {
2323
var id: String {
2424
"\(name)-\(phoneNumber)"
2525
}
26-
2726
}
2827

2928
class CustomAttachmentsFactory: ViewFactory {
@@ -108,16 +107,14 @@ class CustomAttachmentsFactory: ViewFactory {
108107
onCustomAttachmentTap: onCustomAttachmentTap
109108
)
110109
}
111-
112110
}
113111

114112
class CustomMessageTypeResolver: MessageTypeResolving {
115113

116114
func hasCustomAttachment(message: ChatMessage) -> Bool {
117115
let contactAttachments = message.attachments(payloadType: ContactAttachmentPayload.self)
118-
return contactAttachments.count > 0
116+
return !contactAttachments.isEmpty
119117
}
120-
121118
}
122119

123120
struct CustomAttachmentSourcePickerView: View {
@@ -163,7 +160,6 @@ struct CustomAttachmentSourcePickerView: View {
163160
.frame(height: 56)
164161
.background(Color(colors.background1))
165162
}
166-
167163
}
168164

169165
struct CustomContactAttachmentView: View {
@@ -174,7 +170,7 @@ struct CustomContactAttachmentView: View {
174170
let contacts: [CustomAttachment]
175171
let addedContacts: [CustomAttachment]
176172
var onCustomAttachmentTap: (CustomAttachment) -> Void
177-
173+
178174
var body: some View {
179175
AttachmentTypeContainer {
180176
VStack(alignment: .leading) {
@@ -202,7 +198,6 @@ struct CustomContactAttachmentView: View {
202198
}
203199
}
204200
}
205-
206201
}
207202

208203
struct CustomContactAttachmentComposerPreview: View {
@@ -239,7 +234,6 @@ struct CustomContactAttachmentComposerPreview: View {
239234
}
240235
}
241236
}
242-
243237
}
244238

245239
struct CustomContactAttachmentPreview: View {
@@ -252,7 +246,7 @@ struct CustomContactAttachmentPreview: View {
252246
var onCustomAttachmentTap: (CustomAttachment) -> Void
253247
var isAttachmentSelected: Bool
254248
var hasSpacing = true
255-
249+
256250
var body: some View {
257251
Button {
258252
withAnimation {
@@ -283,8 +277,6 @@ struct CustomContactAttachmentPreview: View {
283277
.foregroundColor(Color(colors.textLowEmphasis))
284278
}
285279
}
286-
287280
}
288281
}
289-
290282
}

DemoAppSwiftUI/DemoUser.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extension UserCredentials: Identifiable {
2121
static func builtInUsersByID(id: String) -> UserCredentials? {
2222
builtInUsers.filter { $0.id == id }.first
2323
}
24-
24+
2525
static let builtInUsers: [UserCredentials] = [
2626
(
2727
"luke_skywalker",
@@ -135,7 +135,7 @@ extension UserCredentials: Identifiable {
135135
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiZ2VuZXJhbF9ncmlldm91cyJ9.FPRvRoeZdALErBA1bDybch4xY-c5CEinuc9qqEPzX4E",
136136
"Qymaen jai Sheelal"
137137
)
138-
138+
139139
].map {
140140
UserCredentials(id: $0.0, name: $0.1, avatarURL: URL(string: $0.2)!, token: $0.3, birthLand: $0.4)
141141
}

0 commit comments

Comments
 (0)