Skip to content

Commit e4439da

Browse files
Update factory methods to options params (#977)
1 parent 71ec4e8 commit e4439da

File tree

153 files changed

+4989
-1214
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+4989
-1214
lines changed

.swiftformat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,4 @@
8181
--wrapcollections before-first
8282

8383
# Exclude paths
84-
--exclude Sources/StreamChatSwiftUI/Generated,Sources/StreamChatSwiftUI/StreamSwiftyGif,Sources/StreamChatSwiftUI/StreamNuke
84+
--exclude Sources/StreamChatSwiftUI/Generated,Sources/StreamChatSwiftUI/StreamSwiftyGif,Sources/StreamChatSwiftUI/StreamNuke,StreamChatSwiftUITests/Tests

.swiftlint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ only_rules:
4343
- trailing_comma
4444
- trailing_newline
4545
- trailing_semicolon
46+
- trailing_whitespace
4647
- unneeded_break_in_switch
4748
- unneeded_override
4849
- unused_closure_parameter

DemoAppSwiftUI/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class AppDelegate: NSObject, UIApplicationDelegate {
127127
}
128128

129129
chatClient.currentUserController().addDevice(.apn(token: deviceToken)) { error in
130-
if let error = error {
130+
if let error {
131131
log.error("adding a device failed with an error \(error)")
132132
return
133133
}

DemoAppSwiftUI/AppleMessageComposerView.swift

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,23 @@ struct AppleMessageComposerView<Factory: ViewFactory>: View, KeyboardReadable {
100100
.padding(.all, 8)
101101

102102
factory.makeAttachmentPickerView(
103-
attachmentPickerState: $viewModel.pickerState,
104-
filePickerShown: $viewModel.filePickerShown,
105-
cameraPickerShown: $viewModel.cameraPickerShown,
106-
addedFileURLs: $viewModel.addedFileURLs,
107-
onPickerStateChange: viewModel.change(pickerState:),
108-
photoLibraryAssets: viewModel.imageAssets,
109-
onAssetTap: viewModel.imageTapped(_:),
110-
onCustomAttachmentTap: viewModel.customAttachmentTapped(_:),
111-
isAssetSelected: viewModel.isImageSelected(with:),
112-
addedCustomAttachments: viewModel.addedCustomAttachments,
113-
cameraImageAdded: viewModel.cameraImageAdded(_:),
114-
askForAssetsAccessPermissions: viewModel.askForPhotosPermission,
115-
isDisplayed: viewModel.overlayShown,
116-
height: viewModel.overlayShown ? popupSize : 0,
117-
popupHeight: popupSize
103+
options: AttachmentPickerViewOptions(
104+
attachmentPickerState: $viewModel.pickerState,
105+
filePickerShown: $viewModel.filePickerShown,
106+
cameraPickerShown: $viewModel.cameraPickerShown,
107+
addedFileURLs: $viewModel.addedFileURLs,
108+
onPickerStateChange: viewModel.change(pickerState:),
109+
photoLibraryAssets: viewModel.imageAssets,
110+
onAssetTap: viewModel.imageTapped(_:),
111+
onCustomAttachmentTap: viewModel.customAttachmentTapped(_:),
112+
isAssetSelected: viewModel.isImageSelected(with:),
113+
addedCustomAttachments: viewModel.addedCustomAttachments,
114+
cameraImageAdded: viewModel.cameraImageAdded(_:),
115+
askForAssetsAccessPermissions: viewModel.askForPhotosPermission,
116+
isDisplayed: viewModel.overlayShown,
117+
height: viewModel.overlayShown ? popupSize : 0,
118+
popupHeight: popupSize
119+
)
118120
)
119121
}
120122
.background(
@@ -126,8 +128,8 @@ struct AppleMessageComposerView<Factory: ViewFactory>: View, KeyboardReadable {
126128
)
127129
.onPreferenceChange(HeightPreferenceKey.self) { value in
128130
Task { @MainActor in
129-
if let value = value, value != composerHeight {
130-
self.composerHeight = value
131+
if let value, value != composerHeight {
132+
composerHeight = value
131133
}
132134
}
133135
}
@@ -144,27 +146,29 @@ struct AppleMessageComposerView<Factory: ViewFactory>: View, KeyboardReadable {
144146
}
145147
.onReceive(keyboardHeight) { height in
146148
if height > 0 && height != popupSize {
147-
self.popupSize = height - bottomSafeArea
149+
popupSize = height - bottomSafeArea
148150
}
149151
}
150152
.overlay(
151153
viewModel.showCommandsOverlay ?
152154
factory.makeCommandsContainerView(
153-
suggestions: viewModel.suggestions,
154-
handleCommand: { commandInfo in
155-
viewModel.handleCommand(
156-
for: $viewModel.text,
157-
selectedRangeLocation: $viewModel.selectedRangeLocation,
158-
command: $viewModel.composerCommand,
159-
extraData: commandInfo
160-
)
161-
}
155+
options: CommandsContainerViewOptions(
156+
suggestions: viewModel.suggestions,
157+
handleCommand: { commandInfo in
158+
viewModel.handleCommand(
159+
for: $viewModel.text,
160+
selectedRangeLocation: $viewModel.selectedRangeLocation,
161+
command: $viewModel.composerCommand,
162+
extraData: commandInfo
163+
)
164+
}
165+
)
162166
)
163167
.offset(y: -composerHeight)
164168
.animation(.none, value: viewModel.showCommandsOverlay) : nil,
165169
alignment: .bottom
166170
)
167-
.modifier(factory.makeComposerViewModifier())
171+
.modifier(factory.makeComposerViewModifier(options: ComposerViewModifierOptions()))
168172
.onChange(of: editedMessage) { _ in
169173
viewModel.text = editedMessage?.text ?? ""
170174
if editedMessage != nil {

DemoAppSwiftUI/ChannelHeader/NewChatViewModel.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ import SwiftUI
7171

7272
func onlineInfo(for user: ChatUser) -> String {
7373
if user.isOnline {
74-
return "Online"
74+
"Online"
7575
} else if let lastActiveAt = user.lastActiveAt,
7676
let timeAgo = lastSeenDateFormatter(lastActiveAt) {
77-
return timeAgo
77+
timeAgo
7878
} else {
79-
return "Offline"
79+
"Offline"
8080
}
8181
}
8282

DemoAppSwiftUI/CreateGroupView.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ struct SearchBar: View {
140140

141141
if isEditing {
142142
Button(action: {
143-
self.text = ""
143+
text = ""
144144

145145
}) {
146146
Image(systemName: "multiply.circle.fill")
@@ -152,13 +152,13 @@ struct SearchBar: View {
152152
)
153153
.padding(.horizontal, 10)
154154
.onTapGesture {
155-
self.isEditing = true
155+
isEditing = true
156156
}
157157

158158
if isEditing {
159159
Button(action: {
160-
self.isEditing = false
161-
self.text = ""
160+
isEditing = false
161+
text = ""
162162

163163
// Dismiss the keyboard
164164
UIApplication.shared.sendAction(

DemoAppSwiftUI/CreateGroupViewModel.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ import SwiftUI
5050

5151
func onlineInfo(for user: ChatUser) -> String {
5252
if user.isOnline {
53-
return "Online"
53+
"Online"
5454
} else if let lastActiveAt = user.lastActiveAt,
5555
let timeAgo = lastSeenDateFormatter(lastActiveAt) {
56-
return timeAgo
56+
timeAgo
5757
} else {
58-
return "Offline"
58+
"Offline"
5959
}
6060
}
6161

DemoAppSwiftUI/LoginViewModel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import SwiftUI
3636
),
3737
token: token
3838
) { [weak self] error in
39-
if let error = error {
39+
if let error {
4040
log.error("connecting the user failed \(error)")
4141
return
4242
}
@@ -55,7 +55,7 @@ import SwiftUI
5555
chatClient.connectGuestUser(
5656
userInfo: .init(id: credentials.id, name: credentials.name)
5757
) { [weak self] error in
58-
if let error = error {
58+
if let error {
5959
log.error("connecting the user failed \(error)")
6060
return
6161
}

DemoAppSwiftUI/PinChannelHelpers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct DemoAppChatChannelListItem: View {
7575

7676
private var subtitleView: some View {
7777
HStack(spacing: 4) {
78-
if let image = image {
78+
if let image {
7979
Image(uiImage: image)
8080
.customizable()
8181
.frame(maxHeight: 12)

DemoAppSwiftUI/ViewFactoryExamples.swift

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ class DemoAppFactory: ViewFactory {
1515

1616
public static let shared = DemoAppFactory()
1717

18-
func makeChannelListHeaderViewModifier(title: String) -> some ChannelListHeaderViewModifier {
19-
CustomChannelModifier(title: title)
18+
func makeChannelListHeaderViewModifier(options: ChannelListHeaderViewModifierOptions) -> some ChannelListHeaderViewModifier {
19+
CustomChannelModifier(title: options.title)
2020
}
2121

2222
func supportedMoreChannelActions(
23-
for channel: ChatChannel,
24-
onDismiss: @escaping @MainActor () -> Void,
25-
onError: @escaping @MainActor (Error) -> Void
23+
options: SupportedMoreChannelActionsOptions
2624
) -> [ChannelAction] {
25+
let channel = options.channel
26+
let onDismiss = options.onDismiss
27+
let onError = options.onError
28+
2729
var actions = ChannelAction.defaultActions(
2830
for: channel,
2931
chatClient: chatClient,
@@ -42,19 +44,20 @@ class DemoAppFactory: ViewFactory {
4244
}
4345

4446
func makeChannelListItem(
45-
channel: ChatChannel,
46-
channelName: String,
47-
avatar: UIImage,
48-
onlineIndicatorShown: Bool,
49-
disabled: Bool,
50-
selectedChannel: Binding<ChannelSelectionInfo?>,
51-
swipedChannelId: Binding<String?>,
52-
channelDestination: @escaping @MainActor (ChannelSelectionInfo) -> ChatChannelView<DemoAppFactory>,
53-
onItemTap: @escaping @MainActor (ChatChannel) -> Void,
54-
trailingSwipeRightButtonTapped: @escaping @MainActor (ChatChannel) -> Void,
55-
trailingSwipeLeftButtonTapped: @escaping @MainActor (ChatChannel) -> Void,
56-
leadingSwipeButtonTapped: @escaping @MainActor (ChatChannel) -> Void
47+
options: ChannelListItemOptions<ChannelDestination>
5748
) -> some View {
49+
let channel = options.channel
50+
let channelName = options.channelName
51+
let avatar = options.avatar
52+
let onlineIndicatorShown = options.onlineIndicatorShown
53+
let disabled = options.disabled
54+
let selectedChannel = options.selectedChannel
55+
let swipedChannelId = options.swipedChannelId
56+
let channelDestination = options.channelDestination
57+
let onItemTap = options.onItemTap
58+
let trailingSwipeRightButtonTapped = options.trailingSwipeRightButtonTapped
59+
let trailingSwipeLeftButtonTapped = options.trailingSwipeLeftButtonTapped
60+
let leadingSwipeButtonTapped = options.leadingSwipeButtonTapped
5861
let listItem = DemoAppChatChannelNavigatableListItem(
5962
channel: channel,
6063
channelName: channelName,
@@ -231,35 +234,37 @@ class CustomFactory: ViewFactory {
231234

232235
public static let shared = CustomFactory()
233236

234-
func makeGiphyBadgeViewType(for message: ChatMessage, availableWidth: CGFloat) -> some View {
237+
func makeGiphyBadgeViewType(options: GiphyBadgeViewTypeOptions) -> some View {
235238
EmptyView()
236239
}
237240

238-
func makeLoadingView() -> some View {
241+
func makeLoadingView(options: LoadingViewOptions) -> some View {
239242
VStack {
240243
Text("This is custom loading view")
241244
ProgressView()
242245
}
243246
}
244247

245-
func makeNoChannelsView() -> some View {
248+
func makeNoChannelsView(options: NoChannelsViewOptions) -> some View {
246249
VStack {
247250
Spacer()
248251
Text("This is our own custom no channels view.")
249252
Spacer()
250253
}
251254
}
252255

253-
func makeChannelListHeaderViewModifier(title: String) -> some ChannelListHeaderViewModifier {
254-
CustomChannelModifier(title: title)
256+
func makeChannelListHeaderViewModifier(options: ChannelListHeaderViewModifierOptions) -> some ChannelListHeaderViewModifier {
257+
CustomChannelModifier(title: options.title)
255258
}
256259

257260
// Example for an injected action. Uncomment to see it in action.
258261
func supportedMoreChannelActions(
259-
for channel: ChatChannel,
260-
onDismiss: @escaping @MainActor () -> Void,
261-
onError: @escaping @MainActor (Error) -> Void
262+
options: SupportedMoreChannelActionsOptions
262263
) -> [ChannelAction] {
264+
let channel = options.channel
265+
let onDismiss = options.onDismiss
266+
let onError = options.onError
267+
263268
var defaultActions = ChannelAction.defaultActions(
264269
for: channel,
265270
chatClient: chatClient,
@@ -296,16 +301,14 @@ class CustomFactory: ViewFactory {
296301
}
297302

298303
func makeMoreChannelActionsView(
299-
for channel: ChatChannel,
300-
onDismiss: @escaping @MainActor () -> Void,
301-
onError: @escaping @MainActor (Error) -> Void
304+
options: MoreChannelActionsViewOptions
302305
) -> some View {
303306
VStack {
304307
Text("This is our custom view")
305308
Spacer()
306309
HStack {
307310
Button {
308-
onDismiss()
311+
options.onDismiss()
309312
} label: {
310313
Text("Action")
311314
}
@@ -315,22 +318,23 @@ class CustomFactory: ViewFactory {
315318
}
316319

317320
func makeMessageTextView(
318-
for message: ChatMessage,
319-
isFirst: Bool,
320-
availableWidth: CGFloat
321+
options: MessageTextViewOptions
321322
) -> some View {
322-
CustomMessageTextView(
323+
let message = options.message
324+
let isFirst = options.isFirst
325+
return CustomMessageTextView(
323326
message: message,
324327
isFirst: isFirst
325328
)
326329
}
327330

328331
func makeCustomAttachmentViewType(
329-
for message: ChatMessage,
330-
isFirst: Bool,
331-
availableWidth: CGFloat
332+
options: CustomAttachmentViewTypeOptions
332333
) -> some View {
333-
CustomAttachmentView(
334+
let message = options.message
335+
let isFirst = options.isFirst
336+
let availableWidth = options.availableWidth
337+
return CustomAttachmentView(
334338
message: message,
335339
width: availableWidth,
336340
isFirst: isFirst

0 commit comments

Comments
 (0)