Skip to content

Commit 274c9fc

Browse files
[SWUI-82] Check if all icons in the SDK are configurable (#3)
* Remove iOS 13 version checks as its the minimum supported version * Streamlined images to be using those from Images.swift * Align UI with changes to Image refactoring * Create custom modifier for common customizable image * Revert change to remove padding as it introduced regressions. * Rename custom Image modifier * Implemented image customiyation for AttachmentPickerView * Updated Snapshot tests * Fix missing Spacer in AttachmentPickerView * updated snapshot tests Co-authored-by: martinmitrevski <[email protected]>
1 parent 0ab1865 commit 274c9fc

26 files changed

+104
-88
lines changed

DemoAppSwiftUI/CustomComposerAttachmentView.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,35 +120,36 @@ class CustomMessageTypeResolver: MessageTypeResolving {
120120
struct CustomAttachmentSourcePickerView: View {
121121

122122
@Injected(\.colors) var colors
123+
@Injected(\.images) var images
123124

124125
var selected: AttachmentPickerState
125126
var onTap: (AttachmentPickerState) -> Void
126127

127128
var body: some View {
128129
HStack(alignment: .center, spacing: 24) {
129130
AttachmentPickerButton(
130-
iconName: "photo",
131+
icon: images.attachmentPickerPhotos,
131132
pickerType: .photos,
132133
isSelected: selected == .photos,
133134
onTap: onTap
134135
)
135136

136137
AttachmentPickerButton(
137-
iconName: "folder",
138+
icon: images.attachmentPickerFolder,
138139
pickerType: .files,
139140
isSelected: selected == .files,
140141
onTap: onTap
141142
)
142143

143144
AttachmentPickerButton(
144-
iconName: "camera",
145+
icon: images.attachmentPickerCamera,
145146
pickerType: .camera,
146147
isSelected: selected == .camera,
147148
onTap: onTap
148149
)
149150

150151
AttachmentPickerButton(
151-
iconName: "person.crop.circle",
152+
icon: UIImage(systemName: "person.crop.circle")!,
152153
pickerType: .custom,
153154
isSelected: selected == .custom,
154155
onTap: onTap

Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
1212

1313
@Injected(\.chatClient) private var chatClient
1414
@Injected(\.utils) private var utils
15+
@Injected(\.images) private var images
1516

1617
private var channelDataSource: ChannelDataSource
1718
private var cancellables = Set<AnyCancellable>()
@@ -181,7 +182,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
181182

182183
public func showReactionOverlay() {
183184
guard let view: UIView = topVC()?.view else {
184-
currentSnapshot = UIImage(systemName: "photo")
185+
currentSnapshot = images.snapshot
185186
return
186187
}
187188
UIGraphicsBeginImageContext(view.frame.size)

Sources/StreamChatSwiftUI/ChatChannel/Composer/AttachmentPickerView.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,28 +78,30 @@ public struct AttachmentPickerView<Factory: ViewFactory>: View {
7878
/// View for picking the source of the attachment (photo, files or camera).
7979
struct AttachmentSourcePickerView: View {
8080
@Injected(\.colors) private var colors
81+
@Injected(\.images) private var images
8182

8283
var selected: AttachmentPickerState
8384
var onTap: (AttachmentPickerState) -> Void
8485

8586
var body: some View {
87+
8688
HStack(alignment: .center, spacing: 24) {
8789
AttachmentPickerButton(
88-
iconName: "photo",
90+
icon: images.attachmentPickerPhotos,
8991
pickerType: .photos,
9092
isSelected: selected == .photos,
9193
onTap: onTap
9294
)
9395

9496
AttachmentPickerButton(
95-
iconName: "folder",
97+
icon: images.attachmentPickerFolder,
9698
pickerType: .files,
9799
isSelected: selected == .files,
98100
onTap: onTap
99101
)
100102

101103
AttachmentPickerButton(
102-
iconName: "camera",
104+
icon: images.attachmentPickerCamera,
103105
pickerType: .camera,
104106
isSelected: selected == .camera,
105107
onTap: onTap
@@ -117,18 +119,18 @@ struct AttachmentSourcePickerView: View {
117119
public struct AttachmentPickerButton: View {
118120
@Injected(\.colors) private var colors
119121

120-
var iconName: String
122+
var icon: UIImage
121123
var pickerType: AttachmentPickerState
122124
var isSelected: Bool
123125
var onTap: (AttachmentPickerState) -> Void
124126

125127
public init(
126-
iconName: String,
128+
icon: UIImage,
127129
pickerType: AttachmentPickerState,
128130
isSelected: Bool,
129131
onTap: @escaping (AttachmentPickerState) -> Void
130132
) {
131-
self.iconName = iconName
133+
self.icon = icon
132134
self.pickerType = pickerType
133135
self.isSelected = isSelected
134136
self.onTap = onTap
@@ -138,7 +140,9 @@ public struct AttachmentPickerButton: View {
138140
Button {
139141
onTap(pickerType)
140142
} label: {
141-
Image(systemName: iconName)
143+
Image(uiImage: icon)
144+
.customizable()
145+
.frame(width: 22)
142146
.foregroundColor(
143147
isSelected ? Color(colors.highlightedAccentBackground)
144148
: Color(colors.textLowEmphasis)

Sources/StreamChatSwiftUI/ChatChannel/Composer/ComposerHelperViews.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ import SwiftUI
77

88
/// View used to indicate that an asset is a video.
99
struct VideoIndicatorView: View {
10+
11+
@Injected(\.images) private var images
12+
1013
var body: some View {
1114
BottomLeftView {
12-
Image(systemName: "video.fill")
13-
.renderingMode(.template)
14-
.font(.system(size: 17, weight: .bold))
15+
Image(uiImage: images.videoIndicator)
16+
.customizable()
17+
.frame(width: 22)
18+
.padding(2)
1519
.applyDefaultIconOverlayStyle()
1620
}
1721
}

Sources/StreamChatSwiftUI/ChatChannel/Composer/PhotoAttachmentPickerView.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ public struct PhotoAttachmentCell: View {
7979
.aspectRatio(1, contentMode: .fill)
8080

8181
Image(uiImage: images.imagePlaceholder)
82-
.renderingMode(.template)
83-
.resizable()
84-
.aspectRatio(contentMode: .fit)
82+
.customizable()
8583
.frame(height: 56)
8684
.foregroundColor(Color(colors.background2))
8785
}
@@ -91,8 +89,9 @@ public struct PhotoAttachmentCell: View {
9189
ZStack {
9290
if imageSelected(asset.localIdentifier) {
9391
TopRightView {
94-
Image(systemName: "checkmark.circle.fill")
92+
Image(uiImage: images.checkmarkFilled)
9593
.renderingMode(.template)
94+
.scaledToFit()
9695
.applyDefaultIconOverlayStyle()
9796
}
9897
}

Sources/StreamChatSwiftUI/ChatChannel/Gallery/GalleryView.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ struct GalleryView: View {
1010

1111
@Injected(\.colors) private var colors
1212
@Injected(\.fonts) private var fonts
13+
@Injected(\.images) private var images
1314

1415
var message: ChatMessage
1516
@Binding var isShown: Bool
@@ -72,11 +73,14 @@ struct GalleryView: View {
7273
.font(fonts.bodyBold)
7374

7475
Spacer()
75-
76+
7677
Button {
7778
gridShown = true
7879
} label: {
79-
Image(systemName: "square.grid.3x3.fill")
80+
Image(uiImage: images.gallery)
81+
.renderingMode(.template)
82+
.resizable()
83+
.frame(width: 16, height: 16, alignment: .center)
8084
}
8185
.standardPadding()
8286
}

Sources/StreamChatSwiftUI/ChatChannel/Gallery/ShareButtonView.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import SwiftUI
88
struct ShareButtonView: View {
99
@Injected(\.colors) var colors
1010
@Injected(\.fonts) var fonts
11+
@Injected(\.images) var images
1112

1213
var content: [Any]
1314
@State var isSharePresented = false
@@ -16,8 +17,9 @@ struct ShareButtonView: View {
1617
Button(action: {
1718
self.isSharePresented = true
1819
}, label: {
19-
Image(systemName: "square.and.arrow.up")
20-
.font(fonts.bodyBold)
20+
Image(uiImage: images.share)
21+
.customizable()
22+
.frame(width: 18, height: 22)
2123
})
2224
.foregroundColor(Color(colors.text))
2325
.sheet(isPresented: $isSharePresented) {

Sources/StreamChatSwiftUI/ChatChannel/MessageList/DeletedMessageView.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import SwiftUI
77

88
/// View displayed when a message is deleted.
99
public struct DeletedMessageView: View {
10+
@Injected(\.images) private var images
1011
@Injected(\.fonts) private var fonts
1112
@Injected(\.colors) private var colors
1213
@Injected(\.utils) private var utils
@@ -28,14 +29,17 @@ public struct DeletedMessageView: View {
2829
.standardPadding()
2930
.foregroundColor(Color(colors.textLowEmphasis))
3031
.messageBubble(for: message, isFirst: isFirst)
32+
3133
HStack {
3234
Spacer()
33-
Image(systemName: "eye")
34-
.resizable()
35-
.aspectRatio(contentMode: .fit)
35+
36+
Image(uiImage: images.eye)
37+
.customizable()
3638
.frame(maxWidth: 12)
39+
3740
Text(L10n.Message.onlyVisibleToYou)
3841
.font(fonts.footnote)
42+
3943
Text(dateFormatter.string(from: message.createdAt))
4044
.font(fonts.footnote)
4145
}

Sources/StreamChatSwiftUI/ChatChannel/MessageList/FileAttachmentPreview.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public struct FileAttachmentPreview: View {
99
@Environment(\.presentationMode) var presentationMode
1010

1111
@Injected(\.fonts) private var fonts
12+
@Injected(\.images) private var images
1213

1314
var url: URL
1415

@@ -48,7 +49,7 @@ public struct FileAttachmentPreview: View {
4849
Button {
4950
presentationMode.wrappedValue.dismiss()
5051
} label: {
51-
Image(systemName: "xmark")
52+
Image(uiImage: images.close)
5253
}
5354
}
5455
}

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageAvatarView.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import StreamChat
77
import SwiftUI
88

99
public struct MessageAvatarView: View {
10+
1011
@Injected(\.utils) private var utils
1112
@Injected(\.colors) private var colors
13+
@Injected(\.images) private var images
1214

1315
private var imageCDN: ImageCDN {
1416
utils.imageCDN
@@ -52,7 +54,7 @@ public struct MessageAvatarView: View {
5254
: nil
5355
)
5456
} else {
55-
Image(systemName: "person.circle")
57+
Image(uiImage: images.personPlaceholder)
5658
.renderingMode(.template)
5759
.resizable()
5860
.foregroundColor(Color(colors.textLowEmphasis))

0 commit comments

Comments
 (0)