Skip to content

Commit

Permalink
Introduce disabled state for file upload list
Browse files Browse the repository at this point in the history
Since message entry can have disabled state, file upload list, which is a part of message entry, also needs to have disabled state. These changes introduce such state. Styles use same colors for disabled state as for enabled for now, because we do not have a flow for disabled file upload.

MOB-3763
  • Loading branch information
igorkravchenko authored and Egor Egorov committed Nov 11, 2024
1 parent 30ccfef commit 1ea3ecf
Show file tree
Hide file tree
Showing 19 changed files with 484 additions and 234 deletions.
16 changes: 8 additions & 8 deletions GliaWidgets.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -844,8 +844,8 @@
C09047442B7E2016003C437C /* FileUploadStyle.Mock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C09047432B7E2016003C437C /* FileUploadStyle.Mock.swift */; };
C09047462B7E2064003C437C /* FileUploadErrorStateStyle.Mock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C09047452B7E2064003C437C /* FileUploadErrorStateStyle.Mock.swift */; };
C09047482B7E20B0003C437C /* FileUploadStateStyle.Mock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C09047472B7E20B0003C437C /* FileUploadStateStyle.Mock.swift */; };
C090474A2B7E20E0003C437C /* MessageCenterFileUploadStyle.Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C09047492B7E20E0003C437C /* MessageCenterFileUploadStyle.Equatable.swift */; };
C090474C2B7E210C003C437C /* FileUploadStyle.Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C090474B2B7E210C003C437C /* FileUploadStyle.Equatable.swift */; };
C090474A2B7E20E0003C437C /* MessageCenterFileUploadStyle.EnabledDisabledState.Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C09047492B7E20E0003C437C /* MessageCenterFileUploadStyle.EnabledDisabledState.Equatable.swift */; };
C090474C2B7E210C003C437C /* FileUploadStyle.EnabledDisabledState.Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C090474B2B7E210C003C437C /* FileUploadStyle.EnabledDisabledState.Equatable.swift */; };
C090474E2B7E2138003C437C /* FileUploadErrorStateStyle.Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C090474D2B7E2138003C437C /* FileUploadErrorStateStyle.Equatable.swift */; };
C09047502B7E215E003C437C /* FileUploadStateStyle.Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C090474F2B7E215E003C437C /* FileUploadStateStyle.Equatable.swift */; };
C09047522B7E21A2003C437C /* MessageCenterFileUploadListStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = C09047512B7E21A2003C437C /* MessageCenterFileUploadListStyle.swift */; };
Expand Down Expand Up @@ -1911,8 +1911,8 @@
C09047432B7E2016003C437C /* FileUploadStyle.Mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileUploadStyle.Mock.swift; sourceTree = "<group>"; };
C09047452B7E2064003C437C /* FileUploadErrorStateStyle.Mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileUploadErrorStateStyle.Mock.swift; sourceTree = "<group>"; };
C09047472B7E20B0003C437C /* FileUploadStateStyle.Mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileUploadStateStyle.Mock.swift; sourceTree = "<group>"; };
C09047492B7E20E0003C437C /* MessageCenterFileUploadStyle.Equatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageCenterFileUploadStyle.Equatable.swift; sourceTree = "<group>"; };
C090474B2B7E210C003C437C /* FileUploadStyle.Equatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileUploadStyle.Equatable.swift; sourceTree = "<group>"; };
C09047492B7E20E0003C437C /* MessageCenterFileUploadStyle.EnabledDisabledState.Equatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageCenterFileUploadStyle.EnabledDisabledState.Equatable.swift; sourceTree = "<group>"; };
C090474B2B7E210C003C437C /* FileUploadStyle.EnabledDisabledState.Equatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileUploadStyle.EnabledDisabledState.Equatable.swift; sourceTree = "<group>"; };
C090474D2B7E2138003C437C /* FileUploadErrorStateStyle.Equatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileUploadErrorStateStyle.Equatable.swift; sourceTree = "<group>"; };
C090474F2B7E215E003C437C /* FileUploadStateStyle.Equatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileUploadStateStyle.Equatable.swift; sourceTree = "<group>"; };
C09047512B7E21A2003C437C /* MessageCenterFileUploadListStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageCenterFileUploadListStyle.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2263,14 +2263,14 @@
C09047392B7E1ECD003C437C /* FileUploadStateStyle.RemoteConfig.swift */,
C09047372B7E1EA6003C437C /* FileUploadStateStyle.swift */,
9A186A3427F5CF3C0055886D /* FileUploadStyle.Accessibility.swift */,
C090474B2B7E210C003C437C /* FileUploadStyle.Equatable.swift */,
C090474B2B7E210C003C437C /* FileUploadStyle.EnabledDisabledState.Equatable.swift */,
C09047432B7E2016003C437C /* FileUploadStyle.Mock.swift */,
C09047352B7E1DEF003C437C /* FileUploadStyle.RemoteConfig.swift */,
1A0EDF5925E786DB0076D1AD /* FileUploadStyle.swift */,
C09047552B7E21F0003C437C /* MessageCenterFileUploadListStyle.Equatable.swift */,
C09047532B7E21C5003C437C /* MessageCenterFileUploadListStyle.RemoteConfig.swift */,
C09047512B7E21A2003C437C /* MessageCenterFileUploadListStyle.swift */,
C09047492B7E20E0003C437C /* MessageCenterFileUploadStyle.Equatable.swift */,
C09047492B7E20E0003C437C /* MessageCenterFileUploadStyle.EnabledDisabledState.Equatable.swift */,
C09047412B7E1FDF003C437C /* MessageCenterFileUploadStyle.RemoteConfig.swift */,
C090473F2B7E1FBC003C437C /* MessageCenterFileUploadStyle.swift */,
);
Expand Down Expand Up @@ -5864,7 +5864,7 @@
3197F7B129E958F4008EE9F7 /* SystemMessageStyle.swift in Sources */,
3100D92C296E946600DEC9CE /* SecureConversations.ConfirmationViewController.swift in Sources */,
C0F3DE3B2C6E0DD900DE6D7B /* EntryWidgetView.swift in Sources */,
C090474C2B7E210C003C437C /* FileUploadStyle.Equatable.swift in Sources */,
C090474C2B7E210C003C437C /* FileUploadStyle.EnabledDisabledState.Equatable.swift in Sources */,
C09047402B7E1FBC003C437C /* MessageCenterFileUploadStyle.swift in Sources */,
9A8130BB27D7A41000220BBD /* FileUpload.Environment.Interface.swift in Sources */,
C09046AB2B7D0967003C437C /* WelcomeStyle.SendButton.DisabledStyle.Accessibility.swift in Sources */,
Expand Down Expand Up @@ -6395,7 +6395,7 @@
846A5C3429CB3A130049B29F /* ScreenShareHandler.Implementation.swift in Sources */,
AFA2FDEC28907D7C00428E6D /* EngagementCoordinator.Environment.swift in Sources */,
C09046B52B7D0A84003C437C /* WelcomeStyle.MessageWarningStyle.Accessibility.swift in Sources */,
C090474A2B7E20E0003C437C /* MessageCenterFileUploadStyle.Equatable.swift in Sources */,
C090474A2B7E20E0003C437C /* MessageCenterFileUploadStyle.EnabledDisabledState.Equatable.swift in Sources */,
C0D6C9F72C0D2F6D00D4709B /* AlertPlacement.swift in Sources */,
C09046992B7D06D7003C437C /* WelcomeStyle.MessageTextViewNormalStyle.Accessibility.swift in Sources */,
C09047642B7E2375003C437C /* ChatFileDownloadStateStyle.RemoteConfig.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,11 @@ extension SecureConversations {
case let .success(.available(queueIds)):
self.environment.queueIds = queueIds
self.isSecureConversationsAvailable = true
case .failure, .success(.unavailable(.emptyQueue)):
self.isSecureConversationsAvailable = false
self.engagementAction?(.showAlert(.unavailableMessageCenter()))
case .success(.unavailable(.unauthenticated)):
self.fileUploadListModel.isEnabled = true
case .failure, .success(.unavailable(.emptyQueue)), .success(.unavailable(.unauthenticated)):
// For chat screen we no longer show unavailability dialog, but unavailability banner instead.
self.isSecureConversationsAvailable = false
self.fileUploadListModel.isEnabled = false
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,5 @@ extension SecureConversations.FilePreviewView.Kind {
}

private extension FilePreviewStyle {
static let initial = FileUploadStyle.initial.filePreview
static let initial = FileUploadStyle.initial.enabled.filePreview
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ extension SecureConversations {

var action: ((Action) -> Void)?
var delegate: ((DelegateEvent) -> Void)?
var isEnabled = true {
didSet {
reportChange()
}
}

enum Event {}
enum Action {}
Expand Down Expand Up @@ -91,7 +96,8 @@ extension SecureConversations {
style: style.item,
removeTapped: Cmd { [weak self] in
self?.removeUpload(fileUpload)
}
},
isEnabled: isEnabled
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extension SecureConversations {
let style: Style
let state: State
let removeTapped: Cmd
let isEnabled: Bool
}

static func height(for style: Style) -> CGFloat {
Expand Down Expand Up @@ -68,7 +69,7 @@ extension SecureConversations {
constraints += contentView.heightAnchor.constraint(greaterThanOrEqualToConstant: Self.height(for: props.style))
addSubview(contentView)
contentView.translatesAutoresizingMaskIntoConstraints = false
let style = Style.Properties(style: props.style)
let style = Style.Properties(style: props.style, isEnabled: props.isEnabled)
constraints += contentView.layoutInSuperview(insets: style.contentInsets)

contentView.addSubview(filePreviewView)
Expand Down Expand Up @@ -124,7 +125,8 @@ extension SecureConversations {

func renderProps() {
let style = SecureConversations.FileUploadView.Style.Properties(
style: props.style
style: props.style,
isEnabled: props.isEnabled
)
progressView.backgroundColor = style.progressBackgroundColor
removeButton.tintColor = style.removeButtonColor
Expand All @@ -148,7 +150,7 @@ extension SecureConversations {

private func update(for state: FileUpload.State) {
let style = SecureConversations.FileUploadView.Style.Properties(
style: props.style
style: props.style, isEnabled: props.isEnabled
)
switch state {
case .none:
Expand Down Expand Up @@ -289,7 +291,8 @@ extension SecureConversations.FileUploadView.Props {
init(
fileUpload: GliaWidgets.FileUpload,
style: SecureConversations.FileUploadView.Style,
removeTapped: Cmd
removeTapped: Cmd,
isEnabled: Bool
) {
self.init(
id: fileUpload.uuid.uuidString,
Expand All @@ -298,7 +301,8 @@ extension SecureConversations.FileUploadView.Props {
state: fileUpload.state.value,
localFile: fileUpload.localFile
),
removeTapped: removeTapped
removeTapped: removeTapped,
isEnabled: isEnabled
)
}
}
Expand All @@ -308,6 +312,8 @@ extension FileUploadStyle {
}

extension SecureConversations.FileUploadView {
typealias EnabledDisabledState = StatefulStyle<Style>

enum Style: Equatable {
case chat(FileUploadStyle)
case messageCenter(MessageCenterFileUploadStyle)
Expand Down Expand Up @@ -341,9 +347,11 @@ extension SecureConversations.FileUploadView.Style {
var backgroundColor: UIColor
var removeButtonTopRightOffset: CGSize

init(style: SecureConversations.FileUploadView.Style) {
init(style: SecureConversations.FileUploadView.Style, isEnabled: Bool) {
switch style {
case let .chat(uploadStyle):
case let .chat(styleStates):
let uploadStyle = isEnabled ? styleStates.enabled
: styleStates.disabled
filePreview = uploadStyle.filePreview
uploading = uploadStyle.uploading
uploaded = uploadStyle.uploaded
Expand All @@ -358,7 +366,9 @@ extension SecureConversations.FileUploadView.Style {
cornerRadius = 0
backgroundColor = .clear
removeButtonTopRightOffset = .zero
case let .messageCenter(uploadStyle):
case let .messageCenter(styleStates):
let uploadStyle = isEnabled ? styleStates.enabled
: styleStates.disabled
filePreview = uploadStyle.filePreview
uploading = uploadStyle.uploading
uploaded = uploadStyle.uploaded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,13 @@ extension Theme {
)

var uploadListStyle: MessageCenterFileUploadListStyle {
let filePreview = FilePreviewStyle(
// For now all disabled styles are the same as enabled ones.
// Because there is no design for disabled state of file upload
// and visually we do not show disabled state of file upload.
// But since file upload is a part of the message entry, that
// has to have disabled state, we need to provide these styles
// for file upload as well.
let filePreviewEnabled = FilePreviewStyle(
fileFont: font.subtitle,
fileColor: color.baseLight,
errorIcon: Asset.uploadError.image,
Expand All @@ -181,21 +187,44 @@ extension Theme {
errorBackgroundColor: color.baseNeutral,
accessibility: .init(isFontScalingEnabled: true)
)
let uploading = FileUploadStateStyle(
let filePreviewDisabled = FilePreviewStyle(
fileFont: font.subtitle,
fileColor: color.baseLight,
errorIcon: Asset.uploadError.image,
errorIconColor: color.systemNegative,
backgroundColor: color.primary,
errorBackgroundColor: color.baseNeutral,
accessibility: .init(isFontScalingEnabled: true)
)
let uploadingEnabled = FileUploadStateStyle(
text: Localization.Chat.File.Upload.inProgress,
font: font.mediumSubtitle2,
textColor: color.baseDark,
infoFont: font.caption,
infoColor: color.baseNormal
)
let uploadingDisabled = FileUploadStateStyle(
text: Localization.Chat.File.Upload.inProgress,
font: font.mediumSubtitle2,
textColor: color.baseDark,
infoFont: font.caption,
infoColor: color.baseNormal
)
let uploaded = FileUploadStateStyle(
let uploadedEnabled = FileUploadStateStyle(
text: Localization.Chat.File.Upload.success,
font: font.mediumSubtitle2,
textColor: color.baseDark,
infoFont: font.caption,
infoColor: color.baseNormal
)
let uploadedDisabled = FileUploadStateStyle(
text: Localization.Chat.File.Upload.success,
font: font.mediumSubtitle2,
textColor: color.baseDark,
infoFont: font.caption,
infoColor: color.baseNormal
)
let error = FileUploadErrorStateStyle(
let errorEnabled = FileUploadErrorStateStyle(
text: Localization.Chat.File.Upload.failed,
font: font.mediumSubtitle2,
textColor: color.baseDark,
Expand All @@ -207,11 +236,23 @@ extension Theme {
infoNetworkError: Localization.Chat.File.Upload.networkError,
infoGenericError: Localization.Chat.File.Upload.genericError
)
let upload = MessageCenterFileUploadStyle(
filePreview: filePreview,
uploading: uploading,
uploaded: uploaded,
error: error,
let errorDisabled = FileUploadErrorStateStyle(
text: Localization.Chat.File.Upload.failed,
font: font.mediumSubtitle2,
textColor: color.baseDark,
infoFont: font.caption,
infoColor: color.systemNegative,
infoFileTooBig: Localization.Chat.File.SizeLimit.error,
infoUnsupportedFileType: Localization.Chat.Attachment.unsupportedFile,
infoSafetyCheckFailed: Localization.Chat.File.InfectedFile.error,
infoNetworkError: Localization.Chat.File.Upload.networkError,
infoGenericError: Localization.Chat.File.Upload.genericError
)
let uploadEnabled = MessageCenterFileUploadStyle.EnabledDisabledState(
filePreview: filePreviewEnabled,
uploading: uploadingEnabled,
uploaded: uploadedEnabled,
error: errorEnabled,
progressColor: color.primary,
errorProgressColor: color.systemNegative,
progressBackgroundColor: color.baseNeutral,
Expand All @@ -225,7 +266,28 @@ extension Theme {
isFontScalingEnabled: true
)
)

let uploadDisabled = MessageCenterFileUploadStyle.EnabledDisabledState(
filePreview: filePreviewDisabled,
uploading: uploadingDisabled,
uploaded: uploadedDisabled,
error: errorDisabled,
progressColor: color.primary,
errorProgressColor: color.systemNegative,
progressBackgroundColor: color.baseNeutral,
removeButtonImage: Asset.mcRemoveUpload.image,
removeButtonColor: color.baseNormal,
backgroundColor: .commonGray,
accessibility: .init(
removeButtonAccessibilityLabel: Localization.Chat.File.RemoveUpload.Accessibility.label,
progressPercentValue: Localization.Templates.percentValue,
fileNameWithProgressValue: Localization.Templates.fileNameWithProgressValue,
isFontScalingEnabled: true
)
)
let upload = MessageCenterFileUploadStyle(
enabled: uploadEnabled,
disabled: uploadDisabled
)
return MessageCenterFileUploadListStyle(item: upload)
}

Expand Down
2 changes: 2 additions & 0 deletions GliaWidgets/Sources/StatefulStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ enum StatefulStyle<State> {
}
}
}

extension StatefulStyle: Equatable where State: Equatable {}
Loading

0 comments on commit 1ea3ecf

Please sign in to comment.