Skip to content

Commit

Permalink
Merge pull request #1150 from Infomaniak/clean-shapestyle
Browse files Browse the repository at this point in the history
refactor: Remove ShapeStyle from IKIcon
  • Loading branch information
valentinperignon committed Nov 29, 2023
2 parents 5bb610c + f767325 commit 383929f
Show file tree
Hide file tree
Showing 43 changed files with 186 additions and 167 deletions.
3 changes: 2 additions & 1 deletion Mail/Components/AttachmentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ struct AttachmentView<Content: View>: View {
var body: some View {
VStack(spacing: 0) {
HStack {
IKIcon(size: .large, image: attachment.icon, shapeStyle: MailResourcesAsset.textSecondaryColor.swiftUIColor)
IKIcon(attachment.icon, size: .large)
.foregroundStyle(MailResourcesAsset.textSecondaryColor)

HStack(spacing: UIPadding.small) {
VStack(alignment: .leading, spacing: 0) {
Expand Down
2 changes: 1 addition & 1 deletion Mail/Components/Buttons/Custom Buttons/ExtendedFAB.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct ExtendedFAB: View {
action()
} label: {
HStack(spacing: 0) {
IKIcon(size: .medium, image: icon, shapeStyle: HierarchicalShapeStyle.primary)
IKIcon(icon)

Text(title)
.lineLimit(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ struct MenuDrawerButton: View {
matomo.track(eventWithCategory: .menuDrawer, name: "openByButton")
navigationDrawerState.open()
} label: {
IKIcon(size: .large, image: MailResourcesAsset.burger)
IKIcon(MailResourcesAsset.burger, size: .large)
}
.accessibilityLabel(MailResourcesStrings.Localizable.contentDescriptionButtonMenu)
}
}

#Preview {
MenuDrawerButton()
}
6 changes: 5 additions & 1 deletion Mail/Components/Buttons/Custom Buttons/SearchButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ struct SearchButton: View {
Button {
mainViewState.isShowingSearch = true
} label: {
IKIcon(size: .large, image: MailResourcesAsset.search)
IKIcon(MailResourcesAsset.search, size: .large)
}
}
}

#Preview {
SearchButton()
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct IKFloatingAppButtonStyle: ButtonStyle {
Button {
/* Preview */
} label: {
IKIcon(size: .medium, image: MailResourcesAsset.pencilPlain, shapeStyle: HierarchicalShapeStyle.primary)
IKIcon(MailResourcesAsset.pencilPlain)
}
.buttonStyle(.ikFloatingAppButton(isExtended: false))
}
Expand All @@ -64,7 +64,7 @@ struct IKFloatingAppButtonStyle: ButtonStyle {
/* Preview */
} label: {
Label { Text("Lorem Ipsum") } icon: {
IKIcon(size: .medium, image: MailResourcesAsset.pencilPlain, shapeStyle: .primary)
IKIcon(MailResourcesAsset.pencilPlain)
}
}
}
Expand All @@ -73,7 +73,7 @@ struct IKFloatingAppButtonStyle: ButtonStyle {
Button {
/* Preview */
} label: {
IKIcon(size: .medium, image: MailResourcesAsset.pencilPlain, shapeStyle: HierarchicalShapeStyle.primary)
IKIcon(MailResourcesAsset.pencilPlain)
}
.buttonStyle(.ikFloatingAppButton(isExtended: false))
.controlSize(.large)
Expand All @@ -83,7 +83,7 @@ struct IKFloatingAppButtonStyle: ButtonStyle {
Button {
/* Preview */
} label: {
IKIcon(size: .medium, image: MailResourcesAsset.pencilPlain, shapeStyle: HierarchicalShapeStyle.primary)
IKIcon(MailResourcesAsset.pencilPlain)
}
.buttonStyle(.ikFloatingAppButton(isExtended: false))
.ikButtonLoading(true)
Expand All @@ -94,7 +94,7 @@ struct IKFloatingAppButtonStyle: ButtonStyle {
/* Preview */
} label: {
Label { Text("Lorem Ipsum") } icon: {
IKIcon(size: .medium, image: MailResourcesAsset.pencilPlain, shapeStyle: .primary)
IKIcon(MailResourcesAsset.pencilPlain)
}
}
.ikButtonLoading(true)
Expand All @@ -105,7 +105,7 @@ struct IKFloatingAppButtonStyle: ButtonStyle {
/* Preview */
} label: {
Label { Text("Lorem Ipsum") } icon: {
IKIcon(size: .medium, image: MailResourcesAsset.pencilPlain, shapeStyle: .primary)
IKIcon(MailResourcesAsset.pencilPlain)
}
}
.disabled(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct IKLinkButtonStyle: ButtonStyle {
/* Preview */
} label: {
Label { Text("Lorem Ipsum") } icon: {
IKIcon(size: .medium, image: MailResourcesAsset.pencilPlain, shapeStyle: .primary)
IKIcon(MailResourcesAsset.pencilPlain)
}
}
}
Expand All @@ -69,7 +69,7 @@ struct IKLinkButtonStyle: ButtonStyle {
/* Preview */
} label: {
Label { Text("Lorem Ipsum") } icon: {
IKIcon(size: .medium, image: MailResourcesAsset.pencilPlain, shapeStyle: .primary)
IKIcon(MailResourcesAsset.pencilPlain)
}
}
}
Expand All @@ -79,7 +79,7 @@ struct IKLinkButtonStyle: ButtonStyle {
/* Preview */
} label: {
Label { Text("Lorem Ipsum") } icon: {
IKIcon(size: .medium, image: MailResourcesAsset.pencilPlain, shapeStyle: .primary)
IKIcon(MailResourcesAsset.pencilPlain)
}
}
.controlSize(.small)
Expand All @@ -90,7 +90,7 @@ struct IKLinkButtonStyle: ButtonStyle {
/* Preview */
} label: {
Label { Text("Lorem Ipsum") } icon: {
IKIcon(size: .medium, image: MailResourcesAsset.pencilPlain, shapeStyle: .primary)
IKIcon(MailResourcesAsset.pencilPlain)
}
}
.controlSize(.large)
Expand All @@ -102,7 +102,7 @@ struct IKLinkButtonStyle: ButtonStyle {
/* Preview */
} label: {
Label { Text("Lorem Ipsum") } icon: {
IKIcon(size: .medium, image: MailResourcesAsset.pencilPlain, shapeStyle: .primary)
IKIcon(MailResourcesAsset.pencilPlain)
}
}
.ikButtonPrimaryStyle(MailResourcesAsset.aiColor.swiftUIColor)
Expand All @@ -113,7 +113,7 @@ struct IKLinkButtonStyle: ButtonStyle {
/* Preview */
} label: {
Label { Text("Lorem Ipsum") } icon: {
IKIcon(size: .medium, image: MailResourcesAsset.pencilPlain, shapeStyle: .primary)
IKIcon(MailResourcesAsset.pencilPlain)
}
}
.buttonStyle(.ikLink(isInlined: true))
Expand All @@ -124,7 +124,7 @@ struct IKLinkButtonStyle: ButtonStyle {
/* Preview */
} label: {
Label { Text("Lorem Ipsum") } icon: {
IKIcon(size: .medium, image: MailResourcesAsset.pencilPlain, shapeStyle: .primary)
IKIcon(MailResourcesAsset.pencilPlain)
}
}
.ikButtonLoading(true)
Expand All @@ -135,7 +135,7 @@ struct IKLinkButtonStyle: ButtonStyle {
/* Preview */
} label: {
Label { Text("Lorem Ipsum") } icon: {
IKIcon(size: .medium, image: MailResourcesAsset.pencilPlain, shapeStyle: .primary)
IKIcon(MailResourcesAsset.pencilPlain)
}
}
.disabled(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct IKPlainButtonStyle: ButtonStyle {
/* Preview */
} label: {
Label { Text("Lorem Ipsum") } icon: {
IKIcon(size: .medium, image: MailResourcesAsset.pencilPlain, shapeStyle: .primary)
IKIcon(MailResourcesAsset.pencilPlain)
}
}
}
Expand All @@ -54,7 +54,7 @@ struct IKPlainButtonStyle: ButtonStyle {
/* Preview */
} label: {
Label { Text("Lorem Ipsum") } icon: {
IKIcon(size: .medium, image: MailResourcesAsset.pencilPlain, shapeStyle: .primary)
IKIcon(MailResourcesAsset.pencilPlain)
}
}
.controlSize(.large)
Expand All @@ -65,7 +65,7 @@ struct IKPlainButtonStyle: ButtonStyle {
/* Preview */
} label: {
Label { Text("Lorem Ipsum") } icon: {
IKIcon(size: .medium, image: MailResourcesAsset.pencilPlain, shapeStyle: .primary)
IKIcon(MailResourcesAsset.pencilPlain)
}
}
.controlSize(.large)
Expand All @@ -77,7 +77,7 @@ struct IKPlainButtonStyle: ButtonStyle {
/* Preview */
} label: {
Label { Text("Lorem Ipsum") } icon: {
IKIcon(size: .medium, image: MailResourcesAsset.pencilPlain, shapeStyle: .primary)
IKIcon(MailResourcesAsset.pencilPlain)
}
}
.ikButtonPrimaryStyle(MailResourcesAsset.aiColor.swiftUIColor)
Expand All @@ -89,7 +89,7 @@ struct IKPlainButtonStyle: ButtonStyle {
/* Preview */
} label: {
Label { Text("Lorem Ipsum") } icon: {
IKIcon(size: .medium, image: MailResourcesAsset.pencilPlain, shapeStyle: .primary)
IKIcon(MailResourcesAsset.pencilPlain)
}
}
.ikButtonLoading(true)
Expand All @@ -100,7 +100,7 @@ struct IKPlainButtonStyle: ButtonStyle {
/* Preview */
} label: {
Label { Text("Lorem Ipsum") } icon: {
IKIcon(size: .medium, image: MailResourcesAsset.pencilPlain, shapeStyle: .primary)
IKIcon(MailResourcesAsset.pencilPlain)
}
}
.disabled(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct IKSquareButtonStyle: ButtonStyle {
Button {
/* Preview */
} label: {
IKIcon(size: .medium, image: MailResourcesAsset.pencilPlain, shapeStyle: HierarchicalShapeStyle.primary)
IKIcon(MailResourcesAsset.pencilPlain)
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions Mail/Components/Buttons/IKButton/IKButtonLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ extension LabelStyle where Self == IKLabelStyle {
}

struct IKLabelStyle: LabelStyle {
private let size = IKIcon.Size.medium

func makeBody(configuration: Configuration) -> some View {
HStack(spacing: UIPadding.small) {
configuration.icon
Expand Down
3 changes: 2 additions & 1 deletion Mail/Components/ChevronIcon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ struct ChevronIcon: View {
var color: any ShapeStyle = MailResourcesAsset.textSecondaryColor.swiftUIColor

var body: some View {
IKIcon(size: .small, image: MailResourcesAsset.chevronUp, shapeStyle: color)
IKIcon(MailResourcesAsset.chevronUp, size: .small)
.rotationEffect(style.rotationAngle)
.foregroundStyle(AnyShapeStyle(color))
}
}

Expand Down
43 changes: 24 additions & 19 deletions Mail/Components/IKIcon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,39 @@ import MailResources
import SwiftUI

struct IKIcon: View {
enum Size {
case small, medium, large

var heightAndWidth: CGFloat {
switch self {
case .small:
return 12
case .medium:
return 16
case .large:
return 24
}
}
enum Size: CGFloat {
/// 12pt icon
case small = 12
/// 16pt icon
case regular = 16
/// 24pt icon
case large = 24
}

let icon: Image
let size: Size
var image: MailResourcesImages
var shapeStyle: any ShapeStyle = Color.accentColor

init(_ icon: Image, size: Size = .regular) {
self.icon = icon
self.size = size
}

init(_ icon: MailResourcesImages, size: Size = .regular) {
self.init(icon.swiftUIImage, size: size)
}

var body: some View {
image.swiftUIImage
icon
.resizable()
.scaledToFit()
.frame(width: size.heightAndWidth, height: size.heightAndWidth)
.foregroundStyle(AnyShapeStyle(shapeStyle))
.frame(width: size.rawValue, height: size.rawValue)
}
}

#Preview {
IKIcon(size: .large, image: MailResourcesAsset.folder)
HStack(spacing: UIPadding.regular) {
IKIcon(MailResourcesAsset.pencilPlain, size: .small)
IKIcon(MailResourcesAsset.pencilPlain, size: .regular)
IKIcon(MailResourcesAsset.pencilPlain, size: .large)
}
}
11 changes: 7 additions & 4 deletions Mail/Components/MailboxListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ struct MailboxListView: View {
NavigationLink {
AddMailboxView()
} label: {
IKIcon(
size: .medium,
image: MailResourcesAsset.addCircle
)
IKIcon(MailResourcesAsset.addCircle)
.foregroundStyle(.tint)
}
}
.padding(value: .regular)
Expand All @@ -65,3 +63,8 @@ struct MailboxListView: View {
.frame(maxWidth: .infinity, alignment: .leading)
}
}

#Preview {
MailboxListView(currentMailbox: PreviewHelper.sampleMailbox)
.environmentObject(PreviewHelper.sampleMailboxManager)
}
14 changes: 4 additions & 10 deletions Mail/Components/SearchTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ struct SearchTextField: View {
var body: some View {
HStack(spacing: UIPadding.small) {
Button(action: onSubmit) {
IKIcon(
size: .medium,
image: MailResourcesAsset.search,
shapeStyle: MailResourcesAsset.textTertiaryColor.swiftUIColor
)
IKIcon(MailResourcesAsset.search)
.foregroundStyle(MailResourcesAsset.textTertiaryColor)
}
TextField(MailResourcesStrings.Localizable.searchFieldPlaceholder, text: $value)
.autocorrectionDisabled()
Expand All @@ -56,11 +53,8 @@ struct SearchTextField: View {
.padding(.vertical, value: .intermediate)

Button(action: onDelete) {
IKIcon(
size: .medium,
image: MailResourcesAsset.remove,
shapeStyle: MailResourcesAsset.textTertiaryColor.swiftUIColor
)
IKIcon(MailResourcesAsset.remove)
.foregroundStyle(MailResourcesAsset.textTertiaryColor)
}
.opacity(value.isEmpty ? 0 : 1)
}
Expand Down
26 changes: 20 additions & 6 deletions Mail/Components/ThreadCellDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,29 @@ struct ThreadCellDetailsView: View {
var body: some View {
HStack(spacing: UIPadding.small) {
if hasAttachments {
IKIcon(
size: .medium,
image: MailResourcesAsset.attachment,
shapeStyle: MailResourcesAsset.textPrimaryColor.swiftUIColor
)
IKIcon(MailResourcesAsset.attachment)
.foregroundStyle(MailResourcesAsset.textPrimaryColor)
}
if isFlagged {
IKIcon(size: .medium, image: MailResourcesAsset.starFull, shapeStyle: MailResourcesAsset.yellowColor.swiftUIColor)
IKIcon(MailResourcesAsset.starFull)
.foregroundStyle(MailResourcesAsset.yellowColor)
}
}
}
}

#Preview("Attachments, Flagged") {
ThreadCellDetailsView(hasAttachments: true, isFlagged: true)
}

#Preview("Attachments, Not flagged") {
ThreadCellDetailsView(hasAttachments: true, isFlagged: false)
}

#Preview("No Attachment, Flagged") {
ThreadCellDetailsView(hasAttachments: false, isFlagged: true)
}

#Preview("No Attachment, Not flagged") {
ThreadCellDetailsView(hasAttachments: false, isFlagged: false)
}
Loading

0 comments on commit 383929f

Please sign in to comment.